specs: add spec for DossierController#forbid_invite_submission!

This commit is contained in:
Pierre de La Morinerie 2018-07-31 17:25:39 +02:00 committed by gregoirenovel
parent bdd05937e2
commit a386a0ffb2

View file

@ -96,6 +96,47 @@ describe NewUser::DossiersController, type: :controller do
end
end
describe "#forbid_invite_submission!" do
let(:user) { create(:user) }
let(:asked_dossier) { create(:dossier) }
let(:ensure_authorized) { :forbid_invite_submission! }
let(:submit_action) { 'submit' }
before do
@controller.params = @controller.params.merge(dossier_id: asked_dossier.id, submit_action: submit_action)
allow(@controller).to receive(:current_user).and_return(user)
allow(@controller).to receive(:redirect_to)
end
context 'when a user save their own draft' do
let(:asked_dossier) { create(:dossier, user: user) }
let(:submit_action) { 'draft' }
it_behaves_like 'does not redirect nor flash'
end
context 'when a user submit their own dossier' do
let(:asked_dossier) { create(:dossier, user: user) }
let(:submit_action) { 'submit' }
it_behaves_like 'does not redirect nor flash'
end
context 'when an invite save the draft for a dossier where they where invited' do
before { create(:invite, dossier: asked_dossier, user: user, type: 'InviteUser') }
let(:submit_action) { 'draft' }
it_behaves_like 'does not redirect nor flash'
end
context 'when an invite submit a dossier where they where invited' do
before { create(:invite, dossier: asked_dossier, user: user, type: 'InviteUser') }
let(:submit_action) { 'submit' }
it_behaves_like 'redirects and flashes'
end
end
describe 'attestation' do
before { sign_in(user) }