Commit 26e68dbe authored by Alexandru Croitor's avatar Alexandru Croitor

Project namespace related spec fixes

calling the project namespace factory tries to create
a duplicate namespace because one is already created as
part of the creating project throguh project factory.
parent 63220fc8
......@@ -96,9 +96,7 @@ module Groups
# rubocop: disable CodeReuse/ActiveRecord
def namespace_with_same_path?
# Only check user namespace and Group, the ProjectNamespace will fail at project level
# TODO 70972: review the exclusion of ProjectNamespace
Namespace.without_project_namespaces.exists?(path: @group.path, parent: @new_parent_group)
Namespace.exists?(path: @group.path, parent: @new_parent_group)
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -13,7 +13,7 @@ RSpec.describe API::Namespaces do
let_it_be(:ultimate_plan) { create(:ultimate_plan) }
let_it_be(:project) { create(:project, namespace: group2) }
let_it_be(:project) { create(:project, namespace: group2, name: group2.name, path: group2.path) }
let_it_be(:project_namespace) { create(:project_namespace, project: project) }
let_it_be(:project_namespace) { project.project_namespace }
describe "GET /namespaces" do
context "when authenticated as admin" do
......
......@@ -2,7 +2,7 @@
FactoryBot.define do
factory :project_namespace, class: 'Namespaces::ProjectNamespace' do
project
association :project, factory: :project, strategy: :build
parent { project.namespace }
visibility_level { project.visibility_level }
name { project.name }
......
......@@ -566,7 +566,7 @@ RSpec.describe Group do
context 'when project namespace exists in the group' do
let!(:project) { create(:project, group: group) }
let!(:project_namespace) { create(:project_namespace, project: project) }
let!(:project_namespace) { project.project_namespace }
it 'filters out project namespace' do
expect(group.descendants.find_by_id(project_namespace.id)).to be_nil
......
......@@ -4,7 +4,8 @@ require 'spec_helper'
RSpec.describe NamespacePolicy do
let_it_be(:parent) { create(:namespace) }
let_it_be(:namespace) { create(:project_namespace, parent: parent) }
let_it_be(:project) { create(:project, namespace: parent) }
let_it_be(:namespace) { project.project_namespace }
let(:permissions) do
[:owner_access, :create_projects, :admin_namespace, :read_namespace,
......
......@@ -8,7 +8,7 @@ RSpec.describe API::Namespaces do
let_it_be(:group1) { create(:group, name: 'group.one') }
let_it_be(:group2) { create(:group, :nested) }
let_it_be(:project) { create(:project, namespace: group2, name: group2.name, path: group2.path) }
let_it_be(:project_namespace) { create(:project_namespace, project: project) }
let_it_be(:project_namespace) { project.project_namespace }
describe "GET /namespaces" do
context "when unauthenticated" do
......
......@@ -248,20 +248,28 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do
let_it_be(:membership) { create(:group_member, :owner, group: new_parent_group, user: user) }
let_it_be(:project) { create(:project, path: 'foo', namespace: new_parent_group) }
before do
group.update_attribute(:path, 'foo')
it 'adds an error on group' do
expect(transfer_service.execute(new_parent_group)).to be_falsy
expect(transfer_service.error).to eq('Transfer failed: The parent group already has a subgroup or a project with the same path.')
end
it 'returns false' do
expect(transfer_service.execute(new_parent_group)).to be_falsy
context 'with project namespace' do
before do
project_namespace = project.project_namespace
project.update!(project_namespace_id: nil)
project_namespace.destroy!
end
it 'adds an error on group' do
transfer_service.execute(new_parent_group)
expect(transfer_service.execute(new_parent_group)).to be_falsy
expect(transfer_service.error).to eq('Transfer failed: Validation failed: Group URL has already been taken')
end
end
end
context 'when projects have project namespaces' do
let_it_be(:project) { create(:project, path: 'foo', namespace: new_parent_group) }
before do
transfer_service.execute(new_parent_group)
end
......@@ -271,7 +279,6 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do
let(:projects_with_project_namespace) { [project] }
end
end
end
context 'when the group is allowed to be transferred' do
let_it_be(:new_parent_group, reload: true) { create(:group, :public) }
......
......@@ -23,7 +23,7 @@ RSpec.shared_examples 'namespace traversal' do
let_it_be(:very_deep_nested_group) { create(:group, parent: deep_nested_group) }
let_it_be(:groups) { [group, nested_group, deep_nested_group, very_deep_nested_group] }
let_it_be(:project) { create(:project, group: nested_group) }
let_it_be(:project_namespace) { create(:project_namespace, project: project) }
let_it_be(:project_namespace) { project.project_namespace }
describe '#root_ancestor' do
it 'returns the correct root ancestor' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment