diff options
author | James Lopez <james@jameslopez.es> | 2017-06-23 12:34:07 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2017-06-23 12:41:43 +0300 |
commit | b804db26485ea09dc93269898dc969ed692130a2 (patch) | |
tree | 48ac76727eed23a2815b14e8c5633bbb056f6972 /spec/services | |
parent | e2e0b175ae43bef44ba5fdc45b4a719aaae83422 (diff) |
refactor update user service not to do auth checks
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/users/update_service_spec.rb | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/spec/services/users/update_service_spec.rb b/spec/services/users/update_service_spec.rb index fd32a4f0f33..6c33a232cb0 100644 --- a/spec/services/users/update_service_spec.rb +++ b/spec/services/users/update_service_spec.rb @@ -2,61 +2,42 @@ require 'spec_helper' describe Users::UpdateService, services: true do let(:user) { create(:user) } - let(:admin) { create(:admin) } describe '#execute' do it 'updates the name' do - result = update_user(user, user, name: 'New Name') + result = update_user(user, name: 'New Name') expect(result).to eq({ status: :success }) expect(user.name).to eq('New Name') end - context 'when updated by an admin' do - it 'updates the name' do - result = update_user(admin, user, name: 'New Name') - - expect(result).to eq({ status: :success }) - expect(user.name).to eq('New Name') - end - end - it 'returns an error result when record cannot be updated' do expect do - update_user(user, create(:user), { name: 'New Name' }) - end.to raise_error Gitlab::Access::AccessDeniedError + update_user(user, { email: 'invalid' }) + end.not_to change { user.reload.email } end - def update_user(current_user, user, opts) - described_class.new(current_user, user, opts).execute + def update_user(user, opts) + described_class.new(user, opts).execute end end describe '#execute!' do it 'updates the name' do - result = update_user(user, user, name: 'New Name') + result = update_user(user, name: 'New Name') expect(result).to be true expect(user.name).to eq('New Name') end - context 'when updated by an admin' do - it 'updates the name' do - result = update_user(admin, user, name: 'New Name') - - expect(result).to be true - expect(user.name).to eq('New Name') - end - end - it 'returns an error result when record cannot be updated' do expect do - update_user(user, create(:user), { name: 'New Name' }) - end.to raise_error Gitlab::Access::AccessDeniedError + update_user(user, { email: 'invalid' }) + end.to raise_error(ActiveRecord::RecordInvalid) end - def update_user(current_user, user, opts) - described_class.new(current_user, user, opts).execute! + def update_user(user, opts) + described_class.new(user, opts).execute! end end end |