BigW Consortium Gitlab

project_creator_spec.rb 2.22 KB
Newer Older
Valery Sizov committed
1 2
require 'spec_helper'

Douwe Maan committed
3
describe Gitlab::GithubImport::ProjectCreator, lib: true do
4
  let(:user) { create(:user) }
5 6
  let(:namespace) { create(:group, owner: user) }

7 8 9 10 11
  let(:repo) do
    OpenStruct.new(
      login: 'vim',
      name: 'vim',
      full_name: 'asd/vim',
12
      clone_url: 'https://gitlab.com/asd/vim.git'
13 14
    )
  end
15

16
  subject(:service) { described_class.new(repo, repo.name, namespace, user, github_access_token: 'asdffg') }
17 18 19

  before do
    namespace.add_owner(user)
20
    allow_any_instance_of(Project).to receive(:add_import_job)
21
  end
Valery Sizov committed
22

23 24 25 26 27 28 29 30 31 32 33 34 35
  describe '#execute' do
    it 'creates a project' do
      expect { service.execute }.to change(Project, :count).by(1)
    end

    it 'handle GitHub credentials' do
      project = service.execute

      expect(project.import_url).to eq('https://asdffg@gitlab.com/asd/vim.git')
      expect(project.safe_import_url).to eq('https://*****@gitlab.com/asd/vim.git')
      expect(project.import_data.credentials).to eq(user: 'asdffg', password: nil)
    end

36
    context 'when GitHub project is private' do
37 38 39 40 41 42 43 44 45
      it 'sets project visibility to private' do
        repo.private = true

        project = service.execute

        expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
      end
    end

46
    context 'when GitHub project is public' do
47 48 49 50 51 52
      before do
        allow_any_instance_of(ApplicationSetting).to receive(:default_project_visibility).and_return(Gitlab::VisibilityLevel::INTERNAL)
      end

      it 'sets project visibility to the default project visibility' do
        repo.private = false
53

54
        project = service.execute
55

56 57 58
        expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
      end
    end
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

    context 'when GitHub project has wiki' do
      it 'does not create the wiki repository' do
        allow(repo).to receive(:has_wiki?).and_return(true)

        project = service.execute

        expect(project.wiki.repository_exists?).to eq false
      end
    end

    context 'when GitHub project does not have wiki' do
      it 'creates the wiki repository' do
        allow(repo).to receive(:has_wiki?).and_return(false)

        project = service.execute

        expect(project.wiki.repository_exists?).to eq true
      end
    end
Valery Sizov committed
79 80
  end
end