Remove the proxy value_for_export method

Overload for_export instead
This commit is contained in:
gregoirenovel 2018-12-28 15:46:38 +01:00
parent 7cd50531cf
commit 9e42190148
8 changed files with 24 additions and 28 deletions

View file

@ -49,7 +49,7 @@ class Champ < ApplicationRecord
def for_export
if value.present?
value_for_export
value
else
nil
end
@ -58,10 +58,4 @@ class Champ < ApplicationRecord
def main_value_name
:value
end
private
def value_for_export
value
end
end

View file

@ -1,7 +1,7 @@
class Champs::DecimalNumberChamp < Champ
validates :value, numericality: { allow_nil: true, allow_blank: true }
def value_for_export
value.to_f
def for_export
value.present? ? value.to_f : nil
end
end

View file

@ -1,7 +1,7 @@
class Champs::IntegerNumberChamp < Champ
validates :value, numericality: { only_integer: true, allow_nil: true, allow_blank: true }
def value_for_export
value.to_i
def for_export
value.present? ? value.to_i : nil
end
end

View file

@ -33,6 +33,10 @@ class Champs::LinkedDropDownListChamp < Champ
value.present? ? [primary_value, secondary_value].compact.join(' / ') : ""
end
def for_export
value.present? ? "#{primary_value || ''};#{secondary_value || ''}" : nil
end
def mandatory_and_blank?
mandatory? && (primary_value.blank? || secondary_value.blank?)
end
@ -43,10 +47,6 @@ class Champs::LinkedDropDownListChamp < Champ
private
def value_for_export
"#{primary_value || ''};#{secondary_value || ''}"
end
def pack_value(primary, secondary)
self.value = JSON.generate([primary, secondary])
end

View file

@ -13,6 +13,10 @@ class Champs::MultipleDropDownListChamp < Champ
value.present? ? selected_options.join(', ') : ''
end
def for_export
value.present? ? selected_options.join(', ') : nil
end
private
def format_before_save
@ -26,8 +30,4 @@ class Champs::MultipleDropDownListChamp < Champ
end
end
end
def value_for_export
selected_options.join(', ')
end
end

View file

@ -1,7 +1,5 @@
class Champs::TextareaChamp < Champs::TextChamp
private
def value_for_export
ActionView::Base.full_sanitizer.sanitize(value)
def for_export
value.present? ? ActionView::Base.full_sanitizer.sanitize(value) : nil
end
end

View file

@ -6,12 +6,16 @@ class Champs::YesNoChamp < Champs::CheckboxChamp
end
def to_s
value_for_export
processed_value
end
def for_export
processed_value
end
private
def value_for_export
def processed_value
value == 'true' ? 'oui' : 'non'
end
end

View file

@ -104,19 +104,19 @@ describe Champ do
context 'if yes' do
let(:value) { 'true' }
it { expect(champ.for_export).to eq('oui') }
it { expect(champ.for_export).to eq('Oui') }
end
context 'if no' do
let(:value) { 'false' }
it { expect(champ.for_export).to eq('non') }
it { expect(champ.for_export).to eq('Non') }
end
context 'if nil' do
let(:value) { nil }
it { expect(champ.for_export).to eq(nil) }
it { expect(champ.for_export).to eq('non') }
end
end