specs: refactor invites_controller_spec.rb
This commit is contained in:
parent
2a3ce61dd9
commit
bdd05937e2
1 changed files with 29 additions and 42 deletions
|
@ -1,78 +1,65 @@
|
|||
describe Users::Dossiers::InvitesController, type: :controller do
|
||||
describe '#authenticate_user!' do
|
||||
let(:user) { create :user }
|
||||
let(:invite) { create :invite }
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
let(:invite) { create(:invite, dossier: dossier) }
|
||||
|
||||
subject { get :show, params: { id: invite.id, email: email } }
|
||||
|
||||
context 'when email is not set' do
|
||||
context 'when user is not connected' do
|
||||
before do
|
||||
get :show, params: { id: invite.id }
|
||||
end
|
||||
let(:email) { nil }
|
||||
|
||||
context 'and user is not connected' do
|
||||
it { is_expected.to redirect_to new_user_session_path }
|
||||
end
|
||||
|
||||
context 'when user is connected' do
|
||||
let!(:invite) { create :invite, user: user }
|
||||
|
||||
before do
|
||||
sign_in invite.user
|
||||
|
||||
get :show, params: { id: invite.id }
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq 200 }
|
||||
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) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when email is set' do
|
||||
before do
|
||||
get :show, params: { id: invite.id, email: email }
|
||||
end
|
||||
|
||||
context 'when email is blank' do
|
||||
let(:email) { '' }
|
||||
context 'when email is blank' do
|
||||
let(:email) { '' }
|
||||
it { is_expected.to redirect_to new_user_session_path }
|
||||
end
|
||||
|
||||
context 'when email is not blank' do
|
||||
context 'when email is affected at an user' do
|
||||
let(:email) { user.email }
|
||||
it { is_expected.to redirect_to new_user_session_path }
|
||||
end
|
||||
|
||||
context 'when email is not blank' do
|
||||
context 'when email is affected at an user' do
|
||||
let(:email) { user.email }
|
||||
|
||||
it { is_expected.to redirect_to new_user_session_path }
|
||||
end
|
||||
|
||||
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) }
|
||||
end
|
||||
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) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#GET show' do
|
||||
let(:user) { create :user }
|
||||
|
||||
let(:invite) { create :invite, email: email, dossier: (create :dossier) }
|
||||
|
||||
subject { get :show, params: { id: invite.id } }
|
||||
let(:dossier) { create :dossier }
|
||||
let(:invite) { create :invite, email: email, dossier: dossier }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
end
|
||||
|
||||
context 'when invitation ID is attach at the user email account' do
|
||||
subject! { get :show, params: { id: invite.id } }
|
||||
|
||||
context 'when invitation ID is attached at the user email account' do
|
||||
let(:email) { user.email }
|
||||
it { expect(subject.status).to eq 200 }
|
||||
it { is_expected.to have_http_status(:ok) }
|
||||
end
|
||||
|
||||
context 'when invitation ID is not attach at the user email account' do
|
||||
context 'when invitation ID is not attached at the user email account' do
|
||||
let(:email) { 'fake@email.com' }
|
||||
|
||||
it { expect(subject.status).to eq 302 }
|
||||
it { is_expected.to have_http_status(302) }
|
||||
it { is_expected.to redirect_to dossiers_path }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue