From b33f11115c4fecb88465041041d36b1c48c19f6c Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 8 Aug 2018 15:39:18 +0200 Subject: [PATCH] [fix #2358] Checkbox: serialize in attestation by oui or no --- app/models/champs/checkbox_champ.rb | 4 ++++ spec/models/champs/checkbox_champ_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 spec/models/champs/checkbox_champ_spec.rb diff --git a/app/models/champs/checkbox_champ.rb b/app/models/champs/checkbox_champ.rb index 5bd6dea75..9202ca635 100644 --- a/app/models/champs/checkbox_champ.rb +++ b/app/models/champs/checkbox_champ.rb @@ -4,4 +4,8 @@ class Champs::CheckboxChamp < Champ [ libelle ] end end + + def to_s + value == 'on' ? 'oui' : 'non' + end end diff --git a/spec/models/champs/checkbox_champ_spec.rb b/spec/models/champs/checkbox_champ_spec.rb new file mode 100644 index 000000000..556a8a69a --- /dev/null +++ b/spec/models/champs/checkbox_champ_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Champs::CheckboxChamp do + let(:checkbox) { Champs::CheckboxChamp.new(value: value) } + + describe '#to_s' do + subject { checkbox.to_s } + + context 'when the value is on' do + let(:value) { 'on' } + + it { is_expected.to eq('oui') } + end + + context 'when the value is off' do + let(:value) { 'off' } + + it { is_expected.to eq('non') } + end + end +end