diff --git a/app/models/champs.rb b/app/models/champs.rb new file mode 100644 index 000000000..aa9cd6068 --- /dev/null +++ b/app/models/champs.rb @@ -0,0 +1,6 @@ +class Champs < ActiveRecord::Base + belongs_to :dossier + belongs_to :type_de_champs + delegate :libelle, :type_champs, :order_place, to: :type_de_champs + +end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 406f9256c..340cd8fbe 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -11,6 +11,7 @@ class Dossier < ActiveRecord::Base has_one :entreprise, dependent: :destroy has_one :cerfa, dependent: :destroy has_many :pieces_justificatives, dependent: :destroy + has_many :champs, dependent: :destroy belongs_to :procedure belongs_to :user has_many :commentaires, dependent: :destroy diff --git a/app/models/piece_justificative.rb b/app/models/piece_justificative.rb index da16b0547..aaf3da7ba 100644 --- a/app/models/piece_justificative.rb +++ b/app/models/piece_justificative.rb @@ -5,7 +5,6 @@ class PieceJustificative < ActiveRecord::Base alias_attribute :type, :type_de_piece_justificative_id mount_uploader :content, PieceJustificativeUploader - def empty? content.blank? end diff --git a/app/models/type_de_champs.rb b/app/models/type_de_champs.rb index 679f78c61..9692f11f0 100644 --- a/app/models/type_de_champs.rb +++ b/app/models/type_de_champs.rb @@ -6,6 +6,7 @@ class TypeDeChamps < ActiveRecord::Base } belongs_to :procedure + has_many :champs validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :type_champs, presence: true, allow_blank: false, allow_nil: false diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index dcad59e52..99c88f5ee 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 'champs', 'champs' inflect.irregular 'type_de_champs', 'types_de_champs' end diff --git a/db/migrate/20151103091603_create_champs.rb b/db/migrate/20151103091603_create_champs.rb new file mode 100644 index 000000000..749c76249 --- /dev/null +++ b/db/migrate/20151103091603_create_champs.rb @@ -0,0 +1,9 @@ +class CreateChamps < ActiveRecord::Migration + def change + create_table :champs do |t| + t.string :value + end + add_reference :champs, :type_de_champs, references: :types_de_champs + add_reference :champs, :dossier, references: :dossiers + end +end diff --git a/db/schema.rb b/db/schema.rb index 36a1e8657..436e38073 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: 20151102163051) do +ActiveRecord::Schema.define(version: 20151103091603) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -41,6 +41,12 @@ ActiveRecord::Schema.define(version: 20151102163051) do add_index "cerfas", ["dossier_id"], name: "index_cerfas_on_dossier_id", using: :btree + create_table "champs", force: :cascade do |t| + t.string "value" + t.integer "type_de_champs_id" + t.integer "dossier_id" + end + create_table "commentaires", force: :cascade do |t| t.string "email" t.datetime "created_at", null: false diff --git a/spec/models/champs_spec.rb b/spec/models/champs_spec.rb new file mode 100644 index 000000000..9ca345173 --- /dev/null +++ b/spec/models/champs_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe Champs do + describe 'database columns' do + it { is_expected.to have_db_column(:value) } + end + + describe 'associations' do + it { is_expected.to belong_to(:dossier) } + it { is_expected.to belong_to(:type_de_champs) } + end + + describe 'delegation' do + it { is_expected.to delegate_method(:libelle).to(:type_de_champs) } + it { is_expected.to delegate_method(:type_champs).to(:type_de_champs) } + it { is_expected.to delegate_method(:order_place).to(:type_de_champs) } + end +end \ No newline at end of file diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 18a220857..b4cb7f310 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -16,6 +16,7 @@ describe Dossier do describe 'associations' do it { is_expected.to belong_to(:procedure) } it { is_expected.to have_many(:pieces_justificatives) } + it { is_expected.to have_many(:champs) } it { is_expected.to have_many(:commentaires) } it { is_expected.to have_one(:cerfa) } it { is_expected.to have_one(:etablissement) } diff --git a/spec/models/type_de_champs_spec.rb b/spec/models/type_de_champs_spec.rb index 4533c84eb..9885f29cc 100644 --- a/spec/models/type_de_champs_spec.rb +++ b/spec/models/type_de_champs_spec.rb @@ -10,6 +10,7 @@ describe TypeDeChamps do describe 'associations' do it { is_expected.to belong_to(:procedure) } + it { is_expected.to have_many(:champs) } end describe 'validation' do