Add destroy def and unit test

This commit is contained in:
Lou 2021-05-10 22:06:12 +02:00
commit fc38057172
3 changed files with 25 additions and 1 deletions

View file

@ -29,6 +29,11 @@ class Api::V1::TasksController < ApplicationController
end
end
def destroy
@task.destroy
head 204
end
private
def task_params

View file

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

View file

@ -75,4 +75,22 @@ class Api::V1::TasksControllerTest < ActionDispatch::IntegrationTest
as: :json
assert_response :forbidden
end
# DESTROY
test "should destroy task" do
assert_difference "Task.count", -1 do
delete api_v1_activity_task_url(@activity, @task),
headers: { Authorization: JsonWebToken.encode(user_id: @user.id) },
as: :json
end
assert_response :no_content
end
test "should not destroy task" do
assert_no_difference('Task.count') do
delete api_v1_activity_task_url(@activity, @task),
as: :json
end
assert_response :forbidden
end
end