2015-10-07 14:18:55 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Users::SessionsController, type: :controller do
|
2016-02-11 16:12:59 +01:00
|
|
|
let(:loged_in_with_france_connect) { 'particulier' }
|
2015-10-08 11:26:12 +02:00
|
|
|
let(:user) { create(:user, loged_in_with_france_connect: loged_in_with_france_connect) }
|
2015-10-07 16:38:29 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
|
|
|
end
|
2015-10-07 14:18:55 +02:00
|
|
|
|
2016-02-19 15:04:29 +01:00
|
|
|
describe '.demo' do
|
|
|
|
context 'when server is on env production' do
|
|
|
|
before do
|
|
|
|
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new("production"))
|
|
|
|
end
|
|
|
|
subject { get :demo }
|
|
|
|
|
|
|
|
it { expect(subject).to redirect_to root_path }
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-07 14:18:55 +02:00
|
|
|
describe '.create' do
|
2015-12-09 15:10:11 +01:00
|
|
|
it { expect(described_class).to be < Sessions::SessionsController }
|
2015-10-08 11:26:12 +02:00
|
|
|
|
2015-12-09 15:10:11 +01:00
|
|
|
describe 'France Connect attribut' do
|
|
|
|
before do
|
|
|
|
post :create, user: {email: user.email, password: user.password}
|
|
|
|
user.reload
|
|
|
|
end
|
2015-10-08 11:26:12 +02:00
|
|
|
|
2015-12-24 10:12:23 +01:00
|
|
|
subject { user.loged_in_with_france_connect? }
|
2015-12-09 15:10:11 +01:00
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
2015-10-07 16:38:29 +02:00
|
|
|
end
|
2015-10-07 14:18:55 +02:00
|
|
|
|
2015-10-07 16:38:29 +02:00
|
|
|
describe '.destroy' do
|
2015-10-07 14:18:55 +02:00
|
|
|
before do
|
2015-10-07 16:38:29 +02:00
|
|
|
sign_in user
|
|
|
|
delete :destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'user is sign out' do
|
|
|
|
expect(subject.current_user).to be_nil
|
2015-10-07 14:18:55 +02:00
|
|
|
end
|
|
|
|
|
2015-12-24 10:12:23 +01:00
|
|
|
it 'loged_in_with_france_connect current_user attribut is nil' do
|
2015-10-07 14:18:55 +02:00
|
|
|
user.reload
|
2015-12-24 10:12:23 +01:00
|
|
|
expect(user.loged_in_with_france_connect?).to be_falsey
|
2015-10-07 14:18:55 +02:00
|
|
|
end
|
2015-10-07 16:38:29 +02:00
|
|
|
|
|
|
|
|
2016-02-11 16:12:59 +01:00
|
|
|
context 'when user is connect with france connect particulier' do
|
2015-12-24 10:12:23 +01:00
|
|
|
let(:loged_in_with_france_connect) { 'particulier' }
|
|
|
|
|
|
|
|
it 'redirect to france connect logout page' do
|
|
|
|
expect(response).to redirect_to(FRANCE_CONNECT.particulier_logout_endpoint)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-07 16:38:29 +02:00
|
|
|
context 'when user is not connect with france connect' do
|
2015-12-24 10:12:23 +01:00
|
|
|
let(:loged_in_with_france_connect) { '' }
|
2015-12-09 15:10:11 +01:00
|
|
|
|
2015-10-07 16:38:29 +02:00
|
|
|
it 'redirect to root page' do
|
|
|
|
expect(response).to redirect_to(root_path)
|
|
|
|
end
|
|
|
|
end
|
2015-10-07 14:18:55 +02:00
|
|
|
end
|
2016-05-26 15:59:50 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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 }
|
|
|
|
|
|
|
|
before do
|
|
|
|
session["user_return_to"] = "?procedure_id=#{procedure.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 200}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-07 14:18:55 +02:00
|
|
|
end
|