FIX: Do not send staff welcome message if user already has role
This commit is contained in:
parent
9da3a7f436
commit
6caad5c083
|
@ -19,6 +19,7 @@ module Roleable
|
|||
end
|
||||
|
||||
def grant_moderation!
|
||||
return if moderator
|
||||
set_permission('moderator', true)
|
||||
auto_approve_user
|
||||
enqueue_staff_welcome_message(:moderator)
|
||||
|
@ -29,6 +30,7 @@ module Roleable
|
|||
end
|
||||
|
||||
def grant_admin!
|
||||
return if admin
|
||||
set_permission('admin', true)
|
||||
auto_approve_user
|
||||
enqueue_staff_welcome_message(:admin)
|
||||
|
|
|
@ -164,6 +164,30 @@ describe User do
|
|||
end
|
||||
end
|
||||
|
||||
context 'enqueue_staff_welcome_message' do
|
||||
let!(:first_admin) { Fabricate(:admin) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it 'enqueues message for admin' do
|
||||
expect {
|
||||
user.grant_admin!
|
||||
}.to change { Jobs::SendSystemMessage.jobs.count }.by 1
|
||||
end
|
||||
|
||||
it 'enqueues message for moderator' do
|
||||
expect {
|
||||
user.grant_moderation!
|
||||
}.to change { Jobs::SendSystemMessage.jobs.count }.by 1
|
||||
end
|
||||
|
||||
it 'skips the message if already an admin' do
|
||||
user.update(admin: true)
|
||||
expect {
|
||||
user.grant_admin!
|
||||
}.to change { Jobs::SendSystemMessage.jobs.count }.by 0
|
||||
end
|
||||
end
|
||||
|
||||
context '.set_default_tags_preferences' do
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue