Add ProcedurePresentation

This commit is contained in:
gregoirenovel 2017-10-02 17:03:30 +02:00
parent 905d59da0c
commit 7036f9778b
5 changed files with 44 additions and 1 deletions

View file

@ -1,4 +1,9 @@
class AssignTo < ActiveRecord::Base
belongs_to :procedure
belongs_to :gestionnaire
has_one :procedure_presentation, dependent: :destroy
def procedure_presentation_or_default
self.procedure_presentation || build_procedure_presentation
end
end

View file

@ -0,0 +1,3 @@
class ProcedurePresentation < ActiveRecord::Base
belongs_to :assign_to
end

View file

@ -0,0 +1,10 @@
class CreateProcedurePresentations < ActiveRecord::Migration[5.0]
def change
create_table :procedure_presentations do |t|
t.references :assign_to, index: { unique: true }, foreign_key: true
t.text :displayed_fields, array: true, default: [{ "label" => "Demandeur", "table" => "user", "column" => "email" }.to_json], null: false
t.json :sort, default: { "table" => "self", "column" => "id", "order" => "desc" }.to_json, null: false
t.json :filters, default: { "a-suivre" => [], "suivis" => [], "traites" => [], "tous" => [], "archives" => [] }.to_json, null: false
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: 20170926092716) do
ActiveRecord::Schema.define(version: 20170927092716) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -382,6 +382,14 @@ ActiveRecord::Schema.define(version: 20170926092716) do
t.index ["path"], name: "index_procedure_paths_on_path", using: :btree
end
create_table "procedure_presentations", force: :cascade do |t|
t.integer "assign_to_id"
t.text "displayed_fields", default: ["{\"label\":\"Demandeur\",\"table\":\"user\",\"column\":\"email\"}"], null: false, array: true
t.json "sort", default: "{\"table\":\"self\",\"column\":\"id\",\"order\":\"desc\"}", null: false
t.json "filters", default: "{\"a-suivre\":[],\"suivis\":[],\"traites\":[],\"tous\":[],\"archives\":[]}", null: false
t.index ["assign_to_id"], name: "index_procedure_presentations_on_assign_to_id", unique: true, using: :btree
end
create_table "procedures", force: :cascade do |t|
t.string "libelle"
t.string "description"
@ -503,6 +511,7 @@ ActiveRecord::Schema.define(version: 20170926092716) do
add_foreign_key "initiated_mails", "procedures"
add_foreign_key "procedure_paths", "administrateurs"
add_foreign_key "procedure_paths", "procedures"
add_foreign_key "procedure_presentations", "assign_tos"
add_foreign_key "received_mails", "procedures"
add_foreign_key "refused_mails", "procedures"
add_foreign_key "without_continuation_mails", "procedures"

View file

@ -0,0 +1,16 @@
describe AssignTo, type: :model do
describe '#procedure_presentation_or_default' do
context "without a procedure_presentation" do
let!(:assign_to) { AssignTo.create }
it { expect(assign_to.procedure_presentation_or_default.persisted?).to be_falsey }
end
context "with a procedure_presentation" do
let!(:assign_to) { AssignTo.create }
let!(:procedure_presentation) { ProcedurePresentation.create(assign_to: assign_to) }
it { expect(assign_to.procedure_presentation_or_default).to eq(procedure_presentation) }
end
end
end