job grants badge
This commit is contained in:
parent
0da6dd5610
commit
9ca0f09916
|
@ -2,7 +2,10 @@
|
|||
module Jobs
|
||||
class DonationUser < ::Jobs::Base
|
||||
def execute(args)
|
||||
User.create(args)
|
||||
user = User.create!(args)
|
||||
if args[:rewards].present?
|
||||
DiscourseDonations::Rewards.new(user).grant_badge(args[:rewards][:name])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Jobs::AwardGroup, type: :job do
|
||||
let(:users) { [Fabricate(:user), Fabricate(:user)] }
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Jobs::GrantBadge, type: :job do
|
||||
let(:users) { [Fabricate(:user), Fabricate(:user)] }
|
||||
|
|
|
@ -1,10 +1,24 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Jobs::DonationUser, type: :job do
|
||||
it { should respond_to(:execute).with(1).arguments }
|
||||
let(:args) { { email: 'fsfs4@example.com', username: 'sxsomething', name: 'ssbrian', password: 'ssecret-yo' } }
|
||||
|
||||
before do
|
||||
SiteSetting.stubs(:enable_badges).returns(true)
|
||||
end
|
||||
|
||||
it 'creates a new user' do
|
||||
args = { email: 'foo@example.com', username: 'something' }
|
||||
User.expects(:create).with(args)
|
||||
subject.execute(args)
|
||||
expect{ subject.execute(args) }.to change{ User.count }.by(1)
|
||||
end
|
||||
|
||||
describe 'rewards' do
|
||||
let(:user) { Fabricate(:user, args) }
|
||||
let(:badge) { Fabricate(:badge) }
|
||||
|
||||
it 'has the badge' do
|
||||
User.expects(:create!).returns(user)
|
||||
subject.execute(args.merge(rewards: { type: 'badge', name: badge.name }))
|
||||
expect(user.badges).to include(badge)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue