From 5ca58179029de09aad3efdbcfe0230c4f0317fea Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Mon, 26 Feb 2018 22:27:18 +0100 Subject: [PATCH] FIX: Only likes should change the given daily likes --- app/models/post_action.rb | 5 +++-- spec/models/post_action_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 8bcb64482b3..cc3096272c2 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -302,7 +302,8 @@ SQL BadgeGranter.queue_badge_grant(Badge::Trigger::PostAction, post_action: post_action) end end - GivenDailyLike.increment_for(user.id) + + GivenDailyLike.increment_for(user.id) if post_action_type_id == PostActionType.types[:like] # agree with other flags if staff_took_action @@ -339,7 +340,7 @@ SQL if action = finder.first action.remove_act!(user) action.post.unhide! if action.staff_took_action - GivenDailyLike.decrement_for(user.id) + GivenDailyLike.decrement_for(user.id) if post_action_type_id == PostActionType.types[:like] end end diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index b22abb3b199..f17d1f79865 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -276,6 +276,26 @@ describe PostAction do expect(post.like_count).to eq(0) expect(post.like_score).to eq(0) end + + it "shouldn't change given_likes unless likes are given or removed" do + freeze_time(Time.zone.now) + + PostAction.act(codinghorror, Fabricate(:post), PostActionType.types[:like]) + expect(value_for(codinghorror.id, Date.today)).to eq(1) + + PostActionType.types.each do |type_name, type_id| + post = Fabricate(:post) + + PostAction.act(codinghorror, post, type_id) + actual_count = value_for(codinghorror.id, Date.today) + expected_count = type_name == :like ? 2 : 1 + expect(actual_count).to eq(expected_count), "Expected likes_given to be #{expected_count} when adding '#{type_name}', but got #{actual_count}" + + PostAction.remove_act(codinghorror, post, type_id) + actual_count = value_for(codinghorror.id, Date.today) + expect(actual_count).to eq(1), "Expected likes_given to be 1 when removing '#{type_name}', but got #{actual_count}" + end + end end describe "undo/redo repeatedly" do