diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2017-11-03 11:26:52 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-11-03 11:26:52 +0000 |
commit | 6f1a4ba457afd92a12913a9eddd7af483f5cfff1 (patch) | |
tree | a95d5a1aa50afc13068cb11167c5b075b05994f1 /spec/models/user_spec.rb | |
parent | 7961c235d57bd1933d6687619a7b2162b9cf3bfc (diff) | |
download | gitlab-ce-6f1a4ba457afd92a12913a9eddd7af483f5cfff1.tar.gz |
Add system hooks user_rename and group_rename
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r-- | spec/models/user_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fb03e320734..e0896d64c8f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2217,6 +2217,42 @@ describe User do end end + describe '#username_changed_hook' do + context 'for a new user' do + let(:user) { build(:user) } + + it 'does not trigger system hook' do + expect(user).not_to receive(:system_hook_service) + + user.save! + end + end + + context 'for an existing user' do + let(:user) { create(:user, username: 'old-username') } + + context 'when the username is changed' do + let(:new_username) { 'very-new-name' } + + it 'triggers the rename system hook' do + system_hook_service = SystemHooksService.new + expect(system_hook_service).to receive(:execute_hooks_for).with(user, :rename) + expect(user).to receive(:system_hook_service).and_return(system_hook_service) + + user.update_attributes!(username: new_username) + end + end + + context 'when the username is not changed' do + it 'does not trigger system hook' do + expect(user).not_to receive(:system_hook_service) + + user.update_attributes!(email: 'asdf@asdf.com') + end + end + end + end + describe '#sync_attribute?' do let(:user) { described_class.new } |