display alert message when no email is given for an invite

no exception is raised anymore in this case
This commit is contained in:
Christophe Robillard 2022-07-27 14:50:20 +02:00
parent d02c5ec315
commit c8abe092c1
2 changed files with 10 additions and 1 deletions

View file

@ -3,7 +3,7 @@ class InvitesController < ApplicationController
before_action :store_user_location!, only: [:show]
def create
email = params[:invite_email].downcase
email = params[:invite_email]&.downcase
@dossier = current_user.dossiers.visible_by_user.find(params[:dossier_id])
invite = Invite.create(
dossier: @dossier,

View file

@ -121,6 +121,15 @@ describe InvitesController, type: :controller do
it { expect(flash[:alert]).to be_present }
end
context "when user does'nt give any email" do
subject { post :create, params: { dossier_id: dossier.id } }
before do
subject
end
it { expect { subject }.not_to change(Invite, :count) }
it { expect(flash[:alert]).to be_present }
end
context 'when email is already used' do
let!(:invite) { create(:invite, dossier: dossier) }