2016-12-27 15:50:45 +01:00
|
|
|
describe Users::Dossiers::InvitesController, type: :controller do
|
2016-02-22 10:34:25 +01:00
|
|
|
describe '#authenticate_user!' do
|
|
|
|
let(:user) { create :user }
|
2018-07-19 13:13:08 +02:00
|
|
|
let(:dossier) { create(:dossier, :en_construction) }
|
|
|
|
let(:invite) { create(:invite, dossier: dossier) }
|
|
|
|
|
|
|
|
subject { get :show, params: { id: invite.id, email: email } }
|
2016-02-22 10:34:25 +01:00
|
|
|
|
|
|
|
context 'when email is not set' do
|
2018-07-19 13:13:08 +02:00
|
|
|
let(:email) { nil }
|
2016-02-22 10:34:25 +01:00
|
|
|
|
2018-07-19 13:13:08 +02:00
|
|
|
context 'and user is not connected' do
|
2016-02-22 10:34:25 +01:00
|
|
|
it { is_expected.to redirect_to new_user_session_path }
|
|
|
|
end
|
|
|
|
|
2018-07-19 13:13:08 +02:00
|
|
|
context 'and user is connected' do
|
|
|
|
let(:invite) { create :invite, dossier: dossier, user: user }
|
|
|
|
before { sign_in invite.user }
|
|
|
|
it { is_expected.to have_http_status(:ok) }
|
2016-02-22 10:34:25 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-19 13:13:08 +02:00
|
|
|
context 'when email is blank' do
|
|
|
|
let(:email) { '' }
|
|
|
|
it { is_expected.to redirect_to new_user_session_path }
|
|
|
|
end
|
2016-02-22 10:34:25 +01:00
|
|
|
|
2018-07-19 13:13:08 +02:00
|
|
|
context 'when email is not blank' do
|
|
|
|
context 'when email is affected at an user' do
|
|
|
|
let(:email) { user.email }
|
2016-02-22 10:34:25 +01:00
|
|
|
it { is_expected.to redirect_to new_user_session_path }
|
|
|
|
end
|
|
|
|
|
2018-07-19 13:13:08 +02:00
|
|
|
context 'when email is not affected at an user' do
|
|
|
|
let(:email) { 'new_user@octo.com' }
|
|
|
|
it { is_expected.to redirect_to new_user_registration_path(user_email: email) }
|
2016-02-22 10:34:25 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-16 15:34:49 +01:00
|
|
|
|
|
|
|
describe '#GET show' do
|
|
|
|
let(:user) { create :user }
|
2018-07-19 13:13:08 +02:00
|
|
|
let(:dossier) { create :dossier }
|
|
|
|
let(:invite) { create :invite, email: email, dossier: dossier }
|
2016-12-16 15:34:49 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
2018-07-19 13:13:08 +02:00
|
|
|
subject! { get :show, params: { id: invite.id } }
|
|
|
|
|
|
|
|
context 'when invitation ID is attached at the user email account' do
|
2016-12-16 15:34:49 +01:00
|
|
|
let(:email) { user.email }
|
2018-08-01 17:27:50 +02:00
|
|
|
|
|
|
|
context 'and dossier is a brouillon' do
|
|
|
|
let(:dossier) { create :dossier, state: 'brouillon' }
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(302) }
|
|
|
|
it { is_expected.to redirect_to modifier_dossier_path(dossier) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and dossier is not a brouillon' do
|
|
|
|
let(:dossier) { create :dossier, :en_construction }
|
|
|
|
|
|
|
|
it { is_expected.to have_http_status(:ok) }
|
|
|
|
it { is_expected.to render_template('users/recapitulatif/show') }
|
|
|
|
end
|
2016-12-16 15:34:49 +01:00
|
|
|
end
|
|
|
|
|
2018-07-19 13:13:08 +02:00
|
|
|
context 'when invitation ID is not attached at the user email account' do
|
2016-12-16 15:34:49 +01:00
|
|
|
let(:email) { 'fake@email.com' }
|
|
|
|
|
2018-07-19 13:13:08 +02:00
|
|
|
it { is_expected.to have_http_status(302) }
|
2018-06-27 14:47:02 +02:00
|
|
|
it { is_expected.to redirect_to dossiers_path }
|
2018-07-19 13:13:08 +02:00
|
|
|
it { expect(flash[:alert]).to be_present }
|
2016-12-16 15:34:49 +01:00
|
|
|
end
|
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|