BigW Consortium Gitlab

gitorious_controller_spec.rb 1.77 KB
Newer Older
1
require 'spec_helper'
2
require_relative 'import_spec_helper'
3 4

describe Import::GitoriousController do
5 6
  include ImportSpecHelper

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
  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)
36
      stub_client(repos: [@repo])
37 38 39 40 41 42 43 44 45

      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')
46
      stub_client(repos: [@repo])
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

      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))
65
      stub_client(repo: @repo)
66 67 68 69 70

      post :create, format: :js
    end
  end
end