aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/imports_controller_spec.rb
blob: 08495ff47ec7d12c0f321d362240cf2139d576e0 (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
39
40
41
42
RSpec.describe ImportsController, :type => :controller do
  login_user

  let(:workbench) { create :workbench }
  let(:import)    { create :import, workbench: workbench }

  describe 'GET #new' do
    it 'should be successful if authorized' do
      get :new, workbench_id: workbench.id
      expect(response).to be_success
    end

    it 'should be unsuccessful unless authorized' do
      remove_permissions('imports.create', from_user: @user, save: true)
      get :new, workbench_id: workbench.id
      expect(response).not_to be_success
    end
  end

  describe "POST #create" do
    it "displays a flash message" do
      post :create, workbench_id: workbench.id,
        import: {
          name: 'Offre',
          file: fixture_file_upload('nozip.zip')
        }

      expect(controller).to set_flash[:notice].to(
        I18n.t('flash.imports.create.notice')
      )
    end
  end

  describe 'GET #download' do
    it 'should be successful' do
      get :download, workbench_id: workbench.id, id: import.id, token: import.token_download
      expect(response).to be_success
      expect( response.body ).to eq(import.file.read)
    end
  end

end