From b6226ab33980a8e813560fdbeabb0cda50e8d607 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Fri, 20 Jun 2014 20:07:37 +0530 Subject: [PATCH 1/2] Add multiple grant clarification to description. --- config/locales/client.en.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index de108327829..c1f5fc4b240 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1932,10 +1932,10 @@ en: description: Received a like. nice_post: name: Nice Post - description: Received 10 likes on a post. + description: Received 10 likes on a post. This badge can be granted multiple times. good_post: name: Good Post - description: Received 25 likes on a post. + description: Received 25 likes on a post. This badge can be granted multiple times. great_post: name: Great Post - description: Received 100 likes on a post. + description: Received 100 likes on a post. This badge can be granted multiple times. From 23983efeea6eb6dce2ae5d0610469db969c67d9e Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Sat, 28 Jun 2014 00:32:09 +0530 Subject: [PATCH 2/2] Don't grant multiple_grant badges multiple times for the same post. --- app/services/badge_granter.rb | 2 +- spec/services/badge_granter_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rb index b132c7af184..2bca12c518f 100644 --- a/app/services/badge_granter.rb +++ b/app/services/badge_granter.rb @@ -15,7 +15,7 @@ class BadgeGranter user_badge = UserBadge.find_by(badge_id: @badge.id, user_id: @user.id, post_id: @post_id) - if user_badge.nil? || @badge.multiple_grant? + if user_badge.nil? || (@badge.multiple_grant? && @post_id.nil?) UserBadge.transaction do user_badge = UserBadge.create!(badge: @badge, user: @user, granted_by: @granted_by, diff --git a/spec/services/badge_granter_spec.rb b/spec/services/badge_granter_spec.rb index f893bd42cf6..a8f8499ff20 100644 --- a/spec/services/badge_granter_spec.rb +++ b/spec/services/badge_granter_spec.rb @@ -90,7 +90,9 @@ describe BadgeGranter do # Nice post badge post.update_attributes like_count: 10 BadgeGranter.update_badges(action: :post_like, post_id: post.id) + BadgeGranter.update_badges(action: :post_like, post_id: post.id) UserBadge.find_by(user_id: user.id, badge_id: 6).should_not be_nil + UserBadge.where(user_id: user.id, badge_id: 6).count.should == 1 # Good post badge post.update_attributes like_count: 25 BadgeGranter.update_badges(action: :post_like, post_id: post.id)