sessions: add a helper to clear the stored return path

This commit is contained in:
Pierre de La Morinerie 2019-01-14 15:16:23 +00:00
parent e39fd7b171
commit e580d336e4
6 changed files with 65 additions and 8 deletions

View file

@ -0,0 +1,26 @@
require 'rails_helper'
RSpec.describe Devise::StoreLocationExtension, type: :controller do
class TestController < ActionController::Base
include Devise::Controllers::StoreLocation
include Devise::StoreLocationExtension
end
controller TestController do
end
describe "#clear_stored_location_for" do
context 'when a location has been previously stored' do
before { subject.store_location_for(:user, dossiers_path) }
it 'delete the stored location' do
subject.clear_stored_location_for(:user)
expect(subject.stored_location_for(:user)).to be nil
end
end
context 'when no location has been stored' do
it { expect(subject.clear_stored_location_for(:user)).to be nil }
end
end
end

View file

@ -171,7 +171,10 @@ describe InvitesController, type: :controller do
let(:email) { nil }
context 'and user is not connected' do
it { is_expected.to redirect_to new_user_session_path }
it 'redirects to the sign-in page' do
expect(subject).to redirect_to new_user_session_path
expect(controller.stored_location_for(:user)).to be_present
end
end
context 'and user is connected' do
@ -186,20 +189,29 @@ describe InvitesController, type: :controller do
context 'when email is blank' do
let(:email) { '' }
it { is_expected.to redirect_to new_user_session_path }
it 'redirects to the sign-in page' do
expect(subject).to redirect_to new_user_session_path
expect(controller.stored_location_for(:user)).to be_present
end
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 }
it 'redirects to the sign-in page' do
expect(subject).to redirect_to new_user_session_path
expect(controller.stored_location_for(:user)).to be_present
end
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 }) }
it 'redirects to the sign-up page' do
expect(subject).to redirect_to new_user_registration_path(user: { email: email })
expect(controller.stored_location_for(:user)).to be_present
end
end
end
end
@ -213,6 +225,10 @@ describe InvitesController, type: :controller do
subject! { get :show, params: { id: invite.id } }
it 'clears the stored return location' do
expect(controller.stored_location_for(:user)).to be nil
end
context 'when invitation ID is attached at the user email account' do
let(:email) { user.email }

View file

@ -854,6 +854,11 @@ describe NewUser::DossiersController, type: :controller do
subject { get :new, params: { procedure_id: procedure_id } }
it 'clears the stored procedure context' do
subject
expect(controller.stored_location_for(:user)).to be nil
end
context 'when params procedure_id is present' do
context 'when procedure_id is valid' do
context 'when user is logged in' do