Award credits along with badge achievements (#2683)

This commit is contained in:
Ben Halpern 2019-05-03 15:38:25 -04:00 committed by GitHub
parent 95cb63fe04
commit 15ea00328c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View file

@ -9,6 +9,7 @@ class BadgeAchievement < ApplicationRecord
after_create :notify_recipient
after_create :send_email_notification
after_create :award_credits
before_validation :render_rewarding_context_message_html
def render_rewarding_context_message_html
@ -32,4 +33,8 @@ class BadgeAchievement < ApplicationRecord
NotifyMailer.new_badge_email(self).deliver if user.class.name == "User" && user.email.present? && user.email_badge_notifications
end
handle_asynchronously :send_email_notification
def award_credits
Credit.add_to(user, 5)
end
end

View file

@ -14,4 +14,9 @@ RSpec.describe BadgeAchievement, type: :model do
achievement = create(:badge_achievement)
expect(achievement.rewarding_context_message).to include("</a>")
end
it "awards credits after create" do
achievement = create(:badge_achievement)
expect(achievement.user.credits.size).to eq(5)
end
end