Skip to content

Commit fd8a72f

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

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

spec/lib/miq_preloader_spec.rb

+12
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,17 @@
100101
expect { expect(nodes.first.container_images).to eq([image]) }.to make_database_queries(:count => 1)
101102
end
102103

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

0 commit comments

Comments
 (0)