[#1677] No longer create InviteGestionnaires

This commit is contained in:
Frederic Merizen 2018-03-22 09:15:32 +01:00
parent 6c3f287f68
commit c413dfa127
2 changed files with 36 additions and 36 deletions

View file

@ -30,11 +30,10 @@ class InvitesController < ApplicationController
private
def gestionnaire_or_user?
if !user_signed_in? && !gestionnaire_signed_in?
if !user_signed_in?
return redirect_to root_path
end
@current_devise_profil = current_user if user_signed_in?
@current_devise_profil = current_gestionnaire if gestionnaire_signed_in?
end
end

View file

@ -17,8 +17,7 @@ describe InvitesController, type: :controller do
let(:signed_in_profile) { create(:gestionnaire) }
shared_examples_for "he can not create invitation" do
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject rescue nil }.to change(InviteGestionnaire, :count).by(0) }
it { expect { subject rescue nil }.to change(Invite, :count).by(0) }
end
context 'when gestionnaire has no access to dossier' do
@ -36,18 +35,47 @@ describe InvitesController, type: :controller do
signed_in_profile.procedures << dossier.procedure
end
it { expect { subject }.to change(InviteGestionnaire, :count).by(1) }
it_behaves_like "he can not create invitation"
context 'when is a user who is loged' do
let(:user) { create(:user) }
before do
sign_in create(:user)
dossier.update(user: user)
sign_in(user)
end
it { expect { subject }.to change(InviteGestionnaire, :count).by(1) }
it { expect { subject }.to change(InviteUser, :count).by(1) }
end
end
end
context "when user is signed_in" do
let(:signed_in_profile) { create(:user) }
shared_examples_for "he can not create a invite" do
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject rescue nil }.to change(InviteUser, :count).by(0) }
end
context 'when user has no access to dossier' do
it_behaves_like "he can not create a invite"
end
context 'when user is invited on dossier' do
before { Invite.create(user: signed_in_profile, email: signed_in_profile.email, dossier: dossier) }
it_behaves_like "he can not create a invite"
end
context 'when user has access to dossier' do
before do
dossier.update(user: signed_in_profile)
end
it { expect { subject }.to change(InviteUser, :count).by(1) }
context 'when email is assign to an user' do
let! (:user) { create(:user, email: email) }
let! (:user_invite) { create(:user, email: email) }
before do
subject
@ -62,7 +90,7 @@ describe InvitesController, type: :controller do
end
end
it { expect(invite.user).to eq user }
it { expect(invite.user).to eq user_invite }
it { expect(flash[:notice]).to be_present }
end
@ -124,32 +152,5 @@ describe InvitesController, type: :controller do
end
end
end
context "when user is signed_in" do
let(:signed_in_profile) { create(:user) }
shared_examples_for "he can not create a invite" do
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject rescue nil }.to change(InviteUser, :count).by(0) }
end
context 'when user has no access to dossier' do
it_behaves_like "he can not create a invite"
end
context 'when user is invited on dossier' do
before { Invite.create(user: signed_in_profile, email: signed_in_profile.email, dossier: dossier) }
it_behaves_like "he can not create a invite"
end
context 'when user has access to dossier' do
before do
dossier.update(user: signed_in_profile)
end
it { expect { subject }.to change(InviteUser, :count).by(1) }
end
end
end
end