diff --git a/app/models/manageiq/providers/infra_manager.rb b/app/models/manageiq/providers/infra_manager.rb index 5ed65ae051c..07b007351a6 100644 --- a/app/models/manageiq/providers/infra_manager.rb +++ b/app/models/manageiq/providers/infra_manager.rb @@ -32,6 +32,7 @@ class InfraManager < BaseManager has_many :networks, :through => :hardwares has_many :guest_devices, :through => :hardwares has_many :ems_custom_attributes, :through => :vms_and_templates + has_many :clusterless_hosts, -> { where(:ems_cluster =>nil) }, :class_name => "Host", :foreign_key => "ems_id", :inverse_of => :ext_management_system include HasManyOrchestrationStackMixin @@ -65,10 +66,6 @@ def self.ems_timeouts(type, service = nil) def validate_authentication_status {:available => true, :message => nil} end - - def clusterless_hosts - hosts.where(:ems_cluster => nil) - end end def self.display_name(number = 1) diff --git a/spec/models/manageiq/providers/infra_manager_spec.rb b/spec/models/manageiq/providers/infra_manager_spec.rb index 222d8e63a91..a2cdc1cb9d4 100644 --- a/spec/models/manageiq/providers/infra_manager_spec.rb +++ b/spec/models/manageiq/providers/infra_manager_spec.rb @@ -25,4 +25,14 @@ expect(described_class.ems_timeouts(:ems_redhat, :InVentory)).to eq [5.hours, nil] end end + + describe '.clusterless_hosts' do + it "hosts with no ems" do + ems = FactoryBot.create(:ems_infra) + host = FactoryBot.create(:host, :ext_management_system => ems) + FactoryBot.create(:host, :ext_management_system => ems, :ems_cluster => FactoryBot.create(:ems_cluster)) + + expect(ems.clusterless_hosts).to eq([host]) + end + end end