enqueue the mail job

This commit is contained in:
Rimian Perkins 2017-05-12 10:28:39 +10:00
parent 183d15e539
commit c12cc3246a
2 changed files with 33 additions and 1 deletions

View File

@ -3,6 +3,11 @@ module Jobs
class DonationUser < ::Jobs::Base
def execute(args)
user = User.create!(args.slice(:username, :password, :name, :email))
return unless user.persisted?
Jobs.enqueue(
:critical_user_email,
type: :signup, user_id: user.id, email_token: user.email_tokens.first.token
)
rewards = DiscourseDonations::Rewards.new(user)
args[:rewards].to_a.each do |reward|
rewards.grant_badge(reward[:name]) if reward[:type] == 'badge'

View File

@ -16,10 +16,37 @@ RSpec.describe Jobs::DonationUser, type: :job do
end
end
describe 'sending the signup email' do
let(:user) { User.find_by_email(args[:email]) }
it 'has an email token' do
subject.execute(args)
expect(user.email_tokens).not_to be_empty
end
it 'enqueues the signup email' do
User.expects(:create!).returns(Fabricate(:user, args))
Jobs.expects(:enqueue).with(
:critical_user_email,
type: :signup, user_id: user.id, email_token: user.email_tokens.first.token
)
subject.execute(args)
end
end
describe 'rewards' do
describe 'create user with rewards' do
let(:user) { Fabricate(:user) }
it 'does not create the rewards if the user does not persist' do
User.expects(:create!).returns(user)
user.expects(:persisted?).returns(false)
DiscourseDonations::Rewards.expects(:new).never
subject.execute(args)
end
it 'creates a User object without rewards' do
User.expects(:create!).with(args)
User.expects(:create!).with(args).returns(user)
subject.execute(args.merge(rewards: [], otherthing: nil))
end
end