FIX: when granting old badges that are bronze, do not notify
This commit is contained in:
parent
144bf07886
commit
72849e65de
|
@ -41,15 +41,18 @@ class BadgeGranter
|
|||
end
|
||||
|
||||
if SiteSetting.enable_badges?
|
||||
I18n.with_locale(@user.effective_locale) do
|
||||
notification = @user.notifications.create(
|
||||
notification_type: Notification.types[:granted_badge],
|
||||
data: { badge_id: @badge.id,
|
||||
badge_name: @badge.display_name,
|
||||
badge_slug: @badge.slug,
|
||||
username: @user.username}.to_json
|
||||
)
|
||||
user_badge.update_attributes notification_id: notification.id
|
||||
|
||||
unless @badge.badge_type_id == BadgeType::Bronze && user_badge.granted_at < 2.days.ago
|
||||
I18n.with_locale(@user.effective_locale) do
|
||||
notification = @user.notifications.create(
|
||||
notification_type: Notification.types[:granted_badge],
|
||||
data: { badge_id: @badge.id,
|
||||
badge_name: @badge.display_name,
|
||||
badge_slug: @badge.slug,
|
||||
username: @user.username}.to_json
|
||||
)
|
||||
user_badge.update_attributes notification_id: notification.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -98,6 +98,17 @@ describe BadgeGranter do
|
|||
|
||||
describe 'grant' do
|
||||
|
||||
it 'allows overriding of granted_at does not notify old bronze' do
|
||||
badge = Fabricate(:badge, badge_type_id: BadgeType::Bronze)
|
||||
time = 1.year.ago
|
||||
|
||||
user_badge = BadgeGranter.grant(badge, user, created_at: time)
|
||||
|
||||
expect(user_badge.granted_at).to eq(time)
|
||||
expect(Notification.where(user_id: user.id).count).to eq(0)
|
||||
|
||||
end
|
||||
|
||||
it 'grants multiple badges' do
|
||||
badge = Fabricate(:badge, multiple_grant: true)
|
||||
user_badge = BadgeGranter.grant(badge, user)
|
||||
|
|
Loading…
Reference in New Issue