diff options
| author | Xinhui | 2017-03-06 12:58:34 +0100 |
|---|---|---|
| committer | Xinhui | 2017-03-06 12:58:34 +0100 |
| commit | d0e1b2ec190143a092ab03d4febe5c3b4271c2e2 (patch) | |
| tree | fe6bd4a5b5503988e114490de4349fe58d53ce4e | |
| parent | 156133d5bdbc05fd283f50396f776b43e49e5249 (diff) | |
| download | chouette-core-d0e1b2ec190143a092ab03d4febe5c3b4271c2e2.tar.bz2 | |
Imports#download action
Refs #2719
| -rw-r--r-- | app/controllers/imports_controller.rb | 8 | ||||
| -rw-r--r-- | config/routes.rb | 4 | ||||
| -rw-r--r-- | spec/controllers/imports_controller_spec.rb | 8 |
3 files changed, 19 insertions, 1 deletions
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 3eab7e66b..9b2101584 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -21,6 +21,14 @@ class ImportsController < BreadcrumbController end end + def download + if params[:token] == resource.token_download + send_file resource.file.path + else + user_not_authorized + end + end + private def import_params diff --git a/config/routes.rb b/config/routes.rb index 6e26cbd72..943acb5cb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,9 @@ require 'sidekiq/web' ChouetteIhm::Application.routes.draw do resources :workbenches, :only => [:show] do delete :referentials, on: :member, action: :delete_referentials - resources :imports + resources :imports do + get :download, on: :member + end end devise_for :users, :controllers => { diff --git a/spec/controllers/imports_controller_spec.rb b/spec/controllers/imports_controller_spec.rb index 19756b72f..bffb89338 100644 --- a/spec/controllers/imports_controller_spec.rb +++ b/spec/controllers/imports_controller_spec.rb @@ -4,6 +4,7 @@ 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' do @@ -11,4 +12,11 @@ RSpec.describe ImportsController, :type => :controller do expect(response).to be_success 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 + end + end end |
