Project

General

Profile

Bug #18540

Host#update_attribute(domain: ...) tests fail on Rails 5, model not saved

Added by Dominic Cleal over 5 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Tests
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

Tests that update a host's domain via update_attribute fail on Rails 5, e.g.

Failure:
DomainTest#test_0011_should update hosts_count on domain_id change [/home/dcleal/code/foreman/foreman/test/models/domain_test.rb:118]:
"@domain.hosts_count" didn't change by -1.
Expected: 0
  Actual: 1

The attribute isn't actually on Host::Managed, but the primary Nic via a delegation of #domain= to the primary_interface. Rails 5 has an optimisation in update_attribute that skips the #save when the model's not changed (https://github.com/rails/rails/commit/0fcd4cf) so the change doesn't trigger a save.

The tests should either call #domain= and #save themselves instead of using #update_attribute for this non-attribute, or change the domain attribute on the interface.

Associated revisions

Revision a61ecf63 (diff)
Added by Dominic Cleal over 5 years ago

fixes #18540 - update domain on primary in hosts_count tests

domain/domain_id are not attributes of the host itself, they're
delegated to the primary interface. When using update_attribute on the
host, the model doesn't appear `changed?` so Rails 5 skips the save.

The test "should update hosts_count" is left with delegation as the
direct interface modification is tested in the next test.

History

#1 Updated by The Foreman Bot over 5 years ago

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

#2 Updated by Dominic Cleal over 5 years ago

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

#3 Updated by Dominic Cleal over 5 years ago

  • Legacy Backlogs Release (now unused) set to 209

Also available in: Atom PDF