no name collisions
This commit is contained in:
parent
9ca0f09916
commit
e875b17be2
|
@ -3,8 +3,10 @@ module Jobs
|
|||
class DonationUser < ::Jobs::Base
|
||||
def execute(args)
|
||||
user = User.create!(args)
|
||||
if args[:rewards].present?
|
||||
DiscourseDonations::Rewards.new(user).grant_badge(args[:rewards][:name])
|
||||
rewards = DiscourseDonations::Rewards.new(user)
|
||||
args[:rewards].to_a.each do |reward|
|
||||
rewards.grant_badge(reward[:name]) if reward[:type] == 'badge'
|
||||
rewards.add_to_group(reward[:name]) if reward[:type] == 'group'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,8 @@ module DiscourseDonations
|
|||
BadgeGranter.grant(badge, user)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log_group_add(grp)
|
||||
system_user = User.find(-1)
|
||||
GroupActionLogger.new(system_user, grp).log_add_user_to_group(user)
|
||||
|
|
|
@ -1,24 +1,56 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Jobs::DonationUser, type: :job do
|
||||
let(:args) { { email: 'fsfs4@example.com', username: 'sxsomething', name: 'ssbrian', password: 'ssecret-yo' } }
|
||||
let(:args) { { email: 'captain-sensible@example.com', username: 'wot', name: 'captain', password: 'wot' } }
|
||||
|
||||
before do
|
||||
SiteSetting.stubs(:enable_badges).returns(true)
|
||||
end
|
||||
|
||||
it 'creates a new user' do
|
||||
expect{ subject.execute(args) }.to change{ User.count }.by(1)
|
||||
it 'creates a new user with no rewards' do
|
||||
aggregate_failures do
|
||||
expect{ subject.execute(args) }.to change{ User.count }.by(1)
|
||||
user = User.find_by_email(args[:email])
|
||||
expect(user.badges).to be_empty
|
||||
expect(user.groups).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe 'rewards' do
|
||||
let(:user) { Fabricate(:user, args) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:badge) { Fabricate(:badge) }
|
||||
let(:grp) { Fabricate(:group) }
|
||||
|
||||
it 'has the badge' do
|
||||
before do
|
||||
User.expects(:create!).returns(user)
|
||||
subject.execute(args.merge(rewards: { type: 'badge', name: badge.name }))
|
||||
expect(user.badges).to include(badge)
|
||||
end
|
||||
|
||||
it 'grants the user a badge' do
|
||||
subject.execute(args.merge(rewards: [{ type: 'badge', name: badge.name }]))
|
||||
aggregate_failures do
|
||||
expect(user.badges).to include(badge)
|
||||
expect(user.groups).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
it 'adds the user to the group' do
|
||||
subject.execute(args.merge(rewards: [{ type: 'group', name: grp.name }]))
|
||||
aggregate_failures do
|
||||
expect(user.badges).to be_empty
|
||||
expect(user.groups).to include(grp)
|
||||
end
|
||||
end
|
||||
|
||||
it 'has no collisions in badges' do
|
||||
Fabricate(:badge, name: 'weiner_schitzel')
|
||||
subject.execute(args.merge(rewards: [{ type: 'group', name: 'weiner_schitzel' }]))
|
||||
expect(user.badges).to be_empty
|
||||
end
|
||||
|
||||
it 'has no collisions in groups' do
|
||||
Fabricate(:group, name: 'dude_ranch')
|
||||
subject.execute(args.merge(rewards: [{ type: 'badge', name: 'dude_ranch' }]))
|
||||
expect(user.groups).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue