Merge pull request #1263 from betagouv/better-methods

Better methods
This commit is contained in:
gregoirenovel 2018-01-30 15:56:45 +01:00 committed by GitHub
commit 75c8c7c0b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 29 additions and 36 deletions

View file

@ -32,13 +32,9 @@ class SIADE::EtablissementAdapter
end end
def adresse def adresse
adresse = '' [:l1, :l2, :l3, :l4, :l5, :l6, :l7].map do |line|
[:l1, :l2, :l3, :l4, :l5, :l6, :l7].each do |line| data_source[:etablissement][:adresse][line]
if data_source[:etablissement][:adresse][line].present? end.compact.join("\r\n")
adresse = adresse + data_source[:etablissement][:adresse][line] + "\r\n"
end
end
adresse
end end
def address_attribut_to_fetch def address_attribut_to_fetch

View file

@ -14,7 +14,7 @@ class Commentaire < ActiveRecord::Base
after_create :notify after_create :notify
def header 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 end
def file_url def file_url

View file

@ -154,12 +154,9 @@ class Dossier < ActiveRecord::Base
end end
def convert_specific_hash_values_to_string(hash_to_convert) def convert_specific_hash_values_to_string(hash_to_convert)
hash = {} hash_to_convert.transform_values do |value|
hash_to_convert.each do |key, value| serialize_value_for_export(value)
value = serialize_value_for_export(value)
hash.store(key, value)
end end
hash
end end
def full_data_strings_array def full_data_strings_array
@ -170,11 +167,11 @@ class Dossier < ActiveRecord::Base
def export_entreprise_data def export_entreprise_data
if entreprise.present? if entreprise.present?
etablissement_attr = EtablissementCsvSerializer.new(self.etablissement).attributes.map { |k, v| ["etablissement.#{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.map { |k, v| ["entreprise.#{k}".parameterize.underscore.to_sym, v] }.to_h entreprise_attr = EntrepriseSerializer.new(self.entreprise).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym }
else else
etablissement_attr = EtablissementSerializer.new(Etablissement.new).attributes.map { |k, v| ["etablissement.#{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.map { |k, v| ["entreprise.#{k}".parameterize.underscore.to_sym, v] }.to_h entreprise_attr = EntrepriseSerializer.new(Entreprise.new).attributes.transform_keys { |k| "entreprise.#{k}".parameterize.underscore.to_sym }
end end
convert_specific_hash_values_to_string(etablissement_attr.merge(entreprise_attr)) convert_specific_hash_values_to_string(etablissement_attr.merge(entreprise_attr))
end end

View file

@ -55,8 +55,8 @@ class Gestionnaire < ActiveRecord::Base
procedure_ids = followed_dossiers.pluck(:procedure_id) procedure_ids = followed_dossiers.pluck(:procedure_id)
if procedure_ids.include?(procedure.id) if procedure_ids.include?(procedure.id)
return followed_dossiers.where(procedure_id: procedure.id).inject(0) do |acc, dossier| return followed_dossiers.where(procedure_id: procedure.id).sum do |dossier|
acc += dossier.notifications.where(already_read: false).count dossier.notifications.where(already_read: false).count
end end
end end
0 0

View file

@ -23,11 +23,11 @@ class RenderPartialService
private private
def retrieve_navbar def retrieve_navbar
'layouts/navbars/navbar_' + retrieve_name "layouts/navbars/navbar_#{retrieve_name}"
end end
def retrieve_left_panel def retrieve_left_panel
'layouts/left_panels/left_panel_' + retrieve_name "layouts/left_panels/left_panel_#{retrieve_name}"
end end
def retrieve_name def retrieve_name

View file

@ -302,8 +302,8 @@ shared_examples 'description_controller_spec' do
before do before do
post :update, params: { post :update, params: {
dossier_id: dossier_id, dossier_id: dossier_id,
'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, "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[1].to_s}" => piece_justificative_1
} }
dossier.reload dossier.reload
end end
@ -314,8 +314,8 @@ shared_examples 'description_controller_spec' do
post :update, params: { post :update, params: {
dossier_id: dossier_id, dossier_id: dossier_id,
'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, "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[1].to_s}" => piece_justificative_1
} }
end end
end end
@ -355,8 +355,8 @@ shared_examples 'description_controller_spec' do
subject { subject {
patch :pieces_justificatives, params: { patch :pieces_justificatives, params: {
dossier_id: dossier.id, dossier_id: dossier.id,
'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, "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[1].to_s}" => piece_justificative_1
} }
} }
@ -434,8 +434,8 @@ shared_examples 'description_controller_spec_POST_piece_justificatives_for_owner
subject { subject {
patch :pieces_justificatives, params: { patch :pieces_justificatives, params: {
dossier_id: dossier.id, dossier_id: dossier.id,
'piece_justificative_' + all_pj_type[0].to_s => piece_justificative_0, "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[1].to_s}" => piece_justificative_1
} }
} }

View file

@ -44,7 +44,7 @@ feature 'user is on description page' do
end end
context 'when he adds a piece_justificative and submit form', vcr: { cassette_name: 'description_page_upload_piece_justificative_adds_cerfa_and_submit' } do 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 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')) attach_file(file_input_id, File.path('spec/support/files/dossierPDF.pdf'))
click_on('Soumettre mon dossier') click_on('Soumettre mon dossier')
dossier.reload dossier.reload

View file

@ -21,7 +21,7 @@ feature 'As a User I want to edit a dossier I own' do
end end
scenario 'Getting a dossier, I want to create a new message on', js: true do 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)) expect(page).to have_current_path(users_dossier_recapitulatif_path(Dossier.first.id.to_s))
page.find_by_id('open-message').click page.find_by_id('open-message').click
page.execute_script("$('#texte_commentaire').data('wysihtml5').editor.setValue('Contenu du nouveau message')") 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 end
scenario 'On the same dossier, I want to edit informations', js: true do 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)) expect(page).to have_current_path(users_dossier_recapitulatif_path(dossier.id.to_s))
# Linked Dossier # Linked Dossier

View file

@ -33,7 +33,7 @@ describe SIADE::EtablissementAdapter do
context 'Concaténation lignes adresse' do context 'Concaténation lignes adresse' do
it 'L\'entreprise contient bien une adresse sur plusieurs lignes' 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
end end

View file

@ -95,7 +95,7 @@ describe Gestionnaire, type: :model do
it { is_expected.to eq 0 } it { is_expected.to eq 0 }
it { expect(gestionnaire.follows.count).to eq 0 } it { expect(gestionnaire.follows.count).to eq 0 }
it do 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 subject
end end
end end
@ -108,7 +108,7 @@ describe Gestionnaire, type: :model do
it { is_expected.to eq 0 } it { is_expected.to eq 0 }
it { expect(gestionnaire.follows.count).to eq 1 } it { expect(gestionnaire.follows.count).to eq 1 }
it do 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 subject
end end
end end
@ -124,7 +124,7 @@ describe Gestionnaire, type: :model do
it { is_expected.to eq 1 } it { is_expected.to eq 1 }
it { expect(gestionnaire.follows.count).to eq 1 } it { expect(gestionnaire.follows.count).to eq 1 }
it do it do
expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).to receive(:inject) expect_any_instance_of(Dossier::ActiveRecord_AssociationRelation).to receive(:sum)
subject subject
end end
end end