summaryrefslogtreecommitdiff
path: root/spec/helpers/import_helper_spec.rb
blob: 187b891b9273c2b85f121af71e9866bcfe33c882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'rails_helper'

describe ImportHelper do
  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

  describe '#github_project_link' do
    context 'when provider does not specify a custom URL' do
      it 'uses default GitHub URL' do
        allow(Gitlab.config.omniauth).to receive(:providers).
          and_return([Settingslogic.new('name' => 'github')])

        expect(helper.github_project_link('octocat/Hello-World')).
          to include('href="https://github.com/octocat/Hello-World"')
      end
    end

    context 'when provider specify a custom URL' do
      it 'uses custom URL' do
        allow(Gitlab.config.omniauth).to receive(:providers).
          and_return([Settingslogic.new('name' => 'github', 'url' => 'https://github.company.com')])

        expect(helper.github_project_link('octocat/Hello-World')).
          to include('href="https://github.company.com/octocat/Hello-World"')
      end
    end
  end
end