Procedure: add parent_procedure
This commit is contained in:
parent
28ce027025
commit
9d0b568ef5
4 changed files with 17 additions and 2 deletions
|
@ -10,6 +10,7 @@ class Procedure < ApplicationRecord
|
|||
has_one :attestation_template, dependent: :destroy
|
||||
|
||||
belongs_to :administrateur
|
||||
belongs_to :parent_procedure, class_name: 'Procedure'
|
||||
|
||||
has_many :assign_to, dependent: :destroy
|
||||
has_many :administrateurs_procedures
|
||||
|
@ -128,6 +129,7 @@ class Procedure < ApplicationRecord
|
|||
procedure.without_continuation_mail = without_continuation_mail.try(:dup)
|
||||
|
||||
procedure.cloned_from_library = from_library
|
||||
procedure.parent_procedure = self
|
||||
|
||||
procedure
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddParentProcedureToProcedures < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_reference :procedures, :parent_procedure, foreign_key: { to_table: :procedures }
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_04_11_152844) do
|
||||
ActiveRecord::Schema.define(version: 2018_04_24_130548) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -463,7 +463,9 @@ ActiveRecord::Schema.define(version: 2018_04_11_152844) do
|
|||
t.boolean "ask_birthday", default: false, null: false
|
||||
t.string "web_hook_url"
|
||||
t.boolean "cloned_from_library", default: false
|
||||
t.bigint "parent_procedure_id"
|
||||
t.index ["hidden_at"], name: "index_procedures_on_hidden_at"
|
||||
t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id"
|
||||
end
|
||||
|
||||
create_table "quartier_prioritaires", id: :serial, force: :cascade do |t|
|
||||
|
@ -572,6 +574,7 @@ ActiveRecord::Schema.define(version: 2018_04_11_152844) do
|
|||
add_foreign_key "procedure_paths", "administrateurs"
|
||||
add_foreign_key "procedure_paths", "procedures"
|
||||
add_foreign_key "procedure_presentations", "assign_tos"
|
||||
add_foreign_key "procedures", "procedures", column: "parent_procedure_id"
|
||||
add_foreign_key "received_mails", "procedures"
|
||||
add_foreign_key "refused_mails", "procedures"
|
||||
add_foreign_key "without_continuation_mails", "procedures"
|
||||
|
|
|
@ -289,9 +289,10 @@ describe Procedure do
|
|||
|
||||
subject { @procedure }
|
||||
|
||||
it { expect(subject.parent_procedure).to eq(procedure) }
|
||||
|
||||
it 'should duplicate specific objects with different id' do
|
||||
expect(subject.id).not_to eq(procedure.id)
|
||||
expect(subject).to have_same_attributes_as(procedure)
|
||||
expect(subject.module_api_carto).to have_same_attributes_as(procedure.module_api_carto)
|
||||
|
||||
expect(subject.types_de_piece_justificative.size).to eq procedure.types_de_piece_justificative.size
|
||||
|
@ -315,6 +316,10 @@ describe Procedure do
|
|||
expect(subject.attestation_template.title).to eq(procedure.attestation_template.title)
|
||||
|
||||
expect(subject.cloned_from_library).to be(false)
|
||||
|
||||
cloned_procedure = subject
|
||||
cloned_procedure.parent_procedure_id = nil
|
||||
expect(cloned_procedure).to have_same_attributes_as(procedure)
|
||||
end
|
||||
|
||||
context 'when the procedure is clone from the library' do
|
||||
|
|
Loading…
Reference in a new issue