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-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
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 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
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
end
end