From 33f29f35ab8d704ee203ded88c656742effcee0f Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Thu, 4 Oct 2018 16:56:41 +0200 Subject: [PATCH] Avoid recreating service too often --- app/models/dossier.rb | 4 ---- .../procedures/show.html.haml | 3 ++- spec/models/dossier_spec.rb | 23 ------------------- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 525ac3912..f4c28c44d 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -223,10 +223,6 @@ class Dossier < ApplicationRecord end end - def get_value(table, column) - DossierFieldService.new.get_value(self, table, column) - end - def owner_name if etablissement.present? etablissement.entreprise_raison_sociale diff --git a/app/views/new_gestionnaire/procedures/show.html.haml b/app/views/new_gestionnaire/procedures/show.html.haml index ebcf41b7f..8b5054168 100644 --- a/app/views/new_gestionnaire/procedures/show.html.haml +++ b/app/views/new_gestionnaire/procedures/show.html.haml @@ -92,6 +92,7 @@ = submit_tag "Enregistrer", class: 'button' %tbody + - dossier_field_service = DossierFieldService.new - @dossiers.each do |dossier| %tr %td.folder-col @@ -107,7 +108,7 @@ - @displayed_fields.each do |field| %td = link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do - = dossier.get_value(field['table'], field['column']) + = dossier_field_service.get_value(dossier, field['table'], field['column']) %td.status-col = link_to(gestionnaire_dossier_path(@procedure, dossier), class: 'cell-link') do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 3d6960488..351a890d8 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -732,29 +732,6 @@ describe Dossier do end end - describe "#get_value" do - let(:dossier) { create(:dossier, :with_entreprise, user: user) } - - before do - FranceConnectInformation.create(france_connect_particulier_id: 123, user: user, gender: 'male') - - @champ_public = dossier.champs.first - @champ_public.value = "kiwi" - @champ_public.save - - @champ_private = dossier.champs_private.first - @champ_private.value = "banane" - @champ_private.save - end - - it { expect(dossier.get_value('self', 'created_at')).to eq(dossier.created_at) } - it { expect(dossier.get_value('user', 'email')).to eq(user.email) } - it { expect(dossier.get_value('etablissement', 'entreprise_siren')).to eq(dossier.etablissement.entreprise_siren) } - it { expect(dossier.get_value('etablissement', 'siret')).to eq(dossier.etablissement.siret) } - it { expect(dossier.get_value('type_de_champ', @champ_public.type_de_champ.id.to_s)).to eq(dossier.champs.first.value) } - it { expect(dossier.get_value('type_de_champ_private', @champ_private.type_de_champ.id.to_s)).to eq(dossier.champs_private.first.value) } - end - describe 'updated_at' do let!(:dossier) { create(:dossier) } let(:modif_date) { DateTime.parse('01/01/2100') }