diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb
index c98df27d3..35236414f 100644
--- a/app/controllers/bids_controller.rb
+++ b/app/controllers/bids_controller.rb
@@ -675,11 +675,12 @@ class BidsController < ApplicationController
#删除作业
#by xianbo
def homework_destroy
- @bid_to_destroy = Bid.find params[:course_id]
+ @bid_to_destroy = Bid.find params[:id]
+ course_url = course_homework_path(@bid_to_destroy.courses.first)
(render_403; return false) unless User.current.admin?||User.current.id==@bid_to_destroy.author_id
@bid_to_destroy.destroy
respond_to do |format|
- format.html { redirect_to :back }
+ format.html { redirect_to course_url }
format.js
#format.api { render_api_ok }
end
diff --git a/app/views/courses/homework.html.erb b/app/views/courses/homework.html.erb
index f7cf2a360..7b74351cd 100644
--- a/app/views/courses/homework.html.erb
+++ b/app/views/courses/homework.html.erb
@@ -21,6 +21,9 @@
<%= l(:lebel_homework_commit)%> ( <%= link_to bid.homeworks.count, course_for_bid_path(bid.id), :class => 'c_red'%> )
<% if @is_teacher%>
<%= bid_anonymous_comment(bid)%>
+ <% if bid.homeworks.empty? %>
+ <%= link_to(l(:button_delete),bids_homework_path(:id => bid.id), :method => :delete, :confirm => l(:label_delete_confirm), :class => "fr mr10 work_edit") %>
+ <% end %>
<%= link_to(l(:button_edit),edit_bid_path(:course_id =>@course.id, :bid_id => bid.id), :class => "fr mr10 work_edit") %>
<% elsif @is_student%>
<%= student_anonymous_comment bid %>
@@ -59,4 +62,4 @@
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
-
\ No newline at end of file
+
diff --git a/app/views/users/user_homeworks.html.erb b/app/views/users/user_homeworks.html.erb
index 06c67320a..74560909d 100644
--- a/app/views/users/user_homeworks.html.erb
+++ b/app/views/users/user_homeworks.html.erb
@@ -1,4 +1,4 @@
-
+u
<% if @user.user_extensions.identity == 0 %>
<%= render :partial => 'my_create_homework' %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 09897c1eb..8419ae188 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -759,6 +759,7 @@ en:
button_create_and_continue: Create and continue
button_test: Test
button_edit: Edit
+ button_delete: Delete
button_edit_associated_wikipage: "Edit associated Wiki page: %{page_title}"
button_add: Add
button_change: Change
diff --git a/config/locales/zh.yml b/config/locales/zh.yml
index 4c752660a..73a97c035 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -849,6 +849,7 @@ zh:
button_create_and_continue: 创建并继续
button_test: 测试
button_edit: 编辑
+ button_delete: 删除
button_edit_associated_wikipage: "编辑相关wiki页面: %{page_title}"
button_add: 新增
button_change: 修改
diff --git a/config/routes.rb b/config/routes.rb
index 411386afc..9a8e71156 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -251,7 +251,7 @@ RedmineApp::Application.routes.draw do
post 'boards/:board_id/topics/:id/edit', :to => 'messages#edit'
post 'boards/:board_id/topics/:id/destroy', :to => 'messages#destroy'
# boards end
- post 'bids/homework_destroy', :to => 'bids#homework_destroy'
+ delete 'bids/homework', :to => 'bids#homework_destroy'
# Misc issue routes. TODO: move into resources
match '/issues/auto_complete', :to => 'auto_completes#issues', :via => :get, :as => 'auto_complete_issues'
diff --git a/spec/requests/homework_request_spec.rb b/spec/requests/homework_request_spec.rb
new file mode 100644
index 000000000..05733a56d
--- /dev/null
+++ b/spec/requests/homework_request_spec.rb
@@ -0,0 +1,52 @@
+require 'rails_helper'
+require 'shared_account_spec'
+
+RSpec.describe "homework", type: :request do
+ include_context "create user"
+ let(:course) {FactoryGirl.create(:course, teacher: current_user)}
+ let(:homework){FactoryGirl.attributes_for(:homework)}
+
+ before {
+ shared_register
+ }
+ describe "创建作业" do
+ before do
+ post calls_create_homework_path(course_id: course.id), {
+ bid: homework
+ }
+ @homework = assigns(:bid)
+ end
+ it "参数正确,可以成功创建作业" do
+ expect(response).to redirect_to(course_homework_url(course.id))
+ end
+ it {expect(course.homeworks).to_not be_empty}
+ it {expect(@homework.acts).to_not be_empty}
+ it {expect(@homework.watchers).to_not be_empty}
+ it {expect(@homework.attachments).to_not be_empty}
+ end
+
+ describe "删除作业" do
+ before do
+ shared_login
+ post calls_create_homework_path(course_id: course.id), {
+ bid: homework
+ }
+ @homework = assigns(:bid)
+ delete bids_homework_path(id: @homework.id)
+ end
+ it{expect(response).to redirect_to(course_homework_path(course.id))}
+ it "homework_for_courses应删除" do
+ expect(course.homeworks).to be_empty
+ end
+ it "相关活动也删除" do
+ expect(@homework.acts).to be_empty
+ end
+ it "watches 删除" do
+ expect(@homework.watchers).to be_empty
+ end
+ it "附件 删除" do
+ expect(@homework.attachments).to be_empty
+ end
+ end
+
+end