demarches-normaliennes/spec/controllers/champs/dossier_link_controller_spec.rb
Pierre de La Morinerie 5908b8019a specs: properly use xhr: true in javascript requests
This avoids an unexpected `ActionController::InvalidCrossOriginRequest`
exception to be raised when the forgery protection is disabled.
2021-06-22 13:21:55 +02:00

58 lines
1.6 KiB
Ruby

describe Champs::DossierLinkController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published) }
describe '#show' do
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
context 'when user is connected' do
render_views
before { sign_in user }
let(:params) do
{
dossier: {
champs_attributes: {
'1' => { value: dossier_id.to_s }
}
},
position: '1'
}
end
let(:dossier_id) { dossier.id }
context 'when the dossier exist' do
before do
get :show, params: params, format: :js, xhr: true
end
it 'renders the procedure name' do
expect(response.body).to include('Dossier en brouillon')
expect(response.body).to include(procedure.libelle)
expect(response.body).to include(procedure.organisation)
expect(response.body).to include('.dossier-link-1 .help-block')
end
end
context 'when the dossier does not exist' do
let(:dossier_id) { '13' }
before do
get :show, params: params, format: :js, xhr: true
end
it 'renders error message' do
expect(response.body).to include('Ce dossier est inconnu')
expect(response.body).to include('.dossier-link-1 .help-block')
end
end
end
context 'when user is not connected' do
before do
get :show, params: { position: '1' }, format: :js, xhr: true
end
it { expect(response.code).to eq('401') }
end
end
end