Skip to content

Commit

Permalink
fix all_host_ids reference
Browse files Browse the repository at this point in the history
introduced in:
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 #<EmsCluster:0x000055e3fd7fb930>
       Did you mean?  all_relationship_ids
```
  • Loading branch information
kbrock committed May 26, 2020
1 parent cf75130 commit 2e27701
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/ems_cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
41 changes: 41 additions & 0 deletions spec/models/ems_cluster_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2e27701

Please sign in to comment.