2015-10-07 14:18:55 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Users::SessionsController, type: :controller do
|
2015-10-07 16:38:29 +02:00
|
|
|
let(:login_with_france_connect) { true }
|
|
|
|
let(:user) { create(:user, login_with_france_connect: login_with_france_connect) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
|
|
|
end
|
2015-10-07 14:18:55 +02:00
|
|
|
|
|
|
|
describe '.create' do
|
2015-10-07 16:38:29 +02:00
|
|
|
before do
|
|
|
|
post :create, user: {email: user.email, password: user.password}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'login_with_france_connect current_user attribut is false' do
|
|
|
|
user.reload
|
|
|
|
expect(user.login_with_france_connect).to be_falsey
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'login_with_france_connect current_user attribut is false' do
|
|
|
|
user.reload
|
|
|
|
expect(user.login_with_france_connect).to be_falsey
|
|
|
|
end
|
2015-10-07 16:38:29 +02:00
|
|
|
|
|
|
|
context 'when user is connect with france connect' do
|
|
|
|
it 'redirect to france connect logout page' do
|
|
|
|
expect(response).to redirect_to(FRANCE_CONNECT.logout_endpoint)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not connect with france connect' do
|
|
|
|
let(:login_with_france_connect) { false }
|
|
|
|
|
|
|
|
it 'redirect to root page' do
|
|
|
|
expect(response).to redirect_to(root_path)
|
|
|
|
end
|
|
|
|
end
|
2015-10-07 14:18:55 +02:00
|
|
|
end
|
|
|
|
end
|