Browse Source

Add destroy def and unit test

Lou 3 years ago
parent
commit
fc38057172

+ 5
- 0
app/controllers/api/v1/tasks_controller.rb View File

@@ -29,6 +29,11 @@ class Api::V1::TasksController < ApplicationController
29 29
     end
30 30
   end
31 31
 
32
+  def destroy
33
+    @task.destroy
34
+    head 204
35
+  end
36
+
32 37
   private
33 38
 
34 39
   def task_params

+ 2
- 1
test/controllers/api/v1/activities_controller_test.rb View File

@@ -95,7 +95,8 @@ class Api::V1::ActivitiesControllerTest < ActionDispatch::IntegrationTest
95 95
 
96 96
   test "should forbid destroy activity - not logged in" do
97 97
     assert_no_difference('Activity.count') do
98
-      delete api_v1_activity_url(@activity), as: :json
98
+    delete api_v1_activity_url(@activity),
99
+    as: :json
99 100
     end
100 101
     assert_response :forbidden
101 102
   end

+ 18
- 0
test/controllers/api/v1/tasks_controller_test.rb View File

@@ -75,4 +75,22 @@ class Api::V1::TasksControllerTest < ActionDispatch::IntegrationTest
75 75
     as: :json
76 76
     assert_response :forbidden
77 77
   end
78
+
79
+  # DESTROY
80
+  test "should destroy task" do
81
+    assert_difference "Task.count", -1 do
82
+    delete api_v1_activity_task_url(@activity, @task),
83
+    headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
84
+    as: :json
85
+    end
86
+    assert_response :no_content
87
+  end
88
+
89
+  test "should not destroy task" do
90
+    assert_no_difference('Task.count') do
91
+    delete api_v1_activity_task_url(@activity, @task),
92
+    as: :json
93
+    end
94
+    assert_response :forbidden
95
+  end
78 96
 end

Loading…
Cancel
Save