Skip to content
Snippets Groups Projects
Commit 79534806 authored by Stan Hu's avatar Stan Hu
Browse files

Fix remaining Bitbucket controller specs

parent af692628
No related branches found
No related tags found
No related merge requests found
Loading
@@ -46,7 +46,7 @@ class Import::BitbucketController < Import::BaseController
Loading
@@ -46,7 +46,7 @@ class Import::BitbucketController < Import::BaseController
repo_owner = current_user.username if repo_owner == bitbucket_client.user.username repo_owner = current_user.username if repo_owner == bitbucket_client.user.username
@target_namespace = params[:new_namespace].presence || repo_owner @target_namespace = params[:new_namespace].presence || repo_owner
   
namespace = find_or_create_namespace(@target_namespace, repo_owner) namespace = find_or_create_namespace(@target_namespace, current_user)
   
if current_user.can?(:create_projects, namespace) if current_user.can?(:create_projects, namespace)
@project = Gitlab::BitbucketImport::ProjectCreator.new(repo, @project_name, namespace, current_user, credentials).execute @project = Gitlab::BitbucketImport::ProjectCreator.new(repo, @project_name, namespace, current_user, credentials).execute
Loading
Loading
Loading
@@ -7,7 +7,7 @@ describe Import::BitbucketController do
Loading
@@ -7,7 +7,7 @@ describe Import::BitbucketController do
let(:token) { "asdasd12345" } let(:token) { "asdasd12345" }
let(:secret) { "sekrettt" } let(:secret) { "sekrettt" }
let(:refresh_token) { SecureRandom.hex(15) } let(:refresh_token) { SecureRandom.hex(15) }
let(:access_params) { { bitbucket_access_token: token, bitbucket_access_token_secret: secret } } let(:access_params) { { token: token, expires_at: nil, expires_in: nil, refresh_token: nil } }
   
def assign_session_tokens def assign_session_tokens
session[:bitbucket_token] = token session[:bitbucket_token] = token
Loading
@@ -77,19 +77,16 @@ describe Import::BitbucketController do
Loading
@@ -77,19 +77,16 @@ describe Import::BitbucketController do
let(:bitbucket_username) { user.username } let(:bitbucket_username) { user.username }
   
let(:bitbucket_user) do let(:bitbucket_user) do
{ user: { username: bitbucket_username } }.with_indifferent_access double(username: bitbucket_username)
end end
   
let(:bitbucket_repo) do let(:bitbucket_repo) do
{ slug: "vim", owner: bitbucket_username }.with_indifferent_access double(slug: "vim", owner: bitbucket_username, name: 'vim')
end end
   
before do before do
allow(Gitlab::BitbucketImport::KeyAdder). allow_any_instance_of(Bitbucket::Client).to receive(:repo).and_return(bitbucket_repo)
to receive(:new).with(bitbucket_repo, user, access_params). allow_any_instance_of(Bitbucket::Client).to receive(:user).and_return(bitbucket_user)
and_return(double(execute: true))
stub_client(user: bitbucket_user, project: bitbucket_repo)
assign_session_tokens assign_session_tokens
end end
   
Loading
@@ -97,7 +94,7 @@ describe Import::BitbucketController do
Loading
@@ -97,7 +94,7 @@ describe Import::BitbucketController do
context "when the Bitbucket user and GitLab user's usernames match" do context "when the Bitbucket user and GitLab user's usernames match" do
it "takes the current user's namespace" do it "takes the current user's namespace" do
expect(Gitlab::BitbucketImport::ProjectCreator). expect(Gitlab::BitbucketImport::ProjectCreator).
to receive(:new).with(bitbucket_repo, user.namespace, user, access_params). to receive(:new).with(bitbucket_repo, bitbucket_repo.name, user.namespace, user, access_params).
and_return(double(execute: true)) and_return(double(execute: true))
   
post :create, format: :js post :create, format: :js
Loading
@@ -109,7 +106,7 @@ describe Import::BitbucketController do
Loading
@@ -109,7 +106,7 @@ describe Import::BitbucketController do
   
it "takes the current user's namespace" do it "takes the current user's namespace" do
expect(Gitlab::BitbucketImport::ProjectCreator). expect(Gitlab::BitbucketImport::ProjectCreator).
to receive(:new).with(bitbucket_repo, user.namespace, user, access_params). to receive(:new).with(bitbucket_repo, bitbucket_repo.name, user.namespace, user, access_params).
and_return(double(execute: true)) and_return(double(execute: true))
   
post :create, format: :js post :create, format: :js
Loading
@@ -121,7 +118,7 @@ describe Import::BitbucketController do
Loading
@@ -121,7 +118,7 @@ describe Import::BitbucketController do
let(:other_username) { "someone_else" } let(:other_username) { "someone_else" }
   
before do before do
bitbucket_repo["owner"] = other_username allow(bitbucket_repo).to receive(:owner).and_return(other_username)
end end
   
context "when a namespace with the Bitbucket user's username already exists" do context "when a namespace with the Bitbucket user's username already exists" do
Loading
@@ -130,7 +127,7 @@ describe Import::BitbucketController do
Loading
@@ -130,7 +127,7 @@ describe Import::BitbucketController do
context "when the namespace is owned by the GitLab user" do context "when the namespace is owned by the GitLab user" do
it "takes the existing namespace" do it "takes the existing namespace" do
expect(Gitlab::BitbucketImport::ProjectCreator). expect(Gitlab::BitbucketImport::ProjectCreator).
to receive(:new).with(bitbucket_repo, existing_namespace, user, access_params). to receive(:new).with(bitbucket_repo, bitbucket_repo.name, existing_namespace, user, access_params).
and_return(double(execute: true)) and_return(double(execute: true))
   
post :create, format: :js post :create, format: :js
Loading
@@ -163,7 +160,7 @@ describe Import::BitbucketController do
Loading
@@ -163,7 +160,7 @@ describe Import::BitbucketController do
   
it "takes the new namespace" do it "takes the new namespace" do
expect(Gitlab::BitbucketImport::ProjectCreator). expect(Gitlab::BitbucketImport::ProjectCreator).
to receive(:new).with(bitbucket_repo, an_instance_of(Group), user, access_params). to receive(:new).with(bitbucket_repo, bitbucket_repo.name, an_instance_of(Group), user, access_params).
and_return(double(execute: true)) and_return(double(execute: true))
   
post :create, format: :js post :create, format: :js
Loading
@@ -184,7 +181,7 @@ describe Import::BitbucketController do
Loading
@@ -184,7 +181,7 @@ describe Import::BitbucketController do
   
it "takes the current user's namespace" do it "takes the current user's namespace" do
expect(Gitlab::BitbucketImport::ProjectCreator). expect(Gitlab::BitbucketImport::ProjectCreator).
to receive(:new).with(bitbucket_repo, user.namespace, user, access_params). to receive(:new).with(bitbucket_repo, bitbucket_repo.name, user.namespace, user, access_params).
and_return(double(execute: true)) and_return(double(execute: true))
   
post :create, format: :js post :create, format: :js
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment