2016-04-18 23:01:33 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ImportHelper do
|
2018-08-23 22:21:06 +00:00
|
|
|
describe '#sanitize_project_name' do
|
2018-12-06 00:43:29 +00:00
|
|
|
it 'removes leading tildes' do
|
|
|
|
expect(helper.sanitize_project_name('~~root')).to eq('root')
|
|
|
|
end
|
|
|
|
|
2018-08-23 22:21:06 +00:00
|
|
|
it 'removes whitespace' do
|
|
|
|
expect(helper.sanitize_project_name('my test repo')).to eq('my-test-repo')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes disallowed characters' do
|
|
|
|
expect(helper.sanitize_project_name('Test&me$over*h_ere')).to eq('Test-me-over-h_ere')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-29 21:17:11 +00:00
|
|
|
describe '#import_project_target' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current user can create namespaces' do
|
|
|
|
it 'returns project namespace' do
|
|
|
|
user.update_attribute(:can_create_group, true)
|
|
|
|
|
|
|
|
expect(helper.import_project_target('asd', 'vim')).to eq 'asd/vim'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current user can not create namespaces' do
|
|
|
|
it "takes the current user's namespace" do
|
|
|
|
user.update_attribute(:can_create_group, false)
|
|
|
|
|
|
|
|
expect(helper.import_project_target('asd', 'vim')).to eq "#{user.namespace_path}/vim"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-07 16:44:21 +00:00
|
|
|
describe '#provider_project_link_url' do
|
|
|
|
let(:full_path) { '/repo/path' }
|
|
|
|
let(:host_url) { 'http://provider.com/' }
|
2018-03-12 21:01:43 +00:00
|
|
|
|
2018-11-07 16:44:21 +00:00
|
|
|
it 'appends repo full path to provider host url' do
|
|
|
|
expect(helper.provider_project_link_url(host_url, full_path)).to match('http://provider.com/repo/path')
|
2016-04-18 23:01:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|