summaryrefslogtreecommitdiff
path: root/spec/controllers/import/gitlab_projects_controller_spec.rb
blob: 8759d3c0b97e8ef1c989ba1afbb4acf05b3eda77 (plain)
1
2
3
4
5
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
35
36
37
38
require 'spec_helper'

describe Import::GitlabProjectsController do
  set(:namespace) { create(:namespace) }
  set(:user) { namespace.owner }
  let(:file) { fixture_file_upload(Rails.root + 'spec/fixtures/doc_sample.txt', 'text/plain') }

  before do
    sign_in(user)
  end

  describe 'POST create' do
    context 'with an invalid path' do
      it 'redirects with an error' do
        post :create, namespace_id: namespace.id, path: '/test', file: file

        expect(flash[:alert]).to start_with('Project could not be imported')
        expect(response).to have_gitlab_http_status(302)
      end

      it 'redirects with an error when a relative path is used' do
        post :create, namespace_id: namespace.id, path: '../test', file: file

        expect(flash[:alert]).to start_with('Project could not be imported')
        expect(response).to have_gitlab_http_status(302)
      end
    end

    context 'with a valid path' do
      it 'redirects to the new project path' do
        post :create, namespace_id: namespace.id, path: 'test', file: file

        expect(flash[:notice]).to include('is being imported')
        expect(response).to have_gitlab_http_status(302)
      end
    end
  end
end