tdc can have condition
This commit is contained in:
parent
9f49e8c2ea
commit
758933f6f9
4 changed files with 35 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
# Table name: types_de_champ
|
# Table name: types_de_champ
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
|
# condition :jsonb
|
||||||
# description :text
|
# description :text
|
||||||
# libelle :string
|
# libelle :string
|
||||||
# mandatory :boolean default(FALSE)
|
# mandatory :boolean default(FALSE)
|
||||||
|
@ -77,6 +78,22 @@ class TypeDeChamp < ApplicationRecord
|
||||||
|
|
||||||
serialize :options, WithIndifferentAccess
|
serialize :options, WithIndifferentAccess
|
||||||
|
|
||||||
|
class ConditionSerializer
|
||||||
|
def self.load(condition)
|
||||||
|
if condition.present?
|
||||||
|
Logic.from_h(condition)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.dump(condition)
|
||||||
|
if condition.present?
|
||||||
|
condition.to_h
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
serialize :condition, ConditionSerializer
|
||||||
|
|
||||||
after_initialize :set_dynamic_type
|
after_initialize :set_dynamic_type
|
||||||
after_create :populate_stable_id
|
after_create :populate_stable_id
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddConditionColumnToTypeDeChamp < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :types_de_champ, :condition, :jsonb
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2022_05_20_173939) do
|
ActiveRecord::Schema.define(version: 2022_05_31_100040) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pgcrypto"
|
enable_extension "pgcrypto"
|
||||||
|
@ -787,6 +787,7 @@ ActiveRecord::Schema.define(version: 2022_05_20_173939) do
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "types_de_champ", id: :serial, force: :cascade do |t|
|
create_table "types_de_champ", id: :serial, force: :cascade do |t|
|
||||||
|
t.jsonb "condition"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.text "description"
|
t.text "description"
|
||||||
t.string "libelle"
|
t.string "libelle"
|
||||||
|
|
|
@ -11,4 +11,15 @@ describe TypeDeChamp do
|
||||||
expect(procedure.types_de_champ_private.count).to eq(1)
|
expect(procedure.types_de_champ_private.count).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'condition' do
|
||||||
|
let(:type_de_champ) { create(:type_de_champ) }
|
||||||
|
let(:condition) { Logic::Eq.new(Logic::Constant.new(true), Logic::Constant.new(true)) }
|
||||||
|
|
||||||
|
it 'saves and reload the condition' do
|
||||||
|
type_de_champ.update(condition: condition)
|
||||||
|
type_de_champ.reload
|
||||||
|
expect(type_de_champ.condition).to eq(condition)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue