sign_out all devises connect before sign_in an other
This commit is contained in:
parent
f65c383623
commit
90a3b6763b
8 changed files with 110 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
|||
class Administrateurs::SessionsController < Devise::SessionsController
|
||||
class Administrateurs::SessionsController < Sessions::SessionsController
|
||||
|
||||
def new
|
||||
@administrateur = Administrateur.new
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Gestionnaires::SessionsController < Devise::SessionsController
|
||||
class Gestionnaires::SessionsController < Sessions::SessionsController
|
||||
|
||||
|
||||
def new
|
||||
|
|
10
app/controllers/sessions/sessions_controller.rb
Normal file
10
app/controllers/sessions/sessions_controller.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class Sessions::SessionsController < Devise::SessionsController
|
||||
|
||||
before_action :before_sign_in, only: [:create]
|
||||
|
||||
def before_sign_in
|
||||
sign_out :user if user_signed_in?
|
||||
sign_out :gestionnaire if gestionnaire_signed_in?
|
||||
sign_out :administrateur if administrateur_signed_in?
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
class Users::SessionsController < Devise::SessionsController
|
||||
class Users::SessionsController < Sessions::SessionsController
|
||||
# before_filter :configure_sign_in_params, only: [:create]
|
||||
|
||||
# GET /resource/sign_in
|
||||
|
|
11
spec/controllers/administrateur/sessions_controller_spec.rb
Normal file
11
spec/controllers/administrateur/sessions_controller_spec.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Administrateurs::SessionsController, type: :controller do
|
||||
before do
|
||||
@request.env["devise.mapping"] = Devise.mappings[:administrateur]
|
||||
end
|
||||
|
||||
describe '.create' do
|
||||
it { expect(described_class).to be < Sessions::SessionsController }
|
||||
end
|
||||
end
|
11
spec/controllers/gestionnaires/sessions_controller_spec.rb
Normal file
11
spec/controllers/gestionnaires/sessions_controller_spec.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gestionnaires::SessionsController, type: :controller do
|
||||
before do
|
||||
@request.env["devise.mapping"] = Devise.mappings[:gestionnaire]
|
||||
end
|
||||
|
||||
describe '.create' do
|
||||
it { expect(described_class).to be < Sessions::SessionsController }
|
||||
end
|
||||
end
|
63
spec/controllers/sessions/sessions_controller_spec.rb
Normal file
63
spec/controllers/sessions/sessions_controller_spec.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Sessions::SessionsController, type: :controller do
|
||||
controller Sessions::SessionsController do
|
||||
def create
|
||||
render json: ''
|
||||
end
|
||||
end
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
|
||||
describe '.create' do
|
||||
before do
|
||||
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
end
|
||||
|
||||
it 'calls before_sign_in' do
|
||||
expect_any_instance_of(Sessions::SessionsController).to receive(:before_sign_in)
|
||||
post :create
|
||||
end
|
||||
end
|
||||
|
||||
describe '.create with user connected' do
|
||||
before do
|
||||
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
|
||||
allow_any_instance_of(described_class).to receive(:user_signed_in?).and_return(true)
|
||||
end
|
||||
|
||||
it 'calls sign out for user' do
|
||||
expect_any_instance_of(described_class).to receive(:sign_out).with(:user)
|
||||
post :create
|
||||
end
|
||||
end
|
||||
|
||||
describe '.create with gestionnaire connected' do
|
||||
before do
|
||||
@request.env["devise.mapping"] = Devise.mappings[:gestionnaire]
|
||||
|
||||
allow_any_instance_of(described_class).to receive(:gestionnaire_signed_in?).and_return(true)
|
||||
end
|
||||
|
||||
it 'calls sign out for gestionnaire' do
|
||||
expect_any_instance_of(described_class).to receive(:sign_out).with(:gestionnaire)
|
||||
post :create
|
||||
end
|
||||
end
|
||||
|
||||
describe '.create with administrateur connected' do
|
||||
before do
|
||||
@request.env["devise.mapping"] = Devise.mappings[:administrateur]
|
||||
|
||||
allow_any_instance_of(described_class).to receive(:administrateur_signed_in?).and_return(true)
|
||||
end
|
||||
|
||||
it 'calls sign out for administrateur' do
|
||||
expect_any_instance_of(described_class).to receive(:sign_out).with(:administrateur)
|
||||
post :create
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,14 +9,18 @@ describe Users::SessionsController, type: :controller do
|
|||
end
|
||||
|
||||
describe '.create' do
|
||||
before do
|
||||
post :create, user: { email: user.email, password: user.password }
|
||||
user.reload
|
||||
it { expect(described_class).to be < Sessions::SessionsController }
|
||||
|
||||
describe 'France Connect attribut' do
|
||||
before do
|
||||
post :create, user: {email: user.email, password: user.password}
|
||||
user.reload
|
||||
end
|
||||
|
||||
subject { user.loged_in_with_france_connect }
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
|
||||
subject { user.loged_in_with_france_connect }
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
|
||||
describe '.destroy' do
|
||||
|
@ -42,7 +46,7 @@ describe Users::SessionsController, type: :controller do
|
|||
|
||||
context 'when user is not connect with france connect' do
|
||||
let(:loged_in_with_france_connect) { false }
|
||||
|
||||
|
||||
it 'redirect to root page' do
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue