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

56 lines
1.5 KiB
Ruby
Raw Normal View History

2017-04-13 04:47:52 -04:00
require 'spec_helper'
describe Users::BuildService do
2017-04-13 04:47:52 -04:00
describe '#execute' do
let(:params) do
{ name: 'John Doe', username: 'jduser', email: 'jd@example.com', password: 'mydummypass' }
end
context 'with an admin user' do
let(:admin_user) { create(:admin) }
let(:service) { described_class.new(admin_user, params) }
it 'returns a valid user' do
expect(service.execute).to be_valid
end
end
context 'with non admin user' do
let(:user) { create(:user) }
let(:service) { described_class.new(user, params) }
it 'raises AccessDeniedError exception' do
expect { service.execute }.to raise_error Gitlab::Access::AccessDeniedError
end
end
context 'with nil user' do
let(:service) { described_class.new(nil, params) }
it 'returns a valid user' do
expect(service.execute).to be_valid
end
context 'when "send_user_confirmation_email" application setting is true' do
before do
2017-04-13 15:13:55 -04:00
stub_application_setting(send_user_confirmation_email: true, signup_enabled?: true)
2017-04-13 04:47:52 -04:00
end
it 'does not confirm the user' do
expect(service.execute).not_to be_confirmed
end
end
context 'when "send_user_confirmation_email" application setting is false' do
before do
2017-04-13 15:13:55 -04:00
stub_application_setting(send_user_confirmation_email: false, signup_enabled?: true)
2017-04-13 04:47:52 -04:00
end
it 'confirms the user' do
expect(service.execute).to be_confirmed
end
end
end
end
end