Cleanup after clone

This commit is contained in:
Paul Chavard 2020-07-28 16:39:32 +02:00
parent 7301b202aa
commit 1fca481c6e
2 changed files with 7 additions and 2 deletions

View file

@ -299,6 +299,7 @@ class Procedure < ApplicationRecord
procedure.unpublished_at = nil procedure.unpublished_at = nil
procedure.published_at = nil procedure.published_at = nil
procedure.lien_notice = nil procedure.lien_notice = nil
procedure.published_revision = nil
procedure.draft_revision.procedure = procedure procedure.draft_revision.procedure = procedure
if is_different_admin if is_different_admin
@ -326,6 +327,8 @@ class Procedure < ApplicationRecord
end end
procedure.save procedure.save
procedure.draft_revision.types_de_champ.update_all(revision_id: procedure.draft_revision.id)
procedure.draft_revision.types_de_champ_private.update_all(revision_id: procedure.draft_revision.id)
# FIXUP: needed during transition to revisions # FIXUP: needed during transition to revisions
procedure.draft_revision.types_de_champ.each do |type_de_champ| procedure.draft_revision.types_de_champ.each do |type_de_champ|

View file

@ -387,14 +387,16 @@ describe Procedure do
expect(subject.draft_revision.types_de_champ_private.size).to eq(procedure.draft_revision.types_de_champ_private.size) expect(subject.draft_revision.types_de_champ_private.size).to eq(procedure.draft_revision.types_de_champ_private.size)
procedure.types_de_champ.zip(subject.types_de_champ).each do |ptc, stc| procedure.types_de_champ.zip(subject.types_de_champ).each do |ptc, stc|
expect(stc).to have_same_attributes_as(ptc) expect(stc).to have_same_attributes_as(ptc, except: ["revision_id"])
expect(stc.revision).to eq(subject.draft_revision)
end end
procedure.types_de_champ.zip(procedure.draft_revision.types_de_champ).each do |ptc, rtc| procedure.types_de_champ.zip(procedure.draft_revision.types_de_champ).each do |ptc, rtc|
expect(ptc).to eq(rtc) expect(ptc).to eq(rtc)
end end
subject.types_de_champ_private.zip(procedure.types_de_champ_private).each do |stc, ptc| subject.types_de_champ_private.zip(procedure.types_de_champ_private).each do |stc, ptc|
expect(stc).to have_same_attributes_as(ptc) expect(stc).to have_same_attributes_as(ptc, except: ["revision_id"])
expect(stc.revision).to eq(subject.draft_revision)
end end
procedure.types_de_champ_private.zip(procedure.draft_revision.types_de_champ_private).each do |ptc, rtc| procedure.types_de_champ_private.zip(procedure.draft_revision.types_de_champ_private).each do |ptc, rtc|
expect(ptc).to eq(rtc) expect(ptc).to eq(rtc)