BigW Consortium Gitlab

google_code_controller_spec.rb 1.66 KB
Newer Older
1 2 3
require 'spec_helper'

describe Import::GoogleCodeController 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
  let(:user) { create(:user) }
  let(:dump_file) { fixture_file_upload(Rails.root + 'spec/fixtures/GoogleCodeProjectHosting.json', 'application/json') }

  before do
    sign_in(user)
  end

  describe "POST callback" do
    it "stores Google Takeout dump list in session" do
      post :callback, dump_file: dump_file

      expect(session[:google_code_dump]).to be_a(Hash)
      expect(session[:google_code_dump]["kind"]).to eq("projecthosting#user")
      expect(session[:google_code_dump]).to have_key("projects")
    end
  end

  describe "GET status" do
    before do
      @repo = OpenStruct.new(name: 'vim')
26
      stub_client(valid?: true)
27 28 29 30
    end

    it "assigns variables" do
      @project = create(:project, import_type: 'google_code', creator_id: user.id)
31
      stub_client(repos: [@repo], incompatible_repos: [])
32 33 34 35 36

      get :status

      expect(assigns(:already_added_projects)).to eq([@project])
      expect(assigns(:repos)).to eq([@repo])
37
      expect(assigns(:incompatible_repos)).to eq([])
38 39 40 41
    end

    it "does not show already added project" do
      @project = create(:project, import_type: 'google_code', creator_id: user.id, import_source: 'vim')
42
      stub_client(repos: [@repo], incompatible_repos: [])
43 44 45 46 47 48

      get :status

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

    it "does not show any invalid projects" do
51
      stub_client(repos: [], incompatible_repos: [@repo])
52 53 54 55 56 57

      get :status

      expect(assigns(:repos)).to be_empty
      expect(assigns(:incompatible_repos)).to eq([@repo])
    end
58 59
  end
end