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 ...@@ -96,9 +96,7 @@ module Groups
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def namespace_with_same_path? def namespace_with_same_path?
# Only check user namespace and Group, the ProjectNamespace will fail at project level Namespace.exists?(path: @group.path, parent: @new_parent_group)
# TODO 70972: review the exclusion of ProjectNamespace
Namespace.without_project_namespaces.exists?(path: @group.path, parent: @new_parent_group)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -13,7 +13,7 @@ RSpec.describe API::Namespaces do ...@@ -13,7 +13,7 @@ RSpec.describe API::Namespaces do
let_it_be(:ultimate_plan) { create(:ultimate_plan) } let_it_be(:ultimate_plan) { create(:ultimate_plan) }
let_it_be(:project) { create(:project, namespace: group2) } 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) { 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 describe "GET /namespaces" do
context "when authenticated as admin" do context "when authenticated as admin" do
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
FactoryBot.define do FactoryBot.define do
factory :project_namespace, class: 'Namespaces::ProjectNamespace' do factory :project_namespace, class: 'Namespaces::ProjectNamespace' do
project association :project, factory: :project, strategy: :build
parent { project.namespace } parent { project.namespace }
visibility_level { project.visibility_level } visibility_level { project.visibility_level }
name { project.name } name { project.name }
......
...@@ -566,7 +566,7 @@ RSpec.describe Group do ...@@ -566,7 +566,7 @@ RSpec.describe Group do
context 'when project namespace exists in the group' do context 'when project namespace exists in the group' do
let!(:project) { create(:project, group: group) } 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 it 'filters out project namespace' do
expect(group.descendants.find_by_id(project_namespace.id)).to be_nil expect(group.descendants.find_by_id(project_namespace.id)).to be_nil
......
...@@ -4,7 +4,8 @@ require 'spec_helper' ...@@ -4,7 +4,8 @@ require 'spec_helper'
RSpec.describe NamespacePolicy do RSpec.describe NamespacePolicy do
let_it_be(:parent) { create(:namespace) } 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 let(:permissions) do
[:owner_access, :create_projects, :admin_namespace, :read_namespace, [:owner_access, :create_projects, :admin_namespace, :read_namespace,
......
...@@ -8,7 +8,7 @@ RSpec.describe API::Namespaces do ...@@ -8,7 +8,7 @@ RSpec.describe API::Namespaces do
let_it_be(:group1) { create(:group, name: 'group.one') } let_it_be(:group1) { create(:group, name: 'group.one') }
let_it_be(:group2) { create(:group, :nested) } 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) { 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 describe "GET /namespaces" do
context "when unauthenticated" do context "when unauthenticated" do
......
...@@ -248,31 +248,38 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do ...@@ -248,31 +248,38 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do
let_it_be(:membership) { create(:group_member, :owner, group: new_parent_group, user: user) } 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) } let_it_be(:project) { create(:project, path: 'foo', namespace: new_parent_group) }
before do
group.update_attribute(:path, 'foo')
end
it 'returns false' do
expect(transfer_service.execute(new_parent_group)).to be_falsy
end
it 'adds an error on group' do 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') expect(transfer_service.error).to eq('Transfer failed: The parent group already has a subgroup or a project with the same path.')
end end
context 'when projects have project namespaces' do context 'with project namespace' do
before do before do
transfer_service.execute(new_parent_group) project_namespace = project.project_namespace
project.update!(project_namespace_id: nil)
project_namespace.destroy!
end end
it_behaves_like 'project namespace path is in sync with project path' do it 'adds an error on group' do
let(:group_full_path) { "#{new_parent_group.full_path}" } expect(transfer_service.execute(new_parent_group)).to be_falsy
let(:projects_with_project_namespace) { [project] } expect(transfer_service.error).to eq('Transfer failed: Validation failed: Group URL has already been taken')
end end
end 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
it_behaves_like 'project namespace path is in sync with project path' do
let(:group_full_path) { "#{new_parent_group.full_path}" }
let(:projects_with_project_namespace) { [project] }
end
end
context 'when the group is allowed to be transferred' do context 'when the group is allowed to be transferred' do
let_it_be(:new_parent_group, reload: true) { create(:group, :public) } let_it_be(:new_parent_group, reload: true) { create(:group, :public) }
let_it_be(:new_parent_group_integration) { create(:integrations_slack, group: new_parent_group, project: nil, webhook: 'http://new-group.slack.com') } let_it_be(:new_parent_group_integration) { create(:integrations_slack, group: new_parent_group, project: nil, webhook: 'http://new-group.slack.com') }
......
...@@ -23,7 +23,7 @@ RSpec.shared_examples 'namespace traversal' do ...@@ -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(: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(:groups) { [group, nested_group, deep_nested_group, very_deep_nested_group] }
let_it_be(:project) { create(:project, group: 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 describe '#root_ancestor' do
it 'returns the correct 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