gitlab-org--gitlab-foss/spec/services/users/update_service_spec.rb

44 lines
1 KiB
Ruby
Raw Normal View History

2017-06-13 05:32:21 -04:00
require 'spec_helper'
describe Users::UpdateService, services: true do
let(:user) { create(:user) }
describe '#execute' do
it 'updates the name' do
result = update_user(user, name: 'New Name')
2017-06-13 10:24:36 -04:00
2017-06-23 11:11:31 -04:00
expect(result).to eq(status: :success)
2017-06-13 05:32:21 -04:00
expect(user.name).to eq('New Name')
end
it 'returns an error result when record cannot be updated' do
2017-06-13 07:52:20 -04:00
expect do
update_user(user, { email: 'invalid' })
end.not_to change { user.reload.email }
2017-06-13 05:32:21 -04:00
end
def update_user(user, opts)
described_class.new(user, opts).execute
2017-06-13 05:32:21 -04:00
end
end
2017-06-13 10:24:36 -04:00
describe '#execute!' do
it 'updates the name' do
result = update_user(user, name: 'New Name')
2017-06-13 10:24:36 -04:00
expect(result).to be true
expect(user.name).to eq('New Name')
end
2017-06-23 11:11:31 -04:00
it 'raises an error when record cannot be updated' do
2017-06-13 10:24:36 -04:00
expect do
2017-06-23 11:11:31 -04:00
update_user(user, email: 'invalid')
end.to raise_error(ActiveRecord::RecordInvalid)
2017-06-13 10:24:36 -04:00
end
def update_user(user, opts)
described_class.new(user, opts).execute!
2017-06-13 10:24:36 -04:00
end
end
2017-06-13 05:32:21 -04:00
end