diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 15:07:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-01 15:07:45 +0000 |
commit | 1219a9dce91f4edbc135dfc08299b4122b4825a8 (patch) | |
tree | e7d12a55d75a2d56e60d9527bef3724e3578866d /spec/models/user_spec.rb | |
parent | 1a0d6dbdc2ac3047f4953a359ef27ba6e26074ae (diff) | |
download | gitlab-ce-1219a9dce91f4edbc135dfc08299b4122b4825a8.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r-- | spec/models/user_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f16b1fb136d..b21841ad034 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1221,6 +1221,10 @@ describe User, :do_not_mock_admin_mode do end it 'uses SecureRandom to generate the incoming email token' do + allow_next_instance_of(User) do |user| + allow(user).to receive(:update_highest_role) + end + expect(SecureRandom).to receive(:hex).and_return('3b8ca303') user = create(:user) @@ -4441,4 +4445,52 @@ describe User, :do_not_mock_admin_mode do end end end + + context 'when after_commit :update_highest_role' do + describe 'create user' do + it 'initializes a new Members::UpdateHighestRoleService object' do + expect_next_instance_of(Members::UpdateHighestRoleService) do |service| + expect(service).to receive(:execute) + end + + create(:user) + end + end + + context 'when user already exists' do + let!(:user) { create(:user) } + + describe 'update user' do + using RSpec::Parameterized::TableSyntax + + where(:attributes) do + [ + { state: 'blocked' }, + { ghost: true }, + { user_type: :alert_bot } + ] + end + + with_them do + context 'when state was changed' do + it 'initializes a new Members::UpdateHighestRoleService object' do + expect_next_instance_of(Members::UpdateHighestRoleService) do |service| + expect(service).to receive(:execute) + end + + user.update(attributes) + end + end + end + + context 'when state was not changed' do + it 'does not initialize a new Members::UpdateHighestRoleService object' do + expect(Members::UpdateHighestRoleService).not_to receive(:new) + + user.update(email: 'newmail@example.com') + end + end + end + end + end end |