sign_in: extract the procedure context to a ProcedureContextConcern
This commit is contained in:
parent
e580d336e4
commit
4fd9fa6610
7 changed files with 147 additions and 54 deletions
77
spec/controllers/concerns/procedure_context_concern_spec.rb
Normal file
77
spec/controllers/concerns/procedure_context_concern_spec.rb
Normal file
|
@ -0,0 +1,77 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ProcedureContextConcern, type: :controller do
|
||||
class TestController < ActionController::Base
|
||||
include ProcedureContextConcern
|
||||
|
||||
before_action :restore_procedure_context
|
||||
|
||||
def index
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
|
||||
controller TestController do
|
||||
end
|
||||
|
||||
describe '#restore_procedure_context' do
|
||||
subject { get :index }
|
||||
|
||||
context 'when no return location has been stored' do
|
||||
it 'succeeds, without defining a procedure on the controller' do
|
||||
expect(subject.status).to eq 200
|
||||
expect(assigns(:procedure)).to be nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when no procedure_id is present in the stored return location' do
|
||||
before do
|
||||
controller.store_location_for(:user, dossiers_path)
|
||||
end
|
||||
|
||||
it 'succeeds, without assigns a procedure on the controller' do
|
||||
expect(subject.status).to eq 200
|
||||
expect(assigns(:procedure)).to be nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a procedure location has been stored' do
|
||||
context 'when the stored procedure does not exist' do
|
||||
before do
|
||||
controller.store_location_for(:user, new_dossier_path(procedure_id: '0'))
|
||||
end
|
||||
|
||||
it 'redirects with an error' do
|
||||
expect(subject.status).to eq 302
|
||||
expect(subject).to redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the stored procedure is not published' do
|
||||
let(:procedure) { create :procedure }
|
||||
|
||||
before do
|
||||
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id))
|
||||
end
|
||||
|
||||
it 'redirects with an error' do
|
||||
expect(subject.status).to eq 302
|
||||
expect(subject).to redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the stored procedure exists' do
|
||||
let(:procedure) { create :procedure, :published }
|
||||
|
||||
before do
|
||||
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id))
|
||||
end
|
||||
|
||||
it 'succeeds, and assigns the procedure on the controller' do
|
||||
expect(subject.status).to eq 200
|
||||
expect(assigns(:procedure)).to eq procedure
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,6 +9,21 @@ RSpec.describe Devise::StoreLocationExtension, type: :controller do
|
|||
controller TestController do
|
||||
end
|
||||
|
||||
describe '#get_stored_location_for' do
|
||||
context 'when a location has been previously stored' do
|
||||
before { subject.store_location_for(:user, dossiers_path) }
|
||||
|
||||
it 'returns the stored location without clearing it' do
|
||||
expect(subject.get_stored_location_for(:user)).to eq dossiers_path
|
||||
expect(subject.stored_location_for(:user)).to eq dossiers_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'when no location has been stored' do
|
||||
it { expect(subject.get_stored_location_for(:user)).to be nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#clear_stored_location_for" do
|
||||
context 'when a location has been previously stored' do
|
||||
before { subject.store_location_for(:user, dossiers_path) }
|
||||
|
|
|
@ -173,38 +173,18 @@ describe Users::SessionsController, type: :controller do
|
|||
describe '#new' do
|
||||
subject { get :new }
|
||||
|
||||
context 'when procedure_id is not present in user_return_to session params' do
|
||||
it { expect(subject.status).to eq 200 }
|
||||
end
|
||||
it { expect(subject.status).to eq 200 }
|
||||
|
||||
context 'when procedure_id is present in user_return_to session params' do
|
||||
context 'when procedure_id does not exist' do
|
||||
before do
|
||||
session["user_return_to"] = '?procedure_id=0'
|
||||
end
|
||||
context 'when a procedure location has been stored' do
|
||||
let(:procedure) { create :procedure, :published }
|
||||
|
||||
it { expect(subject.status).to eq 302 }
|
||||
it { expect(subject).to redirect_to root_path }
|
||||
before do
|
||||
controller.store_location_for(:user, new_dossier_path(procedure_id: procedure.id))
|
||||
end
|
||||
|
||||
context 'when procedure is not published' do
|
||||
let(:procedure) { create :procedure }
|
||||
before do
|
||||
session["user_return_to"] = "?procedure_id=#{procedure.id}"
|
||||
end
|
||||
|
||||
it { expect(subject.status).to eq 302 }
|
||||
it { expect(subject).to redirect_to root_path }
|
||||
end
|
||||
|
||||
context 'when procedure_id exist' do
|
||||
let(:procedure) { create :procedure, :published }
|
||||
|
||||
before do
|
||||
session["user_return_to"] = "?procedure_id=#{procedure.id}"
|
||||
end
|
||||
|
||||
it { expect(subject.status).to eq 200 }
|
||||
it 'makes the saved procedure available' do
|
||||
expect(subject.status).to eq 200
|
||||
expect(assigns(:procedure)).to eq procedure
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue