diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-08 06:13:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-08 06:13:30 +0300 |
commit | e7dc35bfd6a07a4c23f83b8173df2e4d1963402a (patch) | |
tree | 147b068237283afecc2c308e48d88134ac295c5b /spec | |
parent | 0a7deb30e20d92bd1251cfc25ce3a0e75c12f188 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
4 files changed, 55 insertions, 0 deletions
diff --git a/spec/factories/organizations/organization_users.rb b/spec/factories/organizations/organization_users.rb index 761f260ccb3..d73d2386356 100644 --- a/spec/factories/organizations/organization_users.rb +++ b/spec/factories/organizations/organization_users.rb @@ -4,5 +4,9 @@ FactoryBot.define do factory :organization_user, class: 'Organizations::OrganizationUser' do user organization + + trait :owner do + access_level { Gitlab::Access::OWNER } + end end end diff --git a/spec/models/organizations/organization_spec.rb b/spec/models/organizations/organization_spec.rb index aba2b03d4d1..7a3c743eddd 100644 --- a/spec/models/organizations/organization_spec.rb +++ b/spec/models/organizations/organization_spec.rb @@ -204,6 +204,32 @@ RSpec.describe Organizations::Organization, type: :model, feature_category: :cel end end + describe '#owner?' do + let_it_be(:user) { create(:user) } + + subject { organization.owner?(user) } + + context 'when user is an owner' do + before do + create(:organization_user, :owner, organization: organization, user: user) + end + + it { is_expected.to eq true } + end + + context 'when user is not an owner' do + before do + create(:organization_user, organization: organization, user: user) + end + + it { is_expected.to eq false } + end + + context 'when user is not an organization user' do + it { is_expected.to eq false } + end + end + describe '#web_url' do it 'returns web url from `Gitlab::UrlBuilder`' do web_url = 'http://127.0.0.1:3000/-/organizations/default' diff --git a/spec/models/organizations/organization_user_spec.rb b/spec/models/organizations/organization_user_spec.rb index 9a2f11e0654..c3416c93ec9 100644 --- a/spec/models/organizations/organization_user_spec.rb +++ b/spec/models/organizations/organization_user_spec.rb @@ -8,6 +8,18 @@ RSpec.describe Organizations::OrganizationUser, type: :model, feature_category: it { is_expected.to belong_to(:user).inverse_of(:organization_users).required } end + describe 'validations' do + subject { build(:organization_user) } + + it { is_expected.to define_enum_for(:access_level).with_values(described_class.access_levels) } + it { is_expected.to validate_presence_of(:access_level) } + it { is_expected.to validate_uniqueness_of(:user).scoped_to(:organization_id) } + + it 'does not allow invalid enum value' do + expect { build(:organization_user, access_level: '_invalid_') }.to raise_error(ArgumentError) + end + end + context 'with loose foreign key on organization_users.organization_id' do it_behaves_like 'cleanup by a loose foreign key' do let_it_be(:parent) { create(:organization) } @@ -21,4 +33,15 @@ RSpec.describe Organizations::OrganizationUser, type: :model, feature_category: let_it_be(:model) { create(:organization_user, user: parent) } end end + + describe '.owners' do + it 'returns the owners of the organization' do + organization_user = create(:organization_user, :owner) + create(:organization_user) + + expect(described_class.owners).to match([organization_user]) + end + end + + it_behaves_like 'having unique enum values' end diff --git a/spec/services/organizations/create_service_spec.rb b/spec/services/organizations/create_service_spec.rb index aae89517c15..bbc0f3d7515 100644 --- a/spec/services/organizations/create_service_spec.rb +++ b/spec/services/organizations/create_service_spec.rb @@ -29,11 +29,13 @@ RSpec.describe Organizations::CreateService, feature_category: :cell do shared_examples 'creating an organization' do it 'creates the organization' do expect { response }.to change { Organizations::Organization.count } + .and change { Organizations::OrganizationUser.count }.by(1) expect(response).to be_success expect(created_organization.name).to eq(params[:name]) expect(created_organization.path).to eq(params[:path]) expect(created_organization.description).to eq(params[:description]) expect(created_organization.avatar.filename).to eq(avatar_filename) + expect(created_organization.owner?(current_user)).to be(true) end end |