FIX: Do not send staff welcome message if user already has role

This commit is contained in:
David Taylor 2020-06-17 12:12:55 +01:00
parent 9da3a7f436
commit 6caad5c083
No known key found for this signature in database
GPG Key ID: 46904C18B1D3F434
2 changed files with 26 additions and 0 deletions

View File

@ -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)

View File

@ -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) }