Skip to content

Commit 490d781

Browse files
committed
test preload passing an array
1 parent 13080b7 commit 490d781

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spec/lib/miq_preloader_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
RSpec.describe MiqPreloader do
22
# implied vms (simple association)
33
let(:ems) { FactoryBot.create(:ems_infra).tap { |ems| FactoryBot.create_list(:vm, 2, :ext_management_system => ems) } }
4+
let(:zone) { FactoryBot.create(:zone) }
45

56
# implied container_nodes (through association)
67
let(:image) do
@@ -100,6 +101,19 @@
100101
expect { expect(nodes.first.container_images).to eq([image]) }.to make_database_queries(:count => 1)
101102
end
102103

104+
it "preloads association array" do
105+
host = FactoryBot.create(:host_vmware) # infra
106+
FactoryBot.create_list(:vm, 2, :ext_management_system => FactoryBot.create(:ems_infra, :zone => zone), :host => host)
107+
emses = ExtManagementSystem.all
108+
109+
# 4: ems, zones, vms, hosts
110+
expect { preload(emses, [:zone, :vms => :host]) }.to make_database_queries(:count => 4)
111+
112+
expect { expect(emses.first.vms.size).to eq(2) }.not_to make_database_queries
113+
expect { expect(emses.first.host).to eq(host) }.not_to make_database_queries
114+
expect { expect(emses.first.zone).to eq(zone) }.not_to make_database_queries
115+
end
116+
103117
def preload(*args, **kwargs)
104118
MiqPreloader.preload(*args, **kwargs)
105119
end

0 commit comments

Comments
 (0)