Merge pull request #9361 from colinux/fix-fork-having-associated-invalid
Usager: fix modif en construction lorsqu'un objet associé (geo area…) n'est pas valide
This commit is contained in:
commit
e24672e71f
2 changed files with 21 additions and 1 deletions
|
@ -246,7 +246,7 @@ class Champ < ApplicationRecord
|
||||||
value_attributes = fork || !private? ? [:value, :value_json, :data, :external_id] : []
|
value_attributes = fork || !private? ? [:value, :value_json, :data, :external_id] : []
|
||||||
relationships = fork || !private? ? [:etablissement, :geo_areas] : []
|
relationships = fork || !private? ? [:etablissement, :geo_areas] : []
|
||||||
|
|
||||||
deep_clone(only: champ_attributes + value_attributes, include: relationships) do |original, kopy|
|
deep_clone(only: champ_attributes + value_attributes, include: relationships, validate: !fork) do |original, kopy|
|
||||||
PiecesJustificativesService.clone_attachments(original, kopy)
|
PiecesJustificativesService.clone_attachments(original, kopy)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -207,6 +207,26 @@ RSpec.describe DossierCloneConcern do
|
||||||
|
|
||||||
# rubocop:enable Lint/BooleanSymbol
|
# rubocop:enable Lint/BooleanSymbol
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when associated record is invalid' do
|
||||||
|
let(:procedure) do
|
||||||
|
create(:procedure, types_de_champ_public: [
|
||||||
|
{ type: :carte, libelle: "Carte", stable_id: 992, mandatory: true }
|
||||||
|
])
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
champ = dossier.champs.find { _1.stable_id == 992 }
|
||||||
|
geo_area = build(:geo_area, champ:, geometry: { "i'm" => "invalid" })
|
||||||
|
geo_area.save!(validate: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'can still fork' do
|
||||||
|
new_dossier.champs.load # load relation so champs are validated below
|
||||||
|
|
||||||
|
expect(new_dossier.champs.find { _1.stable_id == 992 }.geo_areas.first).not_to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue