From ede01b024b32c95e41cd4bca5347ddd2614d51fc Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Wed, 23 Sep 2015 12:16:21 +0200 Subject: [PATCH] [#888] link user to dossier --- app/models/dossier.rb | 1 + app/models/user.rb | 2 ++ db/migrate/20150923101000_add_user_to_dossier.rb | 6 ++++++ db/schema.rb | 9 ++++++--- spec/models/dossier_spec.rb | 1 + spec/models/user_spec.rb | 3 +++ 6 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20150923101000_add_user_to_dossier.rb diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 7c4e1ee1a..dda6f3988 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -12,6 +12,7 @@ class Dossier < ActiveRecord::Base has_one :cerfa has_many :pieces_justificatives belongs_to :procedure + belongs_to :user has_many :commentaires delegate :siren, to: :entreprise diff --git a/app/models/user.rb b/app/models/user.rb index c8220270d..802edb08c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,4 +3,6 @@ class User < ActiveRecord::Base # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable + + has_many :dossiers end diff --git a/db/migrate/20150923101000_add_user_to_dossier.rb b/db/migrate/20150923101000_add_user_to_dossier.rb new file mode 100644 index 000000000..0bf8685b4 --- /dev/null +++ b/db/migrate/20150923101000_add_user_to_dossier.rb @@ -0,0 +1,6 @@ +class AddUserToDossier < ActiveRecord::Migration + def change + add_reference :dossiers, :user, index: true + add_foreign_key :dossiers, :users + end +end diff --git a/db/schema.rb b/db/schema.rb index 2603b24dd..174c2e85a 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: 20150922141232) do +ActiveRecord::Schema.define(version: 20150923101000) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -44,12 +44,14 @@ ActiveRecord::Schema.define(version: 20150922141232) do t.string "montant_aide_demande" t.integer "procedure_id" t.date "date_previsionnelle" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", default: '2015-09-22 09:25:29' + t.datetime "updated_at", default: '2015-09-22 09:25:29' t.string "state" + t.integer "user_id" end add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree + add_index "dossiers", ["user_id"], name: "index_dossiers_on_user_id", using: :btree create_table "entreprises", force: :cascade do |t| t.string "siren" @@ -150,4 +152,5 @@ ActiveRecord::Schema.define(version: 20150922141232) do add_foreign_key "cerfas", "dossiers" add_foreign_key "commentaires", "dossiers" + add_foreign_key "dossiers", "users" end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 7814c87ff..13e5274af 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -21,6 +21,7 @@ describe Dossier do it { is_expected.to have_one(:cerfa) } it { is_expected.to have_one(:etablissement) } it { is_expected.to have_one(:entreprise) } + it { is_expected.to belong_to(:user) } end describe 'delegation' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 13fafe562..ca38b1986 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -15,4 +15,7 @@ describe User, type: :model do it { is_expected.to have_db_column(:created_at) } it { is_expected.to have_db_column(:updated_at) } end + describe 'associations' do + it { is_expected.to have_many(:dossiers) } + end end