File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,12 @@ def create
1515
1616 def destroy
1717 @reaction = @comment . reactions . find ( params [ :id ] )
18- @reaction . destroy
18+
19+ if Current . user != @reaction . reacter
20+ head :forbidden
21+ else
22+ @reaction . destroy
23+ end
1924 end
2025
2126 private
Original file line number Diff line number Diff line change 22
33class Cards ::Comments ::ReactionsControllerTest < ActionDispatch ::IntegrationTest
44 setup do
5- sign_in_as :jz
5+ sign_in_as :david
66 @comment = comments ( :logo_agreement_jz )
77 @card = @comment . card
88 end
@@ -15,10 +15,19 @@ class Cards::Comments::ReactionsControllerTest < ActionDispatch::IntegrationTest
1515 end
1616
1717 test "destroy" do
18- reaction = reactions ( :kevin )
18+ reaction = reactions ( :david )
1919 assert_difference -> { @comment . reactions . count } , -1 do
2020 delete card_comment_reaction_path ( @comment . card , @comment , reaction , format : :turbo_stream )
2121 assert_turbo_stream action : :remove , target : dom_id ( reaction )
2222 end
2323 end
24+
25+ test "non-owner cannot destroy reaction" do
26+ reaction = reactions ( :kevin )
27+
28+ assert_no_difference -> { @comment . reactions . count } do
29+ delete card_comment_reaction_path ( @comment . card , @comment , reaction , format : :turbo_stream )
30+ assert_response :forbidden
31+ end
32+ end
2433end
You can’t perform that action at this time.
0 commit comments