FIX: Granting staff status should auto-approve users waiting approval (#8533)

* FIX: Granting staff status should auto-approve users waiting approval

* Update app/models/concerns/roleable.rb

Co-Authored-By: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
Roman Rizzi
2019-12-12 16:26:38 -03:00
committed by GitHub
parent 76f676879c
commit b6a2875749
4 changed files with 55 additions and 1 deletions

View File

@ -2240,4 +2240,39 @@ describe User do
end
end
end
describe 'Granting admin or moderator status' do
it 'approves the associated reviewable when granting admin status' do
reviewable_user = Fabricate(:reviewable_user)
reviewable_user.target.grant_admin!
expect(reviewable_user.reload.status).to eq Reviewable.statuses[:approved]
end
it 'does nothing when the user is already approved' do
reviewable_user = Fabricate(:reviewable_user)
reviewable_user.perform(Discourse.system_user, :approve_user)
reviewable_user.target.grant_admin!
expect(reviewable_user.reload.status).to eq Reviewable.statuses[:approved]
end
it 'approves the associated reviewable when granting moderator status' do
reviewable_user = Fabricate(:reviewable_user)
reviewable_user.target.grant_moderation!
expect(reviewable_user.reload.status).to eq Reviewable.statuses[:approved]
end
it 'approves the user if there is no reviewable' do
user = Fabricate(:user, approved: false)
user.grant_admin!
expect(user.approved).to eq(true)
end
end
end