BigW Consortium Gitlab

google_code_controller_spec.rb 1.7 KB
Newer Older
1
require 'spec_helper'
2
require_relative 'import_spec_helper'
3 4

describe Import::GoogleCodeController 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
  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')
27
      stub_client(valid?: true)
28 29 30 31
    end

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

      get :status

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

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

      get :status

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

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

      get :status

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