2017-06-13 09:32:21 +00:00
|
|
|
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')
|
|
|
|
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
|
2017-06-13 11:52:20 +00:00
|
|
|
result = update_user(admin, user, name: 'New Name')
|
2017-06-13 09:32:21 +00:00
|
|
|
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
|
2017-06-13 11:52:20 +00:00
|
|
|
expect do
|
|
|
|
update_user(user, create(:user), { name: 'New Name' })
|
|
|
|
end.to raise_error Gitlab::Access::AccessDeniedError
|
2017-06-13 09:32:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_user(current_user, user, opts)
|
2017-06-13 11:52:20 +00:00
|
|
|
described_class.new(current_user, user, opts).execute
|
2017-06-13 09:32:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|