diff --git a/app/controllers/api/v1/activities_controller.rb b/app/controllers/api/v1/activities_controller.rb index 3cc41b7..6a13e26 100644 --- a/app/controllers/api/v1/activities_controller.rb +++ b/app/controllers/api/v1/activities_controller.rb @@ -1,7 +1,6 @@ class Api::V1::ActivitiesController < ApplicationController before_action :set_activity, only: %i[show update destroy] before_action :check_login - before_action :check_owner, only: %i[update destroy] def index render json: Activity.all @@ -43,8 +42,4 @@ class Api::V1::ActivitiesController < ApplicationController def set_activity @activity = Activity.find(params[:id]) end - - def check_owner - head :forbidden unless @activity.author_id == current_user&.id - end end diff --git a/test/controllers/api/v1/activities_controller_test.rb b/test/controllers/api/v1/activities_controller_test.rb index baf55e5..d02af05 100644 --- a/test/controllers/api/v1/activities_controller_test.rb +++ b/test/controllers/api/v1/activities_controller_test.rb @@ -68,15 +68,7 @@ class Api::V1::ActivitiesControllerTest < ActionDispatch::IntegrationTest as: :json assert_response :forbidden end - - test "should forbid update activity - not owner or admin" do - patch api_v1_activity_url(@activity), - params: { activity: { name: "Updated name" } }, - headers: { Authorization: JsonWebToken.encode(user_id: users(:two).id) }, - as: :json - assert_response :forbidden - end - + #DESTROY test "should destroy activity" do assert_difference "Activity.count", -1 do @@ -93,13 +85,4 @@ class Api::V1::ActivitiesControllerTest < ActionDispatch::IntegrationTest end assert_response :forbidden end - - test "should forbid destroy activity - not owner or admin" do - assert_no_difference('Activity.count') do - delete api_v1_activity_url(@activity), - headers: { Authorization: JsonWebToken.encode(user_id: users(:two).id) }, - as: :json - end - assert_response :forbidden - end end \ No newline at end of file diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 33aff36..8fc06ce 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -3,9 +3,4 @@ one: email: one@one.com username: OneUsername - password_digest: <%= BCrypt::Password.create('g00d_pa$$') %> - -two: - email: two@two.com - username: TwoUsername password_digest: <%= BCrypt::Password.create('g00d_pa$$') %> \ No newline at end of file