Add def update and unit tests

This commit is contained in:
Lou 2021-05-10 22:01:24 +02:00
commit da5edf8eab
3 changed files with 26 additions and 2 deletions

View file

@ -51,7 +51,7 @@ class Api::V1::TasksControllerTest < ActionDispatch::IntegrationTest
assert_response :created
end
test "should forbid create task" do
test "should not create task" do
assert_no_difference("Task.count") do
post api_v1_activity_tasks_url(@activity),
params: { task: { name: @task.name, description: @task.description, user_id: @user, activity_id: @activity } },
@ -59,4 +59,20 @@ class Api::V1::TasksControllerTest < ActionDispatch::IntegrationTest
end
assert_response :forbidden
end
# UPDATE
test "should update task" do
patch api_v1_activity_task_url(@activity, @task),
params: { task: { name: "New name", description: "New description" } },
headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
as: :json
assert_response :success
end
test "should not update task" do
patch api_v1_activity_task_url(@activity, @task),
params: { task: { name: "New name", description: "New description" } },
as: :json
assert_response :forbidden
end
end