diff --git a/spec/controllers/new_user/dossiers_controller_spec.rb b/spec/controllers/new_user/dossiers_controller_spec.rb index 22c7ff106..3d891b1f9 100644 --- a/spec/controllers/new_user/dossiers_controller_spec.rb +++ b/spec/controllers/new_user/dossiers_controller_spec.rb @@ -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) }