Project

General

Profile

« Previous | Next » 

Revision a61ecf63

Added by Dominic Cleal over 7 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.

View differences:

test/controllers/hosts_controller_test.rb
setup_user_and_host "view", "domain_id = #{domains(:mydomain).id}"
as_admin do
@host1.update_attribute(:domain, domains(:mydomain))
@host2.update_attribute(:domain, domains(:yourdomain))
@host1.primary_interface.update_attribute(:domain, domains(:mydomain))
@host2.primary_interface.update_attribute(:domain, domains(:yourdomain))
end
get :index, {}, set_session_user.merge(:user => @one.id)
test/models/domain_test.rb
test "should update hosts_count" do
assert_difference "@domain.hosts_count" do
FactoryGirl.create(:host).update_attribute(:domain, @domain)
h = FactoryGirl.create(:host)
h.domain = @domain
h.save!
@domain.reload
end
end
......
test "should update hosts_count on domain_id change" do
host = FactoryGirl.create(:host, :managed, :domain => @domain)
assert_difference "@domain.hosts_count", -1 do
host.update_attribute(:domain_id, FactoryGirl.create(:domain).id)
host.primary_interface.update_attribute(:domain_id, FactoryGirl.create(:domain).id)
@domain.reload
end
end

Also available in: Unified diff