FIX: Only likes should change the given daily likes

This commit is contained in:
Gerhard Schlager 2018-02-26 22:27:18 +01:00
parent e2a524550c
commit 5ca5817902
2 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -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