diff --git a/app/models/procedure.rb b/app/models/procedure.rb index e8dc6eb6a..099f25479 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -1,5 +1,6 @@ class Procedure < ActiveRecord::Base has_many :types_de_piece_justificative + has_many :types_de_champs has_many :dossiers belongs_to :evenement_vie diff --git a/app/models/type_de_champs.rb b/app/models/type_de_champs.rb new file mode 100644 index 000000000..8b59c5d82 --- /dev/null +++ b/app/models/type_de_champs.rb @@ -0,0 +1,13 @@ +class TypeDeChamps < ActiveRecord::Base + enum type: {text: 'text', + textarea: 'textarea', + datetime: 'datetime', + number: 'number' + } + + belongs_to :procedure + + validates :libelle, presence: true, allow_blank: false, allow_nil: false + validates :type, presence: true, allow_blank: false, allow_nil: false + validates :order_place, presence: true, allow_blank: false, allow_nil: false +end \ No newline at end of file diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 8bf6a1eeb..dcad59e52 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -11,6 +11,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym 'API' inflect.irregular 'piece_justificative', 'pieces_justificatives' inflect.irregular 'type_de_piece_justificative', 'types_de_piece_justificative' + inflect.irregular 'type_de_champs', 'types_de_champs' end # These inflection rules are supported but not enabled by default: diff --git a/db/migrate/20151026155158_create_types_de_champs.rb b/db/migrate/20151026155158_create_types_de_champs.rb new file mode 100644 index 000000000..a3ca08c1a --- /dev/null +++ b/db/migrate/20151026155158_create_types_de_champs.rb @@ -0,0 +1,11 @@ +class CreateTypesDeChamps < ActiveRecord::Migration + def change + create_table :types_de_champs do |t| + t.string :libelle + t.string :type + t.integer :order_place + + t.belongs_to :procedure + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 238f3a38d..3859754fd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151023132121) do +ActiveRecord::Schema.define(version: 20151026155158) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -142,6 +142,13 @@ ActiveRecord::Schema.define(version: 20151023132121) do t.boolean "use_api_carto", default: false end + create_table "types_de_champs", force: :cascade do |t| + t.string "libelle" + t.string "type" + t.integer "order_place" + t.integer "procedure_id" + end + create_table "types_de_piece_justificative", force: :cascade do |t| t.string "libelle" t.string "description" diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 5f05ec267..b076e7f7e 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe Procedure do describe 'assocations' do it { is_expected.to have_many(:types_de_piece_justificative) } + it { is_expected.to have_many(:types_de_champs) } it { is_expected.to have_many(:dossiers) } end diff --git a/spec/models/type_de_champs_spec.rb b/spec/models/type_de_champs_spec.rb new file mode 100644 index 000000000..15f4f766b --- /dev/null +++ b/spec/models/type_de_champs_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe TypeDeChamps do + describe 'database columns' do + it { is_expected.to have_db_column(:libelle) } + it { is_expected.to have_db_column(:type) } + it { is_expected.to have_db_column(:order_place) } + end + + describe 'associations' do + it { is_expected.to belong_to(:procedure) } + end + + describe 'validation' do + context 'libelle' do + it { is_expected.not_to allow_value(nil).for(:libelle) } + it { is_expected.not_to allow_value('').for(:libelle) } + it { is_expected.to allow_value('Montant projet').for(:libelle) } + end + + context 'type' do + it { is_expected.not_to allow_value(nil).for(:type) } + it { is_expected.not_to allow_value('').for(:type) } + + it { is_expected.to allow_value('text').for(:type) } + it { is_expected.to allow_value('textarea').for(:type) } + it { is_expected.to allow_value('datetime').for(:type) } + it { is_expected.to allow_value('number').for(:type) } + end + + context 'order_place' do + it { is_expected.not_to allow_value(nil).for(:order_place) } + it { is_expected.not_to allow_value('').for(:order_place) } + it { is_expected.to allow_value(1).for(:order_place) } + end + end +end