BigW Consortium Gitlab

imports_controller_spec.rb 3.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
require 'spec_helper'

describe Projects::ImportsController do
  let(:user) { create(:user) }

  describe 'GET #show' do
    context 'when repository does not exists' do
      let(:project) { create(:empty_project) }

      before do
        sign_in(user)
        project.team << [user, :master]
      end

      it 'renders template' do
        get :show, namespace_id: project.namespace.to_param, project_id: project.to_param

        expect(response).to render_template :show
      end

      it 'sets flash.now if params is present' do
22
        get :show, namespace_id: project.namespace.to_param, project_id: project.to_param, continue: { to: '/', notice_now: 'Started' }
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

        expect(flash.now[:notice]).to eq 'Started'
      end
    end

    context 'when repository exists' do
      let(:project) { create(:project_empty_repo, import_url: 'https://github.com/vim/vim.git') }

      before do
        sign_in(user)
        project.team << [user, :master]
      end

      context 'when import is in progress' do
        before do
          project.update_attribute(:import_status, :started)
        end

        it 'renders template' do
          get :show, namespace_id: project.namespace.to_param, project_id: project.to_param

          expect(response).to render_template :show
        end

        it 'sets flash.now if params is present' do
48
          get :show, namespace_id: project.namespace.to_param, project_id: project.to_param, continue: { to: '/', notice_now: 'In progress' }
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

          expect(flash.now[:notice]).to eq 'In progress'
        end
      end

      context 'when import failed' do
        before do
          project.update_attribute(:import_status, :failed)
        end

        it 'redirects to new_namespace_project_import_path' do
          get :show, namespace_id: project.namespace.to_param, project_id: project.to_param

          expect(response).to redirect_to new_namespace_project_import_path(project.namespace, project)
        end
      end

      context 'when import finished' do
        before do
          project.update_attribute(:import_status, :finished)
        end

        context 'when project is a fork' do
          it 'redirects to namespace_project_path' do
            allow_any_instance_of(Project).to receive(:forked?).and_return(true)

            get :show, namespace_id: project.namespace.to_param, project_id: project.to_param

            expect(flash[:notice]).to eq 'The project was successfully forked.'
            expect(response).to redirect_to namespace_project_path(project.namespace, project)
          end
        end

        context 'when project is external' do
          it 'redirects to namespace_project_path' do
            get :show, namespace_id: project.namespace.to_param, project_id: project.to_param

            expect(flash[:notice]).to eq 'The project was successfully imported.'
            expect(response).to redirect_to namespace_project_path(project.namespace, project)
          end
        end

        context 'when continue params is present' do
          let(:params) do
            {
              to: namespace_project_path(project.namespace, project),
              notice: 'Finished'
            }
          end

          it 'redirects to params[:to]' do
            get :show, namespace_id: project.namespace.to_param, project_id: project.to_param, continue: params

            expect(flash[:notice]).to eq params[:notice]
            expect(response).to redirect_to params[:to]
          end
        end
      end
107 108 109 110 111 112 113 114 115 116 117 118

      context 'when import never happened' do
        before do
          project.update_attribute(:import_status, :none)
        end

        it 'redirects to namespace_project_path' do
          get :show, namespace_id: project.namespace.to_param, project_id: project.to_param

          expect(response).to redirect_to namespace_project_path(project.namespace, project)
        end
      end
119 120 121
    end
  end
end