Create TypeDeChamps

This commit is contained in:
Xavier J 2015-10-26 17:35:02 +01:00
parent d75ed802d2
commit 9392f1d6e3
7 changed files with 72 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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