demarches-normaliennes/spec/controllers/users/sessions_controller_spec.rb
2016-02-11 16:12:59 +01:00

58 lines
No EOL
1.5 KiB
Ruby

require 'spec_helper'
describe Users::SessionsController, type: :controller do
let(:loged_in_with_france_connect) { 'particulier' }
let(:user) { create(:user, loged_in_with_france_connect: loged_in_with_france_connect) }
before do
@request.env["devise.mapping"] = Devise.mappings[:user]
end
describe '.create' do
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
end
describe '.destroy' do
before do
sign_in user
delete :destroy
end
it 'user is sign out' do
expect(subject.current_user).to be_nil
end
it 'loged_in_with_france_connect current_user attribut is nil' do
user.reload
expect(user.loged_in_with_france_connect?).to be_falsey
end
context 'when user is connect with france connect particulier' do
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
context 'when user is not connect with france connect' do
let(:loged_in_with_france_connect) { '' }
it 'redirect to root page' do
expect(response).to redirect_to(root_path)
end
end
end
end