New Routes: add new_gestionnaire/dossier_controller attestation
This commit is contained in:
parent
94f8fb748f
commit
4e6a8c5939
3 changed files with 47 additions and 0 deletions
13
app/controllers/new_gestionnaire/dossiers_controller.rb
Normal file
13
app/controllers/new_gestionnaire/dossiers_controller.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
module NewGestionnaire
|
||||
class DossiersController < ProceduresController
|
||||
def attestation
|
||||
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier
|
||||
Dossier.find(params[:dossier_id])
|
||||
end
|
||||
end
|
||||
end
|
|
@ -235,5 +235,13 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
scope module: 'new_gestionnaire' do
|
||||
resources :procedures, only: [] do
|
||||
resources :dossiers, only: [] do
|
||||
get 'attestation'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
apipie
|
||||
end
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe NewGestionnaire::DossiersController, type: :controller do
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
before { sign_in(gestionnaire) }
|
||||
|
||||
describe 'attestation' do
|
||||
context 'when a dossier has an attestation' do
|
||||
let(:fake_pdf) { double(read: 'pdf content') }
|
||||
let!(:procedure) { create(:procedure, gestionnaires: [gestionnaire]) }
|
||||
let!(:dossier) { create(:dossier, attestation: Attestation.new, procedure: procedure) }
|
||||
|
||||
it 'returns the attestation pdf' do
|
||||
allow_any_instance_of(Attestation).to receive(:pdf).and_return(fake_pdf)
|
||||
|
||||
expect(controller).to receive(:send_data)
|
||||
.with('pdf content', filename: 'attestation.pdf', type: 'application/pdf') do
|
||||
controller.render nothing: true
|
||||
end
|
||||
|
||||
get :attestation, params: { procedure_id: procedure.id, dossier_id: dossier.id }
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue