debian-mirror-gitlab/spec/services/users/signup_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.3 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Users::SignupService do
2019-12-26 22:10:19 +05:30
let(:user) { create(:user, setup_for_company: true) }
describe '#execute' do
context 'when updating name' do
it 'updates the name attribute' do
result = update_user(user, name: 'New Name')
2023-03-17 16:20:25 +05:30
expect(result.success?).to be(true)
2019-12-26 22:10:19 +05:30
expect(user.reload.name).to eq('New Name')
end
it 'returns an error result when name is missing' do
result = update_user(user, name: '')
expect(user.reload.name).not_to be_blank
2023-03-17 16:20:25 +05:30
expect(result.success?).to be(false)
expect(result.message).to include("Name can't be blank")
2019-12-26 22:10:19 +05:30
end
end
context 'when updating role' do
it 'updates the role attribute' do
result = update_user(user, role: 'development_team_lead')
2023-03-17 16:20:25 +05:30
expect(result.success?).to be(true)
2019-12-26 22:10:19 +05:30
expect(user.reload.role).to eq('development_team_lead')
end
it 'returns an error result when role is missing' do
result = update_user(user, role: '')
expect(user.reload.role).not_to be_blank
2023-03-17 16:20:25 +05:30
expect(result.success?).to be(false)
expect(result.message).to eq("Role can't be blank")
2019-12-26 22:10:19 +05:30
end
end
context 'when updating setup_for_company' do
it 'updates the setup_for_company attribute' do
result = update_user(user, setup_for_company: 'false')
2023-03-17 16:20:25 +05:30
expect(result.success?).to be(true)
2019-12-26 22:10:19 +05:30
expect(user.reload.setup_for_company).to be(false)
end
2020-11-24 15:15:51 +05:30
context 'when on .com' do
before do
allow(Gitlab).to receive(:com?).and_return(true)
end
2019-12-26 22:10:19 +05:30
2020-11-24 15:15:51 +05:30
it 'returns an error result when setup_for_company is missing' do
result = update_user(user, setup_for_company: '')
expect(user.reload.setup_for_company).not_to be_blank
2023-03-17 16:20:25 +05:30
expect(result.success?).to be(false)
expect(result.message).to eq("Setup for company can't be blank")
2020-11-24 15:15:51 +05:30
end
end
context 'when not on .com' do
it 'returns success when setup_for_company is blank' do
result = update_user(user, setup_for_company: '')
2023-03-17 16:20:25 +05:30
expect(result.success?).to be(true)
2020-11-24 15:15:51 +05:30
expect(user.reload.setup_for_company).to be(nil)
end
2019-12-26 22:10:19 +05:30
end
end
def update_user(user, opts)
described_class.new(user, opts).execute
end
end
end