BigW Consortium Gitlab

gitorious_controller_spec.rb 1.73 KB
Newer Older
1 2 3
require 'spec_helper'

describe Import::GitoriousController do
4 5
  include ImportSpecHelper

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
  let(:user) { create(:user) }

  before do
    sign_in(user)
  end

  describe "GET new" do
    it "redirects to import endpoint on gitorious.org" do
      get :new

      expect(controller).to redirect_to("https://gitorious.org/gitlab-import?callback_url=http://test.host/import/gitorious/callback")
    end
  end

  describe "GET callback" do
    it "stores repo list in session" do
      get :callback, repos: 'foo/bar,baz/qux'

      expect(session[:gitorious_repos]).to eq('foo/bar,baz/qux')
    end
  end

  describe "GET status" do
    before do
      @repo = OpenStruct.new(full_name: 'asd/vim')
    end

    it "assigns variables" do
      @project = create(:project, import_type: 'gitorious', creator_id: user.id)
35
      stub_client(repos: [@repo])
36 37 38 39 40 41 42 43 44

      get :status

      expect(assigns(:already_added_projects)).to eq([@project])
      expect(assigns(:repos)).to eq([@repo])
    end

    it "does not show already added project" do
      @project = create(:project, import_type: 'gitorious', creator_id: user.id, import_source: 'asd/vim')
45
      stub_client(repos: [@repo])
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

      get :status

      expect(assigns(:already_added_projects)).to eq([@project])
      expect(assigns(:repos)).to eq([])
    end
  end

  describe "POST create" do
    before do
      @repo = Gitlab::GitoriousImport::Repository.new('asd/vim')
    end

    it "takes already existing namespace" do
      namespace = create(:namespace, name: "asd", owner: user)
      expect(Gitlab::GitoriousImport::ProjectCreator).
        to receive(:new).with(@repo, namespace, user).
        and_return(double(execute: true))
64
      stub_client(repo: @repo)
65 66 67 68 69

      post :create, format: :js
    end
  end
end