diff options
Diffstat (limited to 'spec/support/controllers/githubish_import_controller_shared_examples.rb')
-rw-r--r-- | spec/support/controllers/githubish_import_controller_shared_examples.rb | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/spec/support/controllers/githubish_import_controller_shared_examples.rb b/spec/support/controllers/githubish_import_controller_shared_examples.rb index c59b30c772d..cd70126deb8 100644 --- a/spec/support/controllers/githubish_import_controller_shared_examples.rb +++ b/spec/support/controllers/githubish_import_controller_shared_examples.rb @@ -114,19 +114,7 @@ shared_examples 'a GitHub-ish import controller: POST create' do to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider). and_return(double(execute: true)) - post :create, format: :js - end - end - - context "when the provider user and GitLab user's usernames don't match" do - let(:provider_username) { "someone_else" } - - it "takes the current user's namespace" do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider). - and_return(double(execute: true)) - - post :create, format: :js + post :create, target_namespace: provider_username, format: :js end end end @@ -140,30 +128,27 @@ shared_examples 'a GitHub-ish import controller: POST create' do end context "when a namespace with the provider user's username already exists" do - let!(:existing_namespace) { create(:namespace, name: other_username, owner: user) } + let!(:existing_namespace) { create(:group, name: other_username) } context "when the namespace is owned by the GitLab user" do + before { existing_namespace.add_owner(user) } + it "takes the existing namespace" do expect(Gitlab::GithubImport::ProjectCreator). to receive(:new).with(provider_repo, provider_repo.name, existing_namespace, user, access_params, type: provider). and_return(double(execute: true)) - post :create, format: :js + post :create, target_namespace: existing_namespace.name, format: :js end end context "when the namespace is not owned by the GitLab user" do - before do - existing_namespace.owner = create(:user) - existing_namespace.save - end - it "creates a project using user's namespace" do expect(Gitlab::GithubImport::ProjectCreator). to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider). and_return(double(execute: true)) - post :create, format: :js + post :create, target_namespace: existing_namespace.name, format: :js end end end @@ -203,15 +188,17 @@ shared_examples 'a GitHub-ish import controller: POST create' do to receive(:new).with(provider_repo, provider_repo.name, user.namespace, user, access_params, type: provider). and_return(double(execute: true)) - post :create, format: :js + post :create, target_namespace: provider_username, format: :js end end end context 'user has chosen a namespace and name for the project' do - let(:test_namespace) { create(:namespace, name: 'test_namespace', owner: user) } + let(:test_namespace) { create(:group, name: 'test_namespace') } let(:test_name) { 'test_name' } + before { test_namespace.add_owner(user) } + it 'takes the selected namespace and name' do expect(Gitlab::GithubImport::ProjectCreator). to receive(:new).with(provider_repo, test_name, test_namespace, user, access_params, type: provider). @@ -219,21 +206,18 @@ shared_examples 'a GitHub-ish import controller: POST create' do post :create, { target_namespace: test_namespace.name, new_name: test_name, format: :js } end - - it 'takes the selected name and default namespace' do - expect(Gitlab::GithubImport::ProjectCreator). - to receive(:new).with(provider_repo, test_name, user.namespace, user, access_params, type: provider). - and_return(double(execute: true)) - - post :create, { new_name: test_name, format: :js } - end end context 'user has chosen an existing nested namespace and name for the project' do - let(:parent_namespace) { create(:namespace, name: 'foo', owner: user) } - let(:nested_namespace) { create(:namespace, name: 'bar', parent: parent_namespace, owner: user) } + let(:parent_namespace) { create(:group, name: 'foo') } + let(:nested_namespace) { create(:group, name: 'bar', parent: parent_namespace) } let(:test_name) { 'test_name' } + before do + parent_namespace.add_owner(user) + nested_namespace.add_owner(user) + end + it 'takes the selected namespace and name' do expect(Gitlab::GithubImport::ProjectCreator). to receive(:new).with(provider_repo, test_name, nested_namespace, user, access_params, type: provider). @@ -276,7 +260,9 @@ shared_examples 'a GitHub-ish import controller: POST create' do context 'user has chosen existent and non-existent nested namespaces and name for the project' do let(:test_name) { 'test_name' } - let!(:parent_namespace) { create(:namespace, name: 'foo', owner: user) } + let!(:parent_namespace) { create(:group, name: 'foo') } + + before { parent_namespace.add_owner(user) } it 'takes the selected namespace and name' do expect(Gitlab::GithubImport::ProjectCreator). |