[fix #905] Champ: add for_export method which strips tag for textarea champ
This commit is contained in:
parent
3f2419a2a3
commit
338911d1a8
3 changed files with 37 additions and 2 deletions
|
@ -70,6 +70,19 @@ class Champ < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def for_export
|
||||
if value.present?
|
||||
case type_champ
|
||||
when 'textarea'
|
||||
ActionView::Base.full_sanitizer.sanitize(value)
|
||||
else
|
||||
value
|
||||
end
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_date_to_iso
|
||||
|
|
|
@ -251,8 +251,8 @@ class Dossier < ActiveRecord::Base
|
|||
def to_sorted_values
|
||||
serialized_dossier = DossierTableExportSerializer.new(self)
|
||||
values = serialized_dossier.attributes.values
|
||||
values += self.ordered_champs.map(&:value)
|
||||
values += self.ordered_champs_private.map(&:value)
|
||||
values += self.ordered_champs.map(&:for_export)
|
||||
values += self.ordered_champs_private.map(&:for_export)
|
||||
values += self.export_entreprise_data.values
|
||||
values
|
||||
end
|
||||
|
|
|
@ -63,4 +63,26 @@ describe Champ do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'for_export' do
|
||||
let(:type_de_champ) { create(:type_de_champ_public, type_champ: type_champ) }
|
||||
let(:champ) { Champ.new(type_de_champ: type_de_champ, value: value) }
|
||||
|
||||
before { champ.save }
|
||||
|
||||
context 'when type_de_champ is text' do
|
||||
let(:type_champ) { 'text' }
|
||||
let(:value) { '123' }
|
||||
|
||||
it { expect(champ.for_export).to eq('123') }
|
||||
end
|
||||
|
||||
context 'when type_de_champ is textarea' do
|
||||
let(:type_champ) { 'textarea' }
|
||||
let(:value) { '<b>gras<b>' }
|
||||
|
||||
it { expect(champ.for_export).to eq('gras') }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue