Skip to content

test preload passing an array #23402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spec/lib/miq_preloader_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
RSpec.describe MiqPreloader do
# implied vms (simple association)
let(:ems) { FactoryBot.create(:ems_infra).tap { |ems| FactoryBot.create_list(:vm, 2, :ext_management_system => ems) } }
let(:zone) { FactoryBot.create(:zone) }

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

it "preloads association array" do
host = FactoryBot.create(:host_vmware) # infra
FactoryBot.create_list(:vm, 2, :ext_management_system => FactoryBot.create(:ems_infra, :zone => zone), :host => host)
emses = ExtManagementSystem.all

# 4: ems, zones, vms, hosts
expect { preload(emses, [:zone, :vms => :host]) }.to make_database_queries(:count => 4)

expect { expect(emses.first.vms.size).to eq(2) }.not_to make_database_queries
expect { expect(emses.first.vms.first.host).to eq(host) }.not_to make_database_queries
expect { expect(emses.first.zone).to eq(zone) }.not_to make_database_queries
end

def preload(*args, **kwargs)
MiqPreloader.preload(*args, **kwargs)
end
Expand Down
Loading