layouts: migrate sign_in to the shared layout

This commit is contained in:
Pierre de La Morinerie 2019-01-08 07:20:49 +00:00
parent 13f1d4c7d9
commit d36696442b
9 changed files with 140 additions and 97 deletions

View file

@ -0,0 +1,56 @@
require 'spec_helper'
feature 'Signin in:' do
let!(:user) { create(:user, password: password) }
let(:password) { 'testpassword' }
scenario 'an existing user can sign-in' do
visit root_path
click_on 'Connexion'
sign_in_with user.email, password
expect(page).to have_current_path dossiers_path
end
context 'when visiting a procedure' do
let(:procedure) { create :simple_procedure, :with_service }
before do
visit commencer_path(path: procedure.path)
end
scenario 'an existing user can sign-in and fill the procedure' do
expect(page).to have_current_path new_user_session_path
expect(page).to have_content procedure.libelle
expect(page).to have_content procedure.description
expect(page).to have_content procedure.service.email
sign_in_with user.email, password
expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last)
expect(page).to have_content procedure.libelle
expect(page).to have_content procedure.description
expect(page).to have_content "Données d'identité"
end
end
context 'when a user is not confirmed yet' do
let!(:user) { create(:user, password: password, confirmed_at: nil) }
# Ideally, when signing-in with an unconfirmed account,
# the user would be redirected to the "resend email confirmation" page.
#
# However the check for unconfirmed accounts is made by Warden every time a page is loaded 
# and much earlier than SessionsController#create.
#
# For now only test the default behavior (an error message is displayed).
scenario 'they get an error message' do
visit root_path
click_on 'Connexion'
sign_in_with user.email, password
expect(page).to have_content 'Vous devez confirmer votre adresse email pour continuer'
end
end
end

View file

@ -4,25 +4,31 @@ describe 'layouts/procedure_context.html.haml', type: :view do
let(:procedure) { create(:simple_procedure, :with_service) }
let(:dossier) { create(:dossier, procedure: procedure) }
before do
assign(:dossier, dossier)
end
subject do
render html: 'Column content', layout: 'layouts/procedure_context.html.haml'
end
it 'renders a description of the procedure' do
expect(subject).to have_text(dossier.procedure.libelle)
expect(subject).to have_text(dossier.procedure.description)
end
it 'renders the inner content' do
expect(subject).to have_text('Column content')
context 'when a dossier is assigned' do
before do
assign(:dossier, dossier)
end
it 'renders a description of the procedure' do
expect(subject).to have_text(dossier.procedure.libelle)
expect(subject).to have_text(dossier.procedure.description)
end
it 'renders the inner content' do
expect(subject).to have_text('Column content')
end
it 'renders the procedure footer' do
expect(subject).to have_text(dossier.procedure.service.nom)
expect(subject).to have_text(dossier.procedure.service.email)
end
end
it 'renders the dossier footer' do
expect(subject).to have_text(dossier.procedure.service.nom)
expect(subject).to have_text(dossier.procedure.service.email)
end
end

View file

@ -10,24 +10,12 @@ describe 'users/sessions/new.html.haml', type: :view do
before do
assign(:user, User.new)
render
end
context 'when user_return_to session params contains a procedure_id' do
before do
assign(:dossier, dossier)
render
end
it { expect(rendered).to have_selector('.procedure-logos') }
it { expect(rendered).to have_content(dossier.procedure.libelle) }
it { expect(rendered).to have_content(dossier.procedure.description) }
end
context 'when user_return_to session params not contains a procedure_id' do
before do
render
end
it { expect(rendered).to have_content('Un outil simple') }
it 'renders' do
expect(rendered).to have_field('Email')
expect(rendered).to have_field('Mot de passe')
expect(rendered).to have_button('Se connecter')
end
end