Make some methods private

This commit is contained in:
gregoirenovel 2018-04-26 18:41:04 +02:00
parent f020fa9e2b
commit 886431b120
2 changed files with 32 additions and 32 deletions

View file

@ -132,32 +132,6 @@ class Dossier < ApplicationRecord
procedure.cerfa_flag? && cerfa.size != 0
end
def convert_specific_hash_values_to_string(hash_to_convert)
hash_to_convert.transform_values do |value|
serialize_value_for_export(value)
end
end
def export_etablissement_data
if etablissement.present?
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.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
def to_sorted_values
serialized_dossier = DossierTableExportSerializer.new(self)
values = serialized_dossier.attributes.values
values += ordered_champs.map(&:for_export)
values += ordered_champs_private.map(&:for_export)
values += export_etablissement_data.values
values
end
def export_headers
serialized_dossier = DossierTableExportSerializer.new(self)
headers = serialized_dossier.attributes.keys
@ -316,6 +290,32 @@ class Dossier < ApplicationRecord
value.nil? || value.kind_of?(Time) ? value : value.to_s
end
def convert_specific_hash_values_to_string(hash_to_convert)
hash_to_convert.transform_values do |value|
serialize_value_for_export(value)
end
end
def export_etablissement_data
if etablissement.present?
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.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
def to_sorted_values
serialized_dossier = DossierTableExportSerializer.new(self)
values = serialized_dossier.attributes.values
values += ordered_champs.map(&:for_export)
values += ordered_champs_private.map(&:for_export)
values += export_etablissement_data.values
values
end
def send_dossier_received
if saved_change_to_state? && en_instruction?
NotificationMailer.send_dossier_received(id).deliver_later

View file

@ -158,7 +158,7 @@ describe Dossier do
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
let(:dossier_serialized_attributes) { DossierSerializer.new(dossier).attributes }
subject { dossier.convert_specific_hash_values_to_string(dossier_serialized_attributes) }
subject { dossier.send(:convert_specific_hash_values_to_string, dossier_serialized_attributes) }
it { expect(dossier_serialized_attributes[:id]).to be_an(Integer) }
it { expect(dossier_serialized_attributes[:created_at]).to be_a(Time) }
@ -177,7 +177,7 @@ describe Dossier do
let(:procedure) { create(:procedure) }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
subject { dossier.export_etablissement_data }
subject { dossier.send(:export_etablissement_data) }
it { expect(subject[:etablissement_siret]).to eq('44011762001530') }
it { expect(subject[:etablissement_siege_social]).to eq('true') }
@ -228,12 +228,12 @@ describe Dossier do
expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count +
dossier.procedure.types_de_champ.count +
dossier.procedure.types_de_champ_private.count +
dossier.export_etablissement_data.count)
dossier.send(:export_etablissement_data).count)
end
end
describe '#to_sorted_values' do
subject { dossier.to_sorted_values }
subject { dossier.send(:to_sorted_values) }
it { expect(subject[0]).to be_a_kind_of(Integer) }
it { expect(subject[1]).to be_a_kind_of(Time) }
@ -255,13 +255,13 @@ describe Dossier do
expect(subject.count).to eq(DossierTableExportSerializer.new(dossier).attributes.count +
dossier.procedure.types_de_champ.count +
dossier.procedure.types_de_champ_private.count +
dossier.export_etablissement_data.count)
dossier.send(:export_etablissement_data).count)
end
context 'dossier for individual' do
let(:dossier_with_individual) { create(:dossier, :for_individual, user: user, procedure: procedure) }
subject { dossier_with_individual.to_sorted_values }
subject { dossier_with_individual.send(:to_sorted_values) }
it { expect(subject[11]).to eq(dossier_with_individual.individual.gender) }
it { expect(subject[12]).to eq(dossier_with_individual.individual.prenom) }