diff --git a/app/lib/siade/etablissement_adapter.rb b/app/lib/siade/etablissement_adapter.rb index ef03721b3..6b52d6bda 100644 --- a/app/lib/siade/etablissement_adapter.rb +++ b/app/lib/siade/etablissement_adapter.rb @@ -32,13 +32,9 @@ class SIADE::EtablissementAdapter end def adresse - adresse = '' - [:l1, :l2, :l3, :l4, :l5, :l6, :l7].each do |line| - if data_source[:etablissement][:adresse][line].present? - adresse = adresse + data_source[:etablissement][:adresse][line] + "\r\n" - end - end - adresse + [:l1, :l2, :l3, :l4, :l5, :l6, :l7].map do |line| + data_source[:etablissement][:adresse][line] + end.compact.join("\r\n") end def address_attribut_to_fetch diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 7b3c651d9..3cfeab1da 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -14,7 +14,7 @@ class Commentaire < ActiveRecord::Base after_create :notify def header - "#{email}, " + I18n.l(created_at.localtime, format: '%d %b %Y %H:%M') + "#{email}, #{I18n.l(created_at.localtime, format: '%d %b %Y %H:%M')}" end def file_url diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 5843337d2..a1dd384e1 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -154,12 +154,9 @@ class Dossier < ActiveRecord::Base end def convert_specific_hash_values_to_string(hash_to_convert) - hash = {} - hash_to_convert.each do |key, value| - value = serialize_value_for_export(value) - hash.store(key, value) + hash_to_convert.transform_values do |value| + serialize_value_for_export(value) end - hash end def full_data_strings_array @@ -170,11 +167,11 @@ class Dossier < ActiveRecord::Base def export_entreprise_data if entreprise.present? - etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{k}".parameterize.underscore.to_sym, v] }.to_h - entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.map { |k, v| ["entreprise.#{k}".parameterize.underscore.to_sym, v] }.to_h + etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym } + entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym } else - etablissement_attr = EtablissementSerializer.new(Etablissement.new).attributes.map { |k, v| ["etablissement.#{k}".parameterize.underscore.to_sym, v] }.to_h - entreprise_attr = EntrepriseSerializer.new(Entreprise.new).attributes.map { |k, v| ["entreprise.#{k}".parameterize.underscore.to_sym, v] }.to_h + etablissement_attr = EtablissementSerializer.new(Etablissement.new).attributes.transform_keys { |k| "etablissement.#{k}".parameterize.underscore.to_sym } + entreprise_attr = EntrepriseSerializer.new(Entreprise.new).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym } end convert_specific_hash_values_to_string(etablissement_attr.merge(entreprise_attr)) end diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb index 02cd33e81..1b965373a 100644 --- a/app/models/gestionnaire.rb +++ b/app/models/gestionnaire.rb @@ -55,8 +55,8 @@ class Gestionnaire < ActiveRecord::Base procedure_ids = followed_dossiers.pluck(:procedure_id) if procedure_ids.include?(procedure.id) - return followed_dossiers.where(procedure_id: procedure.id).inject(0) do |acc, dossier| - acc += dossier.notifications.where(already_read: false).count + return followed_dossiers.where(procedure_id: procedure.id).sum do |dossier| + dossier.notifications.where(already_read: false).count end end 0 diff --git a/app/services/render_partial_service.rb b/app/services/render_partial_service.rb index 5d37024ea..186c8f633 100644 --- a/app/services/render_partial_service.rb +++ b/app/services/render_partial_service.rb @@ -23,11 +23,11 @@ class RenderPartialService private def retrieve_navbar - 'layouts/navbars/navbar_' + retrieve_name + "layouts/navbars/navbar_#{retrieve_name}" end def retrieve_left_panel - 'layouts/left_panels/left_panel_' + retrieve_name + "layouts/left_panels/left_panel_#{retrieve_name}" end def retrieve_name diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb index 0811a33e4..4a5d57e85 100644 --- a/spec/controllers/users/description_controller_shared_example.rb +++ b/spec/controllers/users/description_controller_shared_example.rb @@ -302,8 +302,8 @@ shared_examples 'description_controller_spec' do before do post :update, params: { dossier_id: dossier_id, - 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, - 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 + "piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0, + "piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1 } dossier.reload end @@ -314,8 +314,8 @@ shared_examples 'description_controller_spec' do post :update, params: { dossier_id: dossier_id, - 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, - 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 + "piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0, + "piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1 } end end @@ -355,8 +355,8 @@ shared_examples 'description_controller_spec' do subject { patch :pieces_justificatives, params: { dossier_id: dossier.id, - 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, - 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 + "piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0, + "piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1 } } @@ -434,8 +434,8 @@ shared_examples 'description_controller_spec_POST_piece_justificatives_for_owner subject { patch :pieces_justificatives, params: { dossier_id: dossier.id, - 'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, - 'piece_justificative_' + all_pj_type[1].to_s => piece_justificative_1 + "piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0, + "piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1 } } diff --git a/spec/features/description_page/upload_piece_justificative_spec.rb b/spec/features/description_page/upload_piece_justificative_spec.rb index 25ccf4f75..50f00c9fb 100644 --- a/spec/features/description_page/upload_piece_justificative_spec.rb +++ b/spec/features/description_page/upload_piece_justificative_spec.rb @@ -44,7 +44,7 @@ feature 'user is on description page' do end context 'when he adds a piece_justificative and submit form', vcr: { cassette_name: 'description_page_upload_piece_justificative_adds_cerfa_and_submit' } do before do - file_input_id = 'piece_justificative_' + dossier.types_de_piece_justificative.first.id.to_s + file_input_id = "piece_justificative_#{dossier.types_de_piece_justificative.first.id.to_s}" attach_file(file_input_id, File.path('spec/support/files/dossierPDF.pdf')) click_on('Soumettre mon dossier') dossier.reload diff --git a/spec/features/users/dossier_edition_spec.rb b/spec/features/users/dossier_edition_spec.rb index d64311de5..3de44ef52 100644 --- a/spec/features/users/dossier_edition_spec.rb +++ b/spec/features/users/dossier_edition_spec.rb @@ -21,7 +21,7 @@ feature 'As a User I want to edit a dossier I own' do end scenario 'Getting a dossier, I want to create a new message on', js: true do - page.find_by_id('tr_dossier_' + dossier.id.to_s).click + page.find_by_id("tr_dossier_#{dossier.id.to_s}").click expect(page).to have_current_path(users_dossier_recapitulatif_path(Dossier.first.id.to_s)) page.find_by_id('open-message').click page.execute_script("$('#texte_commentaire').data('wysihtml5').editor.setValue('Contenu du nouveau message')") @@ -30,7 +30,7 @@ feature 'As a User I want to edit a dossier I own' do end scenario 'On the same dossier, I want to edit informations', js: true do - page.find_by_id('tr_dossier_' + dossier.id.to_s).click + page.find_by_id("tr_dossier_#{dossier.id.to_s}").click expect(page).to have_current_path(users_dossier_recapitulatif_path(dossier.id.to_s)) # Linked Dossier diff --git a/spec/lib/siade/etablissement_adapter_spec.rb b/spec/lib/siade/etablissement_adapter_spec.rb index 394f2ee70..3e5092692 100644 --- a/spec/lib/siade/etablissement_adapter_spec.rb +++ b/spec/lib/siade/etablissement_adapter_spec.rb @@ -33,7 +33,7 @@ describe SIADE::EtablissementAdapter do context 'Concaténation lignes adresse' do it 'L\'entreprise contient bien une adresse sur plusieurs lignes' do - expect(subject[:adresse]).to eq("OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE\r\n") + expect(subject[:adresse]).to eq("OCTO TECHNOLOGY\r\n50 AVENUE DES CHAMPS ELYSEES\r\n75008 PARIS\r\nFRANCE") end end diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index e300ffe6c..7b92dd830 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -95,7 +95,7 @@ describe Gestionnaire, type: :model do it { is_expected.to eq 0 } it { expect(gestionnaire.follows.count).to eq 0 } it do - expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject) + expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:sum) subject end end @@ -108,7 +108,7 @@ describe Gestionnaire, type: :model do it { is_expected.to eq 0 } it { expect(gestionnaire.follows.count).to eq 1 } it do - expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:inject) + expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).not_to receive(:sum) subject end end @@ -124,7 +124,7 @@ describe Gestionnaire, type: :model do it { is_expected.to eq 1 } it { expect(gestionnaire.follows.count).to eq 1 } it do - expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).to receive(:inject) + expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).to receive(:sum) subject end end