From 2e277013a8cb5501cbeb192ccb0b30d7d4ec619f Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Tue, 26 May 2020 11:02:09 -0400 Subject: [PATCH] fix all_host_ids reference introduced in: ManageIQ/manageiq#20149 ``` 1) EmsClusterController#show render listnav partial correctly for timeline page Failure/Error: sdate, edate = @tl_record.first_and_last_event(@tl_options.evt_type) NameError: undefined local variable or method `all_host_ids' for # Did you mean? all_relationship_ids ``` --- app/models/ems_cluster.rb | 4 ++-- spec/models/ems_cluster_spec.rb | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/models/ems_cluster.rb b/app/models/ems_cluster.rb index b923aa7d8d9..e7df1d2128b 100644 --- a/app/models/ems_cluster.rb +++ b/app/models/ems_cluster.rb @@ -190,13 +190,13 @@ def event_where_clause(assoc = :ems_events) cond = ["ems_cluster_id = ?"] cond_params = [id] - ids = all_host_ids + ids = host_ids unless ids.empty? cond << "host_id IN (?) OR dest_host_id IN (?)" cond_params += [ids, ids] end - ids = all_vm_or_template_ids + ids = vm_or_template_ids unless ids.empty? cond << "vm_or_template_id IN (?) OR dest_vm_or_template_id IN (?)" cond_params += [ids, ids] diff --git a/spec/models/ems_cluster_spec.rb b/spec/models/ems_cluster_spec.rb index e02bbcbf7bd..9244b16c999 100644 --- a/spec/models/ems_cluster_spec.rb +++ b/spec/models/ems_cluster_spec.rb @@ -250,4 +250,45 @@ end end end + + describe "#event_where_clause" do + let(:cluster) { FactoryBot.create(:ems_cluster) } + # just doing one to avoid db random ordering + let(:vms) { FactoryBot.create_list(:vm, 1, :ems_cluster => cluster)} + let(:hosts) { FactoryBot.create_list(:host, 1, :ems_cluster => cluster)} + it "handles empty cluster" do + expect(cluster.event_where_clause).to eq(["ems_cluster_id = ?", cluster.id]) + end + + it "handles vms" do + vms # pre-load vms + result = cluster.event_where_clause + expected = [ + "ems_cluster_id = ? OR vm_or_template_id IN (?) OR dest_vm_or_template_id IN (?)", + cluster.id, vms.map(&:id), vms.map(&:id) + ] + expect(result).to eq(expected) + end + + it "handles hosts" do + hosts # pre-load vms + result = cluster.event_where_clause + expected = [ + "ems_cluster_id = ? OR host_id IN (?) OR dest_host_id IN (?)", + cluster.id, hosts.map(&:id), hosts.map(&:id) + ] + expect(result).to eq(expected) + end + + it "handles both" do + vms # pre-load vms, hosts + hosts + result = cluster.event_where_clause + expected = [ + "ems_cluster_id = ? OR host_id IN (?) OR dest_host_id IN (?) OR vm_or_template_id IN (?) OR dest_vm_or_template_id IN (?)", + cluster.id, hosts.map(&:id), hosts.map(&:id), vms.map(&:id), vms.map(&:id) + ] + expect(result).to eq(expected) + end + end end