4cb747fdb6
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
98 lines
3.4 KiB
Ruby
98 lines
3.4 KiB
Ruby
describe DossierSearchService do
|
|
describe '#matching_dossiers_for_instructeur' do
|
|
subject { liste_dossiers }
|
|
|
|
let(:liste_dossiers) do
|
|
described_class.matching_dossiers_for_instructeur(terms, instructeur_1)
|
|
end
|
|
|
|
let(:administrateur_1) { create(:administrateur) }
|
|
let(:administrateur_2) { create(:administrateur) }
|
|
|
|
let(:instructeur_1) { create(:instructeur, administrateurs: [administrateur_1]) }
|
|
let(:instructeur_2) { create(:instructeur, administrateurs: [administrateur_2]) }
|
|
|
|
before do
|
|
instructeur_1.assign_to_procedure(procedure_1)
|
|
instructeur_2.assign_to_procedure(procedure_2)
|
|
end
|
|
|
|
let(:procedure_1) { create(:procedure, :published, administrateur: administrateur_1) }
|
|
let(:procedure_2) { create(:procedure, :published, administrateur: administrateur_2) }
|
|
|
|
let!(:dossier_0) { create(:dossier, state: Dossier.states.fetch(:brouillon), procedure: procedure_1, user: create(:user, email: 'brouillon@clap.fr')) }
|
|
|
|
let!(:etablissement_1) { create(:etablissement, entreprise_raison_sociale: 'OCTO Academy', siret: '41636169600051') }
|
|
let!(:dossier_1) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_1, user: create(:user, email: 'contact@test.com'), etablissement: etablissement_1) }
|
|
|
|
let!(:etablissement_2) { create(:etablissement, entreprise_raison_sociale: 'Plop octo', siret: '41816602300012') }
|
|
let!(:dossier_2) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_1, user: create(:user, email: 'plop@gmail.com'), etablissement: etablissement_2) }
|
|
|
|
let!(:etablissement_3) { create(:etablissement, entreprise_raison_sociale: 'OCTO Technology', siret: '41816609600051') }
|
|
let!(:dossier_3) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_2, user: create(:user, email: 'peace@clap.fr'), etablissement: etablissement_3) }
|
|
|
|
let!(:dossier_archived) { create(:dossier, state: Dossier.states.fetch(:en_construction), procedure: procedure_1, archived: true, user: create(:user, email: 'archived@clap.fr')) }
|
|
|
|
describe 'search is empty' do
|
|
let(:terms) { '' }
|
|
|
|
it { expect(subject.size).to eq(0) }
|
|
end
|
|
|
|
describe 'search brouillon file' do
|
|
let(:terms) { 'brouillon' }
|
|
|
|
it { expect(subject.size).to eq(0) }
|
|
end
|
|
|
|
describe 'search archived file' do
|
|
let(:terms) { 'archived' }
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
end
|
|
|
|
describe 'search on contact email' do
|
|
let(:terms) { 'clap' }
|
|
|
|
it { expect(subject.size).to eq(0) }
|
|
end
|
|
|
|
describe 'search on SIRET' do
|
|
context 'when is part of SIRET' do
|
|
let(:terms) { '4181' }
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
end
|
|
|
|
context 'when is a complet SIRET' do
|
|
let(:terms) { '41816602300012' }
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
end
|
|
end
|
|
|
|
describe 'search on raison social' do
|
|
let(:terms) { 'OCTO' }
|
|
|
|
it { expect(subject.size).to eq(2) }
|
|
end
|
|
|
|
describe 'search terms surrounded with spurious spaces' do
|
|
let(:terms) { ' OCTO ' }
|
|
|
|
it { expect(subject.size).to eq(2) }
|
|
end
|
|
|
|
describe 'search on multiple fields' do
|
|
let(:terms) { 'octo plop' }
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
end
|
|
|
|
describe 'search with characters disallowed by the tsquery parser' do
|
|
let(:terms) { "'?\\:&!(OCTO) <plop>" }
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
end
|
|
end
|
|
end
|