diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/import/bitbucket_server_controller_spec.rb | 22 | ||||
-rw-r--r-- | spec/helpers/import_helper_spec.rb | 4 |
2 files changed, 23 insertions, 3 deletions
diff --git a/spec/controllers/import/bitbucket_server_controller_spec.rb b/spec/controllers/import/bitbucket_server_controller_spec.rb index bb282db5a41..a125e6ed16d 100644 --- a/spec/controllers/import/bitbucket_server_controller_spec.rb +++ b/spec/controllers/import/bitbucket_server_controller_spec.rb @@ -28,9 +28,11 @@ describe Import::BitbucketServerController do end describe 'POST create' do + let(:project_name) { "my-project_123" } + before do allow(controller).to receive(:bitbucket_client).and_return(client) - repo = double(name: 'my-project') + repo = double(name: project_name) allow(client).to receive(:repo).with(project_key, repo_slug).and_return(repo) assign_session_tokens end @@ -39,7 +41,7 @@ describe Import::BitbucketServerController do it 'returns the new project' do allow(Gitlab::BitbucketServerImport::ProjectCreator) - .to receive(:new).with(project_key, repo_slug, anything, 'my-project', user.namespace, user, anything) + .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything) .and_return(double(execute: project)) post :create, params: { project: project_key, repository: repo_slug }, format: :json @@ -47,6 +49,20 @@ describe Import::BitbucketServerController do expect(response).to have_gitlab_http_status(200) end + context 'with project key with tildes' do + let(:project_key) { '~someuser_123' } + + it 'successfully creates a project' do + allow(Gitlab::BitbucketServerImport::ProjectCreator) + .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything) + .and_return(double(execute: project)) + + post :create, params: { project: project_key, repository: repo_slug, format: :json } + + expect(response).to have_gitlab_http_status(200) + end + end + it 'returns an error when an invalid project key is used' do post :create, params: { project: 'some&project' } @@ -69,7 +85,7 @@ describe Import::BitbucketServerController do it 'returns an error when the project cannot be saved' do allow(Gitlab::BitbucketServerImport::ProjectCreator) - .to receive(:new).with(project_key, repo_slug, anything, 'my-project', user.namespace, user, anything) + .to receive(:new).with(project_key, repo_slug, anything, project_name, user.namespace, user, anything) .and_return(double(execute: build(:project))) post :create, params: { project: project_key, repository: repo_slug }, format: :json diff --git a/spec/helpers/import_helper_spec.rb b/spec/helpers/import_helper_spec.rb index cb0ea4e26ba..af4931e3370 100644 --- a/spec/helpers/import_helper_spec.rb +++ b/spec/helpers/import_helper_spec.rb @@ -2,6 +2,10 @@ require 'rails_helper' describe ImportHelper do describe '#sanitize_project_name' do + it 'removes leading tildes' do + expect(helper.sanitize_project_name('~~root')).to eq('root') + end + it 'removes whitespace' do expect(helper.sanitize_project_name('my test repo')).to eq('my-test-repo') end |