log adding the user to a group
This commit is contained in:
parent
061ea69434
commit
d5c10de4c6
|
@ -2,6 +2,8 @@
|
|||
|
||||
module DiscourseDonations
|
||||
class Rewards
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
@ -9,13 +11,19 @@ module DiscourseDonations
|
|||
def add_to_group(name)
|
||||
grp = ::Group.find_by_name(name)
|
||||
return if grp.nil?
|
||||
grp.add(@user)
|
||||
log_group_add(grp)
|
||||
grp.add(user)
|
||||
end
|
||||
|
||||
def grant_badge(name)
|
||||
badge = ::Badge.find_by_name(name)
|
||||
return if badge.nil?
|
||||
BadgeGranter.grant(badge, @user)
|
||||
BadgeGranter.grant(badge, user)
|
||||
end
|
||||
|
||||
def log_group_add(grp)
|
||||
system_user = User.find(-1)
|
||||
GroupActionLogger.new(system_user, grp).log_add_user_to_group(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,15 +9,22 @@ module DiscourseDonations
|
|||
it 'adds the user to a group' do
|
||||
Group.expects(:find_by_name).with(grp.name).returns(grp)
|
||||
grp.expects(:add).with(user)
|
||||
subject.expects(:log_group_add).once
|
||||
subject.add_to_group(grp.name)
|
||||
end
|
||||
|
||||
it 'does not add the user to a group' do
|
||||
Group.expects(:find_by_name).with(grp.name).returns(nil)
|
||||
grp.expects(:add).never
|
||||
subject.expects(:log_group_add).never
|
||||
expect(subject.add_to_group(grp.name)).to be_falsy
|
||||
end
|
||||
|
||||
it 'logs the group add' do
|
||||
GroupActionLogger.any_instance.expects(:log_add_user_to_group)
|
||||
subject.add_to_group(grp.name)
|
||||
end
|
||||
|
||||
it 'grants the user a badge' do
|
||||
badge = Fabricate(:badge)
|
||||
BadgeGranter.expects(:grant).with(badge, user)
|
||||
|
|
Loading…
Reference in New Issue