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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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