models: fix touch not propagating when using nested attributes

Sometimes, when using nested attributes, touch doesn’t propagate to
parent relationships. (see https://github.com/rails/rails/issues/26726)

Specifically, this happens in our app when updating a dossier with
only new attachements (but without changing the value of any fields).

To work around this, we need to define the parent relationship
explicitely. This is good practice anyway.

Fix #3906
This commit is contained in:
Pierre de La Morinerie 2019-05-29 16:28:27 +00:00
parent 52d672486e
commit 51aacabf13
7 changed files with 57 additions and 12 deletions

View file

@ -127,6 +127,14 @@ FactoryBot.define do
end
end
trait :with_piece_justificative do
after(:build) do |procedure, _evaluator|
type_de_champ = create(:type_de_champ_piece_justificative)
procedure.types_de_champ << type_de_champ
end
end
# Deprecated
trait :with_two_type_de_piece_justificative do
after(:build) do |procedure, _evaluator|
rib = create(:type_de_piece_justificative, :rib, order_place: 1)