New Routes: add new_user/dossier_controller attestation
This commit is contained in:
parent
15b16f36b7
commit
1e661fa686
3 changed files with 31 additions and 0 deletions
|
@ -2,6 +2,10 @@ module NewUser
|
|||
class DossiersController < UserController
|
||||
before_action :ensure_ownership!
|
||||
|
||||
def attestation
|
||||
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier
|
||||
|
|
|
@ -229,5 +229,11 @@ Rails.application.routes.draw do
|
|||
|
||||
get "patron" => "root#patron"
|
||||
|
||||
scope module: 'new_user' do
|
||||
resources :dossiers, only: [] do
|
||||
get 'attestation'
|
||||
end
|
||||
end
|
||||
|
||||
apipie
|
||||
end
|
||||
|
|
|
@ -43,4 +43,25 @@ describe NewUser::DossiersController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'attestation' do
|
||||
before { sign_in(user) }
|
||||
|
||||
context 'when a dossier has an attestation' do
|
||||
let(:fake_pdf) { double(read: 'pdf content') }
|
||||
let!(:dossier) { create(:dossier, attestation: Attestation.new, user: user) }
|
||||
|
||||
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: { dossier_id: dossier.id }
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue