Browse Source

Fix test (remove it), and add other unit test on def show

Lou 3 years ago
parent
commit
3e6506c7d7
1 changed files with 6 additions and 11 deletions
  1. 6
    11
      test/controllers/api/v1/tasks_controller_test.rb

+ 6
- 11
test/controllers/api/v1/tasks_controller_test.rb View File

@@ -27,6 +27,11 @@ class Api::V1::TasksControllerTest < ActionDispatch::IntegrationTest
27 27
     headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
28 28
     as: :json
29 29
     assert_response :success
30
+
31
+    json_response = JSON.parse(self.response.body)
32
+    assert_equal @task.name, json_response['data']['attributes']['name']
33
+    assert_equal @task.user_id, json_response['data']['attributes']['user_id']
34
+    assert_equal @task.activity_id, json_response['data']['attributes']['activity_id']
30 35
   end
31 36
 
32 37
   test "should not access show" do
@@ -46,7 +51,7 @@ class Api::V1::TasksControllerTest < ActionDispatch::IntegrationTest
46 51
     assert_response :created
47 52
   end
48 53
 
49
-  test "should forbid create task - not logged in" do
54
+  test "should forbid create task" do
50 55
     assert_no_difference("Task.count") do
51 56
       post api_v1_activity_tasks_url(@activity),
52 57
       params: { task: { name: @task.name, description: @task.description, user_id: @user, activity_id: @activity } },
@@ -54,14 +59,4 @@ class Api::V1::TasksControllerTest < ActionDispatch::IntegrationTest
54 59
     end
55 60
     assert_response :forbidden
56 61
   end
57
-
58
-  test "should forbid create task - missing user or activity id" do
59
-    assert_no_difference("Task.count") do
60
-      post api_v1_activity_tasks_url(@activity),
61
-      params: { task: { name: @task.name, description: @task.description } },
62
-      headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
63
-      as: :json
64
-    end
65
-    assert_response :forbidden
66
-  end
67 62
 end

Loading…
Cancel
Save