UserMailNotification records are not set up properly when a mail notification is added.
|Assigned To:||Shimon Shtein|
|Target version:||Team Ivan Iteration 15|
|Found in release:||Pull request:||https://github.com/theforeman/foreman/pull/4531|
|Velocity based estimate||-|
When assigning one-to-many associations we should use after(:create) hook to add those associations properly.
#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.
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.