diff --git a/lib/post_action_creator.rb b/lib/post_action_creator.rb index ce582cc7cb7..0ee475c1274 100644 --- a/lib/post_action_creator.rb +++ b/lib/post_action_creator.rb @@ -89,6 +89,12 @@ class PostActionCreator PostActionNotifier.post_action_created(post_action) notify_subscribers + # agree with other flags + if @take_action && reviewable = @post.reviewable_flag + result.reviewable.perform(@created_by, :agree_and_keep) + post_action.try(:update_counters) + end + result.success = true result.post_action = post_action @@ -211,12 +217,6 @@ private GivenDailyLike.increment_for(@created_by.id) if @post_action_type_id == PostActionType.types[:like] - # agree with other flags - if @take_action && reviewable = @post.reviewable_flag - reviewable.perform(@created_by, :agree_and_keep) - post_action.try(:update_counters) - end - post_action rescue ActiveRecord::RecordNotUnique # can happen despite being .create diff --git a/spec/components/post_action_creator_spec.rb b/spec/components/post_action_creator_spec.rb index 56fc67b64bf..e59f85d93fc 100644 --- a/spec/components/post_action_creator_spec.rb +++ b/spec/components/post_action_creator_spec.rb @@ -101,4 +101,23 @@ describe PostActionCreator do end end end + + context "take_action" do + before do + PostActionCreator.create(Fabricate(:user), post, :inappropriate) + end + + it "will agree with the old reviewable" do + reviewable = PostActionCreator.new( + Fabricate(:moderator), + post, + PostActionType.types[:spam], + take_action: true + ).perform.reviewable + scores = reviewable.reviewable_scores + expect(scores[0]).to be_agreed + expect(scores[1]).to be_agreed + expect(reviewable.reload).to be_approved + end + end end