demarches-normaliennes/spec/features/users/dossier_creation_spec.rb
Pierre de La Morinerie 4cb747fdb6 specs: always require rails_helper
Test helpers are separated between two files: spec_helper and
rails_helper. This separation is meant to allow tests that do not
require Rails (like testing standalone libs) to boot faster.

The spec_helper file is always loaded, through `--require spec_helper`
in the `.rspec` config file. When needed, the rails_helper file is
expected to be required manually.

This is fine, but:
- Many test files have a redundant `require 'spec_helper'` line;
- Many test files should require `rails_helper`, but don't.

Not requiring `rails_helper` will cause the Rails-concerned section of
the test environment not to be configured–which may cause subtle bugs
(like the test database not being properly initialized).

Moreover, Spring loads all the Rails files on preloading anyway. So the
gains from using only `spec_helper` are thin.

To streamline this process, this commit:
- Configures `.rspec` to require `rails_helper` by default;
- Remove all manual requires to spec_helper or rails_helper.

Reference: https://stackoverflow.com/questions/24145329/how-is-spec-rails-helper-rb-different-from-spec-spec-helper-rb-do-i-need-it
2020-03-31 12:48:32 +02:00

124 lines
4.7 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

feature 'Creating a new dossier:' do
let(:user) { create(:user) }
let(:siret) { '40307130100044' }
let(:siren) { siret[0...9] }
context 'when the user is already signed in' do
before do
login_as user, scope: :user
end
context 'when the procedure has identification by individual' do
let(:procedure) { create(:procedure, :published, :for_individual, :with_service, ask_birthday: ask_birthday) }
let(:ask_birthday) { false }
let(:expected_birthday) { nil }
before do
visit commencer_path(path: procedure.path)
click_on 'Commencer la démarche'
expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last)
expect(page).to have_procedure_description(procedure)
choose 'M.'
fill_in 'individual_nom', with: 'Nom'
fill_in 'individual_prenom', with: 'Prenom'
end
shared_examples 'the user can create a new draft' do
it do
click_button('Continuer')
expect(page).to have_current_path(brouillon_dossier_path(procedure.dossiers.last))
expect(user.dossiers.first.individual.birthdate).to eq(expected_birthday)
end
end
context 'when the birthday is asked' do
let(:ask_birthday) { true }
let(:expected_birthday) { Date.new(1987, 10, 14) }
before do
fill_in 'individual_birthdate', with: birthday_format
end
context 'when the browser supports `type=date` input fields' do
let(:birthday_format) { '1987-10-14' }
it_behaves_like 'the user can create a new draft'
end
context 'when the browser does not support `type=date` input fields' do
let(:birthday_format) { '1987-10-14' }
it_behaves_like 'the user can create a new draft'
end
end
context 'when the birthday is not asked' do
let(:ask_birthday) { false }
let(:expected_birthday) { nil }
it_behaves_like 'the user can create a new draft'
end
end
context 'when identifying through SIRET' do
let(:procedure) { create(:procedure, :published, :with_service, :with_type_de_champ) }
let(:dossier) { procedure.dossiers.last }
before do
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/etablissements\/#{siret}?.*token=/)
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/etablissements.json'))
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/entreprises\/#{siren}?.*token=/)
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/entreprises.json'))
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/exercices\/#{siret}?.*token=/)
.to_return(status: 200, body: File.read('spec/fixtures/files/api_entreprise/exercices.json'))
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/associations\/#{siret}?.*token=/)
.to_return(status: 404, body: '')
end
scenario 'the user can enter the SIRET of its etablissement and create a new draft' do
visit commencer_path(path: procedure.path)
click_on 'Commencer la démarche'
expect(page).to have_current_path siret_dossier_path(dossier)
expect(page).to have_procedure_description(procedure)
fill_in 'Numéro SIRET', with: siret
click_on 'Valider'
expect(page).to have_current_path(etablissement_dossier_path(dossier))
expect(page).to have_content('OCTO-TECHNOLOGY')
click_on 'Continuer avec ces informations'
expect(page).to have_current_path(brouillon_dossier_path(dossier))
end
scenario 'the user is notified when its SIRET is invalid' do
visit commencer_path(path: procedure.path)
click_on 'Commencer la démarche'
expect(page).to have_current_path(siret_dossier_path(dossier))
expect(page).to have_procedure_description(procedure)
fill_in 'Numéro SIRET', with: '0000'
click_on 'Valider'
expect(page).to have_current_path(siret_dossier_path(dossier))
expect(page).to have_content('Le numéro SIRET doit comporter 14 chiffres')
expect(page).to have_field('Numéro SIRET', with: '0000')
end
end
end
context 'when the user is not signed in' do
let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, :published) }
scenario 'the user is an instructeur with untrusted device' do
visit commencer_path(path: procedure.path)
click_on "Jai déjà un compte"
sign_in_with(instructeur.email, instructeur.user.password, true)
expect(page).to have_current_path(commencer_path(path: procedure.path))
end
end
end