Bug #19541

UserMailNotification records are not set up properly when a mail notification is added.

Added by Shimon Shtein 5 months ago. Updated 4 months ago.

Status:Closed
Priority:Normal
Assigned To:Shimon Shtein
Category:Rails
Target version:Team Ivan Iteration 15
Difficulty: Bugzilla link:
Found in release: Pull request:https://github.com/theforeman/foreman/pull/4531
Story points-
Velocity based estimate-
Release1.16.0Release relationshipAuto

Description

When assigning one-to-many associations we should use after(:create) hook to add those associations properly.

Associated revisions

Revision 7b085199
Added by Shimon Shtein 5 months ago

Fixes #19541 - properly mark user <-> mail_notification relation

Mark `:inverse_of` on `User` and `UserMailNotification` objects
so the relation properties would be set automatically, even for
new in-memory instances.

History

#1 Updated by The Foreman Bot 5 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4531 added

#2 Updated by Ivan Necas 5 months ago

  • Target version set to Team Ivan Iteration 15

#3 Updated by Shimon Shtein 5 months ago

  • Subject changed from Fix user factory's :with_mail_notification trait to UserMailNotification records are not set up properly when a mail notification is added.

When using new in-memory objects, the association objects are not set up correctly without :inverse_of option.

to reproduce:

User.new(:login => 'zzz', :mail_notifications => [MailNotification.new]).user_mail_notifications.first.user

This statement will return nil, but should return a reference to the newly created user.
This happens due to the fact that inverse_of is not set.
After setting proper inverse_of, Active Record will point UserMailNotification#user property to the newly created user in this example.

#4 Updated by Dominic Cleal 5 months ago

  • Category set to Rails

#5 Updated by Shimon Shtein 5 months ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#6 Updated by Marek Hulán 4 months ago

  • Release set to 1.16.0

Also available in: Atom PDF