Award credits along with badge achievements (#2683)
This commit is contained in:
parent
95cb63fe04
commit
15ea00328c
2 changed files with 10 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue