2016-06-02 11:05:42 +05:30
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ImportHelper do
|
2016-09-29 09:46:39 +05:30
|
|
|
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
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '#provider_project_link' do
|
|
|
|
context 'when provider is "github"' do
|
|
|
|
context 'when provider does not specify a custom URL' do
|
|
|
|
it 'uses default GitHub URL' do
|
|
|
|
allow(Gitlab.config.omniauth).to receive(:providers).
|
2016-06-02 11:05:42 +05:30
|
|
|
and_return([Settingslogic.new('name' => 'github')])
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(helper.provider_project_link('github', 'octocat/Hello-World')).
|
2016-06-02 11:05:42 +05:30
|
|
|
to include('href="https://github.com/octocat/Hello-World"')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'when provider specify a custom URL' do
|
|
|
|
it 'uses custom URL' do
|
|
|
|
allow(Gitlab.config.omniauth).to receive(:providers).
|
2016-06-02 11:05:42 +05:30
|
|
|
and_return([Settingslogic.new('name' => 'github', 'url' => 'https://github.company.com')])
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(helper.provider_project_link('github', 'octocat/Hello-World')).
|
2016-06-02 11:05:42 +05:30
|
|
|
to include('href="https://github.company.com/octocat/Hello-World"')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when provider is "gitea"' do
|
|
|
|
before do
|
|
|
|
assign(:gitea_host_url, 'https://try.gitea.io/')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses given host' do
|
|
|
|
expect(helper.provider_project_link('gitea', 'octocat/Hello-World')).
|
|
|
|
to include('href="https://try.gitea.io/octocat/Hello-World"')
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|