cleanup tests
This commit is contained in:
parent
468e9e849a
commit
e043645a88
3 changed files with 65 additions and 33 deletions
|
@ -31,13 +31,6 @@ class DossierSearchService
|
|||
.uniq
|
||||
end
|
||||
|
||||
def self.id_compatible?(number)
|
||||
ActiveRecord::Type::Integer.new.serialize(number)
|
||||
true
|
||||
rescue ActiveModel::RangeError
|
||||
false
|
||||
end
|
||||
|
||||
def self.dossier_by_full_text_for_user(search_terms, dossiers)
|
||||
ts_vector = "to_tsvector('french', search_terms)"
|
||||
ts_query = "to_tsquery('french', #{Dossier.connection.quote(to_tsquery(search_terms))})"
|
||||
|
@ -56,15 +49,11 @@ class DossierSearchService
|
|||
end
|
||||
end
|
||||
|
||||
def self.dossier_by_full_text_for_current_user(search_terms, user)
|
||||
ts_vector = "to_tsvector('french', search_terms || private_search_terms)"
|
||||
ts_query = "to_tsquery('french', #{Dossier.connection.quote(to_tsquery(search_terms))})"
|
||||
|
||||
user
|
||||
.dossiers
|
||||
.state_not_brouillon
|
||||
.where("#{ts_vector} @@ #{ts_query}")
|
||||
.order(Arel.sql("COALESCE(ts_rank(#{ts_vector}, #{ts_query}), 0) DESC"))
|
||||
def self.id_compatible?(number)
|
||||
ActiveRecord::Type::Integer.new.serialize(number)
|
||||
true
|
||||
rescue ActiveModel::RangeError
|
||||
false
|
||||
end
|
||||
|
||||
def self.to_tsquery(search_terms)
|
||||
|
|
|
@ -1,32 +1,47 @@
|
|||
describe RechercheController, type: :controller do
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_all_annotations) }
|
||||
let(:dossier2) { create(:dossier, :en_construction, procedure: dossier.procedure) }
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
|
||||
let(:dossier_with_expert) { avis.dossier }
|
||||
let(:avis) { create(:avis, dossier: create(:dossier, :en_construction, :with_all_annotations)) }
|
||||
|
||||
let(:user) { instructeur.user }
|
||||
|
||||
before do
|
||||
#instructeur.groupe_instructeurs << dossier2.procedure.defaut_groupe_instructeur
|
||||
instructeur.groupe_instructeurs << dossier.procedure.defaut_groupe_instructeur
|
||||
instructeur.assign_to_procedure(dossier.procedure)
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
before { sign_in(instructeur.user) }
|
||||
before { sign_in(user) }
|
||||
|
||||
subject { get :index, params: { q: query } }
|
||||
|
||||
describe 'by id' do
|
||||
context 'when instructeur own the dossier' do
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
let(:query) { dossier.id }
|
||||
|
||||
before { subject }
|
||||
|
||||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
it 'returns the expected dossier' do
|
||||
expect(assigns(:dossiers).count).to eq(1)
|
||||
expect(assigns(:dossiers).first.id).to eq(dossier.id)
|
||||
expect(assigns(:projected_dossiers).count).to eq(1)
|
||||
expect(assigns(:projected_dossiers).first.dossier_id).to eq(dossier.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when expert own the dossier' do
|
||||
let(:user) { avis.experts_procedure.expert.user }
|
||||
let(:query) { dossier_with_expert.id }
|
||||
|
||||
before { subject }
|
||||
|
||||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
it 'returns the expected dossier' do
|
||||
expect(assigns(:projected_dossiers).count).to eq(1)
|
||||
expect(assigns(:projected_dossiers).first.dossier_id).to eq(dossier_with_expert.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,7 +53,7 @@ describe RechercheController, type: :controller do
|
|||
|
||||
it 'does not return the dossier' do
|
||||
subject
|
||||
expect(assigns(:dossiers).count).to eq(0)
|
||||
expect(assigns(:projected_dossiers).count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,7 +64,35 @@ describe RechercheController, type: :controller do
|
|||
|
||||
it 'does not return the dossier' do
|
||||
subject
|
||||
expect(assigns(:dossiers).count).to eq(0)
|
||||
expect(assigns(:projected_dossiers).count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'by private annotations' do
|
||||
context 'when instructeur search by private annotations' do
|
||||
let(:query) { dossier.private_search_terms }
|
||||
|
||||
before { subject }
|
||||
|
||||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
it 'returns the expected dossier' do
|
||||
expect(assigns(:projected_dossiers).count).to eq(1)
|
||||
expect(assigns(:projected_dossiers).first.dossier_id).to eq(dossier.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when expert search by private annotations' do
|
||||
let(:user) { avis.experts_procedure.expert.user }
|
||||
let(:query) { dossier_with_expert.private_search_terms }
|
||||
|
||||
before { subject }
|
||||
|
||||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
it 'returns 0 dossiers' do
|
||||
expect(assigns(:projected_dossiers).count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -61,7 +104,7 @@ describe RechercheController, type: :controller do
|
|||
|
||||
it 'returns 0 dossier' do
|
||||
subject
|
||||
expect(assigns(:dossiers).count).to eq(0)
|
||||
expect(assigns(:projected_dossiers).count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
describe DossierSearchService do
|
||||
describe '#matching_dossiers_for_current_user' do
|
||||
describe '#matching_dossiers' do
|
||||
subject { liste_dossiers }
|
||||
|
||||
let(:liste_dossiers) do
|
||||
described_class.matching_dossiers_for_current_user(terms, instructeur_1.user)
|
||||
described_class.matching_dossiers(instructeur_1.dossiers, terms)
|
||||
end
|
||||
|
||||
let(:administrateur_1) { create(:administrateur) }
|
||||
|
|
Loading…
Reference in a new issue