instructeurs: fix ProcedurePresentation to use instructeur.user.email

The `joins` are declared explicitely in order to associate a predictable
name to the joined table.

Otherwise, when the query is joined with `:users`, ActiveRecord will
alias the join automatically  to solve the conflict. Unfortunately, the
automatic resolution means that the table name becomes unpredictable,
and thus unsuitable to perform queries on.
This commit is contained in:
Pierre de La Morinerie 2019-10-16 13:02:42 +02:00
parent 8b8213c301
commit 8e6930d257
3 changed files with 73 additions and 9 deletions

View file

@ -379,6 +379,26 @@ describe ProcedurePresentation do
end
end
context 'for followers_instructeurs table' do
let(:table) { 'followers_instructeurs' }
let(:order) { 'asc' } # Desc works the same, no extra test required
let!(:dossier_a) { create(:dossier, :en_construction, procedure: procedure) }
let!(:dossier_z) { create(:dossier, :en_construction, procedure: procedure) }
let!(:dossier_without_instructeur) { create(:dossier, :en_construction, procedure: procedure) }
before do
create(:follow, dossier: dossier_a, instructeur: create(:instructeur, email: 'abaca@exemple.fr'))
create(:follow, dossier: dossier_z, instructeur: create(:instructeur, email: 'zythum@exemple.fr'))
end
context 'for email column' do
let(:column) { 'email' }
it { is_expected.to eq([dossier_a, dossier_z, dossier_without_instructeur].map(&:id)) }
end
end
context 'for other tables' do
# All other columns and tables work the same so its ok to test only one
let(:table) { 'etablissement' }
@ -395,7 +415,7 @@ describe ProcedurePresentation do
describe '#filtered_ids' do
let(:procedure_presentation) { create(:procedure_presentation, assign_to: create(:assign_to, procedure: procedure), filters: { "suivis" => filter }) }
subject { procedure_presentation.filtered_ids(procedure.dossiers, 'suivis') }
subject { procedure_presentation.filtered_ids(procedure.dossiers.joins(:user), 'suivis') }
context 'for self table' do
context 'for created_at column' do