feat(type_de_champ): test value casts
This commit is contained in:
parent
aeb1d1c53a
commit
415be4f9ea
2 changed files with 63 additions and 1 deletions
|
@ -785,7 +785,7 @@ class TypeDeChamp < ApplicationRecord
|
||||||
when ['integer_number', 'decimal_number'], # recast numbers automatically
|
when ['integer_number', 'decimal_number'], # recast numbers automatically
|
||||||
['decimal_number', 'integer_number'], # may lose some data, but who cares ?
|
['decimal_number', 'integer_number'], # may lose some data, but who cares ?
|
||||||
['text', 'textarea'], # allow short text to long text
|
['text', 'textarea'], # allow short text to long text
|
||||||
# ['drop_down_list', 'multiple_drop_down_list'], # single list can become multi
|
['drop_down_list', 'multiple_drop_down_list'], # single list can become multi
|
||||||
['date', 'datetime'], # date <=> datetime
|
['date', 'datetime'], # date <=> datetime
|
||||||
['datetime', 'date'] # may lose some data, but who cares ?
|
['datetime', 'date'] # may lose some data, but who cares ?
|
||||||
true
|
true
|
||||||
|
|
|
@ -413,4 +413,66 @@ describe TypeDeChamp do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'champ_value with cast' do
|
||||||
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: type_champ }]) }
|
||||||
|
let(:dossier) { create(:dossier, procedure:) }
|
||||||
|
let(:type_champ) { :text }
|
||||||
|
let(:last_write_type_champ) { :text }
|
||||||
|
let(:champ_value) { 'hello' }
|
||||||
|
let(:champ_type) { TypeDeChamp.type_champ_to_champ_class_name(last_write_type_champ.to_s) }
|
||||||
|
let(:type_de_champ) { procedure.active_revision.types_de_champ.first }
|
||||||
|
let(:champ) { dossier.champs.first }
|
||||||
|
|
||||||
|
subject { champ.update_columns(type: champ_type, value: champ_value); type_de_champ.champ_value(champ) }
|
||||||
|
|
||||||
|
it { expect(subject).to eq('hello') }
|
||||||
|
|
||||||
|
context 'text -> integer_number' do
|
||||||
|
let(:last_write_type_champ) { :text }
|
||||||
|
let(:type_champ) { :integer_number }
|
||||||
|
|
||||||
|
it { expect(subject).to eq('') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'integer_number -> text' do
|
||||||
|
let(:last_write_type_champ) { :integer_number }
|
||||||
|
let(:type_champ) { :text }
|
||||||
|
let(:champ_value) { '42' }
|
||||||
|
|
||||||
|
it { expect(subject).to eq('') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'integer_number -> decimal_number' do
|
||||||
|
let(:last_write_type_champ) { :integer_number }
|
||||||
|
let(:type_champ) { :decimal_number }
|
||||||
|
let(:champ_value) { '42' }
|
||||||
|
|
||||||
|
it { expect(subject).to eq('42') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'decimal_number -> integer_number' do
|
||||||
|
let(:last_write_type_champ) { :decimal_number }
|
||||||
|
let(:type_champ) { :integer_number }
|
||||||
|
let(:champ_value) { '42.1' }
|
||||||
|
|
||||||
|
it { expect(subject).to eq('42.1') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'drop_down_list -> multiple_drop_down_list' do
|
||||||
|
let(:last_write_type_champ) { :drop_down_list }
|
||||||
|
let(:type_champ) { :multiple_drop_down_list }
|
||||||
|
let(:champ_value) { type_de_champ.drop_down_options.first }
|
||||||
|
|
||||||
|
it { expect(subject).to eq(champ_value) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'multiple_drop_down_list -> drop_down_list' do
|
||||||
|
let(:last_write_type_champ) { :multiple_drop_down_list }
|
||||||
|
let(:type_champ) { :drop_down_list }
|
||||||
|
let(:champ_value) { "[\"#{type_de_champ.drop_down_options.first}\"]" }
|
||||||
|
|
||||||
|
it { expect(subject).to eq('') }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue