demarches-normaliennes/spec/controllers/users/sessions_controller_spec.rb

51 lines
1.3 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Users::SessionsController, type: :controller do
2015-10-08 11:26:12 +02:00
let(:loged_in_with_france_connect) { true }
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
describe '.create' do
2015-10-07 16:38:29 +02:00
before do
2015-10-08 11:26:12 +02:00
post :create, user: { email: user.email, password: user.password }
2015-10-07 16:38:29 +02:00
user.reload
end
2015-10-08 11:26:12 +02:00
subject { user.loged_in_with_france_connect }
it { is_expected.to be_falsey }
2015-10-07 16:38:29 +02:00
end
2015-10-07 16:38:29 +02:00
describe '.destroy' do
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
end
2015-10-08 11:26:12 +02:00
it 'loged_in_with_france_connect current_user attribut is false' do
user.reload
2015-10-08 11:26:12 +02:00
expect(user.loged_in_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
2015-10-08 11:26:12 +02:00
let(:loged_in_with_france_connect) { false }
2015-10-07 16:38:29 +02:00
it 'redirect to root page' do
expect(response).to redirect_to(root_path)
end
end
end
end