add champ_value for dropdown
This commit is contained in:
parent
809d991819
commit
5ac3049033
4 changed files with 26 additions and 1 deletions
|
@ -16,6 +16,8 @@ module Logic
|
|||
case [left.type, right.type]
|
||||
in [a, ^a] # syntax for same type
|
||||
true
|
||||
in [:enum, :string]
|
||||
left.options.include?(right.value)
|
||||
else
|
||||
false
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ class Logic::ChampValue < Logic::Term
|
|||
champ(champs).true?
|
||||
when all_types.fetch(:integer_number), all_types.fetch(:decimal_number)
|
||||
champ(champs).for_api
|
||||
when all_types.fetch(:text)
|
||||
when all_types.fetch(:drop_down_list), all_types.fetch(:text)
|
||||
champ(champs).value
|
||||
end
|
||||
end
|
||||
|
@ -28,6 +28,8 @@ class Logic::ChampValue < Logic::Term
|
|||
:number
|
||||
when all_types.fetch(:text)
|
||||
:string
|
||||
when all_types.fetch(:drop_down_list)
|
||||
:enum
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,6 +56,10 @@ class Logic::ChampValue < Logic::Term
|
|||
self.class == other.class && @stable_id == other.stable_id
|
||||
end
|
||||
|
||||
def options
|
||||
type_de_champ.drop_down_list_enabled_non_empty_options
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def type_de_champ
|
||||
|
|
|
@ -41,6 +41,13 @@ describe Logic::ChampValue do
|
|||
it { is_expected.to eq(42.01) }
|
||||
end
|
||||
|
||||
context 'dropdown tdc' do
|
||||
let(:champ) { create(:champ_drop_down_list, value: 'choix 1') }
|
||||
|
||||
it { expect(champ_value(champ.stable_id).type).to eq(:enum) }
|
||||
it { is_expected.to eq('choix 1') }
|
||||
end
|
||||
|
||||
context 'checkbox tdc' do
|
||||
let(:champ) { create(:champ_checkbox, value: 'on') }
|
||||
|
||||
|
|
|
@ -18,6 +18,16 @@ describe Logic do
|
|||
describe '.compatible_type?' do
|
||||
it { expect(Logic.compatible_type?(constant(true), constant(true))).to be true }
|
||||
it { expect(Logic.compatible_type?(constant(1), constant(true))).to be false }
|
||||
|
||||
context 'with a dropdown' do
|
||||
let(:drop_down) { create(:type_de_champ_drop_down_list) }
|
||||
let(:first_option) { drop_down.drop_down_list_enabled_non_empty_options.first }
|
||||
|
||||
it do
|
||||
expect(Logic.compatible_type?(champ_value(drop_down.stable_id), constant(first_option))).to be true
|
||||
expect(Logic.compatible_type?(champ_value(drop_down.stable_id), constant('a'))).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'priority' do
|
||||
|
|
Loading…
Reference in a new issue