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
def search_terms
if value == 'on'
[libelle]
end
end
def to_s
value == 'on' ? 'Oui' : 'Non'
class Champs::CheckboxChamp < Champs::YesNoChamp
def true?
value == 'on'
end
def for_export
value == 'on' ? 'on' : 'off'
end
def for_api
value == 'on' ? 'on' : 'off'
true? ? 'on' : 'off'
end
end

View file

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

View file

@ -196,5 +196,65 @@ describe ChampSerializer do
expect(subject[:entreprise]).to include(capital_social: etablissement.entreprise_capital_social)
}
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