enqueue the mail job
This commit is contained in:
parent
183d15e539
commit
c12cc3246a
|
@ -3,6 +3,11 @@ module Jobs
|
||||||
class DonationUser < ::Jobs::Base
|
class DonationUser < ::Jobs::Base
|
||||||
def execute(args)
|
def execute(args)
|
||||||
user = User.create!(args.slice(:username, :password, :name, :email))
|
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)
|
rewards = DiscourseDonations::Rewards.new(user)
|
||||||
args[:rewards].to_a.each do |reward|
|
args[:rewards].to_a.each do |reward|
|
||||||
rewards.grant_badge(reward[:name]) if reward[:type] == 'badge'
|
rewards.grant_badge(reward[:name]) if reward[:type] == 'badge'
|
||||||
|
|
|
@ -16,10 +16,37 @@ RSpec.describe Jobs::DonationUser, type: :job do
|
||||||
end
|
end
|
||||||
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 'rewards' do
|
||||||
describe 'create user with 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
|
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))
|
subject.execute(args.merge(rewards: [], otherthing: nil))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue