parent
9062e76942
commit
f33544f067
3 changed files with 33 additions and 1 deletions
|
@ -416,6 +416,7 @@ class Procedure < ApplicationRecord
|
|||
procedure.save
|
||||
procedure.draft_types_de_champ.update_all(revision_id: procedure.draft_revision.id)
|
||||
procedure.draft_types_de_champ_private.update_all(revision_id: procedure.draft_revision.id)
|
||||
TypeDeChamp.where(parent: procedure.draft_types_de_champ.repetition + procedure.draft_types_de_champ_private.repetition).update_all(revision_id: procedure.draft_revision.id)
|
||||
|
||||
if is_different_admin || from_library
|
||||
procedure.draft_types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) }
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: fix_types_de_champ_revisions'
|
||||
task fix_types_de_champ_revisions: :environment do
|
||||
puts "Running deploy task 'fix_types_de_champ_revisions'"
|
||||
|
||||
types_de_champ = TypeDeChamp.joins(:parent).where('types_de_champ.revision_id != parents_types_de_champ.revision_id')
|
||||
progress = ProgressReport.new(types_de_champ.count)
|
||||
types_de_champ.find_each do |type_de_champ|
|
||||
type_de_champ.update_column(:revision_id, type_de_champ.parent.revision_id)
|
||||
progress.inc
|
||||
end
|
||||
progress.finish
|
||||
|
||||
# Update task as completed. If you remove the line below, the task will
|
||||
# run with every deploy (or every time you call after_party:run).
|
||||
AfterParty::TaskRecord
|
||||
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||
end
|
||||
end
|
|
@ -325,14 +325,16 @@ describe Procedure do
|
|||
|
||||
describe 'clone' do
|
||||
let(:service) { create(:service) }
|
||||
let(:procedure) { create(:procedure, received_mail: received_mail, service: service, types_de_champ: [type_de_champ_0, type_de_champ_1, type_de_champ_2, type_de_champ_pj], types_de_champ_private: [type_de_champ_private_0, type_de_champ_private_1, type_de_champ_private_2]) }
|
||||
let(:procedure) { create(:procedure, received_mail: received_mail, service: service, types_de_champ: [type_de_champ_0, type_de_champ_1, type_de_champ_2, type_de_champ_pj, type_de_champ_repetition], types_de_champ_private: [type_de_champ_private_0, type_de_champ_private_1, type_de_champ_private_2, type_de_champ_private_repetition]) }
|
||||
let(:type_de_champ_0) { build(:type_de_champ, position: 0) }
|
||||
let(:type_de_champ_1) { build(:type_de_champ, position: 1) }
|
||||
let(:type_de_champ_2) { build(:type_de_champ_drop_down_list, position: 2) }
|
||||
let(:type_de_champ_pj) { build(:type_de_champ_piece_justificative, position: 3, old_pj: { stable_id: 2713 }) }
|
||||
let(:type_de_champ_repetition) { build(:type_de_champ_repetition, position: 4, types_de_champ: [build(:type_de_champ)]) }
|
||||
let(:type_de_champ_private_0) { build(:type_de_champ, :private, position: 0) }
|
||||
let(:type_de_champ_private_1) { build(:type_de_champ, :private, position: 1) }
|
||||
let(:type_de_champ_private_2) { build(:type_de_champ_drop_down_list, :private, position: 2) }
|
||||
let(:type_de_champ_private_repetition) { build(:type_de_champ_repetition, :private, position: 3, types_de_champ: [build(:type_de_champ, :private)]) }
|
||||
let(:received_mail) { build(:received_mail) }
|
||||
let(:from_library) { false }
|
||||
let(:administrateur) { procedure.administrateurs.first }
|
||||
|
@ -378,11 +380,21 @@ describe Procedure do
|
|||
expect(stc.revision).to eq(subject.draft_revision)
|
||||
end
|
||||
|
||||
TypeDeChamp.where(parent: procedure.draft_types_de_champ.repetition).zip(TypeDeChamp.where(parent: subject.draft_types_de_champ.repetition)).each do |ptc, stc|
|
||||
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id", "parent_id"])
|
||||
expect(stc.revision).to eq(subject.draft_revision)
|
||||
end
|
||||
|
||||
procedure.draft_types_de_champ_private.zip(subject.draft_types_de_champ_private).each do |ptc, stc|
|
||||
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id"])
|
||||
expect(stc.revision).to eq(subject.draft_revision)
|
||||
end
|
||||
|
||||
TypeDeChamp.where(parent: procedure.draft_types_de_champ_private.repetition).zip(TypeDeChamp.where(parent: subject.draft_types_de_champ_private.repetition)).each do |ptc, stc|
|
||||
expect(stc).to have_same_attributes_as(ptc, except: ["revision_id", "parent_id"])
|
||||
expect(stc.revision).to eq(subject.draft_revision)
|
||||
end
|
||||
|
||||
expect(subject.attestation_template.title).to eq(procedure.attestation_template.title)
|
||||
|
||||
expect(subject.cloned_from_library).to be(false)
|
||||
|
|
Loading…
Reference in a new issue