Procedure and expert link

This commit is contained in:
simon lehericey 2021-01-07 15:45:02 +01:00 committed by kara Diaby
parent 29e9f2dd32
commit d409a9a6c5
5 changed files with 59 additions and 1 deletions

View file

@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: experts_procedures
#
# id :bigint not null, primary key
# allow_decision_access :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
# expert_id :bigint not null
# procedure_id :bigint not null
#
class ExpertsProcedure < ApplicationRecord
belongs_to :expert
belongs_to :procedure
validates :expert, uniqueness: { scope: :procedure }
end

View file

@ -70,6 +70,9 @@ class Procedure < ApplicationRecord
has_many :all_types_de_champ, -> { joins(:procedure).where('types_de_champ.revision_id != procedures.draft_revision_id').ordered }, through: :revisions, source: :types_de_champ
has_many :all_types_de_champ_private, -> { joins(:procedure).where('types_de_champ.revision_id != procedures.draft_revision_id').ordered }, through: :revisions, source: :types_de_champ_private
has_many :experts_procedures, dependent: :destroy
has_many :experts, through: :experts_procedures
has_one :module_api_carto, dependent: :destroy
has_one :attestation_template, dependent: :destroy

View file

@ -0,0 +1,11 @@
class CreateExpertsProcedures < ActiveRecord::Migration[6.0]
def change
create_table :experts_procedures do |t|
t.references :expert, null: false, foreign_key: true
t.references :procedure, null: false, foreign_key: true
t.boolean :allow_decision_access, default: false, null: false
t.timestamps
end
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_01_07_143938) do
ActiveRecord::Schema.define(version: 2021_01_13_150013) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -326,6 +326,16 @@ ActiveRecord::Schema.define(version: 2021_01_07_143938) do
t.datetime "updated_at", precision: 6, null: false
end
create_table "experts_procedures", force: :cascade do |t|
t.bigint "expert_id", null: false
t.bigint "procedure_id", null: false
t.boolean "allow_decision_access", default: false, null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["expert_id"], name: "index_experts_procedures_on_expert_id"
t.index ["procedure_id"], name: "index_experts_procedures_on_procedure_id"
end
create_table "exports", force: :cascade do |t|
t.string "format", null: false
t.datetime "created_at", null: false
@ -722,6 +732,8 @@ ActiveRecord::Schema.define(version: 2021_01_07_143938) do
add_foreign_key "dossiers", "groupe_instructeurs"
add_foreign_key "dossiers", "procedure_revisions", column: "revision_id"
add_foreign_key "dossiers", "users"
add_foreign_key "experts_procedures", "experts"
add_foreign_key "experts_procedures", "procedures"
add_foreign_key "feedbacks", "users"
add_foreign_key "geo_areas", "champs"
add_foreign_key "groupe_instructeurs", "procedures"

View file

@ -0,0 +1,16 @@
require 'rails_helper'
RSpec.describe Expert, type: :model do
describe 'an expert could be add to a procedure' do
let(:procedure) { create(:procedure) }
let(:expert) { Expert.create }
before do
procedure.experts << expert
procedure.reload
end
it { expect(procedure.experts).to eq([expert]) }
end
end