Revert for_api value on yes_no champs

This commit is contained in:
Paul Chavard 2019-01-29 14:37:57 +01:00
parent 7c59f953e3
commit 7678d8eb0b
3 changed files with 69 additions and 19 deletions

View file

@ -1,19 +1,9 @@
class Champs::CheckboxChamp < Champ class Champs::CheckboxChamp < Champs::YesNoChamp
def search_terms def true?
if value == 'on' value == 'on'
[libelle]
end
end
def to_s
value == 'on' ? 'Oui' : 'Non'
end end
def for_export def for_export
value == 'on' ? 'on' : 'off' true? ? 'on' : 'off'
end
def for_api
value == 'on' ? 'on' : 'off'
end end
end end

View file

@ -1,6 +1,6 @@
class Champs::YesNoChamp < Champs::CheckboxChamp class Champs::YesNoChamp < Champ
def search_terms def search_terms
if value == 'true' if true?
[libelle] [libelle]
end end
end end
@ -13,13 +13,13 @@ class Champs::YesNoChamp < Champs::CheckboxChamp
processed_value processed_value
end end
def for_api def true?
processed_value value == 'true'
end end
private private
def processed_value def processed_value
value == 'true' ? 'Oui' : 'Non' true? ? 'Oui' : 'Non'
end end
end end

View file

@ -196,5 +196,65 @@ describe ChampSerializer do
expect(subject[:entreprise]).to include(capital_social: etablissement.entreprise_capital_social) expect(subject[:entreprise]).to include(capital_social: etablissement.entreprise_capital_social)
} }
end end
context 'when type champ yes_no' do
context 'true' do
let(:champ) { create(:champ_yes_no, value: 'true') }
it { is_expected.to include(value: 'true') }
end
context 'false' do
let(:champ) { create(:champ_yes_no, value: 'false') }
it { is_expected.to include(value: 'false') }
end
context 'nil' do
let(:champ) { create(:champ_yes_no, value: nil) }
it { is_expected.to include(value: nil) }
end
end
context 'when type champ checkbox' do
context 'on' do
let(:champ) { create(:champ_checkbox, value: 'on') }
it { is_expected.to include(value: 'on') }
end
context 'off' do
let(:champ) { create(:champ_checkbox, value: 'off') }
it { is_expected.to include(value: 'off') }
end
context 'nil' do
let(:champ) { create(:champ_checkbox, value: nil) }
it { is_expected.to include(value: nil) }
end
end
context 'when type champ engagement' do
context 'on' do
let(:champ) { create(:champ_engagement, value: 'on') }
it { is_expected.to include(value: 'on') }
end
context 'off' do
let(:champ) { create(:champ_engagement, value: 'off') }
it { is_expected.to include(value: 'off') }
end
context 'nil' do
let(:champ) { create(:champ_engagement, value: nil) }
it { is_expected.to include(value: nil) }
end
end
end end
end end