From 9d406770a8760a10f7805e2d7043be56f0390d97 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 6 Nov 2018 16:20:11 +0100 Subject: [PATCH] [fix #2956] YesNo: fixing to_s --- app/models/champs/yes_no_champ.rb | 4 ++++ spec/models/champs/yes_no_champ_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 spec/models/champs/yes_no_champ_spec.rb diff --git a/app/models/champs/yes_no_champ.rb b/app/models/champs/yes_no_champ.rb index 6fcd401b9..27ead824a 100644 --- a/app/models/champs/yes_no_champ.rb +++ b/app/models/champs/yes_no_champ.rb @@ -5,6 +5,10 @@ class Champs::YesNoChamp < Champs::CheckboxChamp end end + def to_s + value_for_export + end + private def value_for_export diff --git a/spec/models/champs/yes_no_champ_spec.rb b/spec/models/champs/yes_no_champ_spec.rb new file mode 100644 index 000000000..0eeb81b43 --- /dev/null +++ b/spec/models/champs/yes_no_champ_spec.rb @@ -0,0 +1,23 @@ +describe Champs::YesNoChamp do + describe '#to_s' do + subject { Champs::YesNoChamp.new(value: value).to_s } + + context 'when the value is false' do + let(:value) { "false" } + + it { is_expected.to eq("non") } + end + + context 'when the value is true' do + let(:value) { "true" } + + it { is_expected.to eq("oui") } + end + + context 'when the value is nil' do + let(:value) { nil } + + it { is_expected.to eq("non") } + end + end +end