-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move miq_preloader_spec tree building logic to shared_context
This makes a new rspec shared_context that can be used to replicate the tree building functionality in the specs that test the method `MiqPreloader.polymorphic_preload_for_child_classes`. The same data can then be used in higher level abstraction tests to confirm the functionality works as expected there as well.
- Loading branch information
1 parent
2f971d5
commit 4980f77
Showing
2 changed files
with
73 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
spec/support/examples_group/shared_context_for_ems_metadata_tree.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
shared_context "simple ems_metadata tree" do | ||
##################### | ||
# Context Variables # | ||
##################### | ||
|
||
# These can be updated to increase the amount of data in the tree | ||
|
||
let(:cluster_count) { 2 } | ||
let(:hosts_per_cluster) { 2 } | ||
let(:vms_per_host) { 2 } | ||
|
||
############### | ||
# Base models # | ||
############### | ||
|
||
let(:ems) { FactoryGirl.create(:ems_infra) } | ||
let(:clusters) { FactoryGirl.create_list(:ems_cluster, cluster_count, :ext_management_system => ems) } | ||
|
||
let(:hosts) do | ||
hosts = [] | ||
clusters.each do |cluster| | ||
hosts += FactoryGirl.create_list(:host, hosts_per_cluster, | ||
:ext_management_system => ems, | ||
:ems_cluster => cluster) | ||
end | ||
hosts | ||
end | ||
|
||
let(:vms) do | ||
vms = [] | ||
hosts.each do |host| | ||
vms += FactoryGirl.create_list(:vm, vms_per_host, | ||
:ext_management_system => ems, | ||
:host => host) | ||
end | ||
vms | ||
end | ||
|
||
################# | ||
# Relationships # | ||
################# | ||
|
||
let(:ems_rel) { ems.init_relationship } | ||
let(:cluster_rels) { clusters.map { |cluster| cluster.init_relationship(ems_rel) } } | ||
|
||
# The next to use a integer division trick to map the proper parent_rel to | ||
# the record being created (the `[index / child_per_parent]` part) | ||
|
||
let(:host_rels) do | ||
hosts.map.with_index do |host, index| | ||
host.init_relationship(cluster_rels[index / hosts_per_cluster]) | ||
end | ||
end | ||
|
||
let(:vm_rels) do | ||
vms.map.with_index do |vm, index| | ||
vm.init_relationship(host_rels[index / vms_per_host]) | ||
end | ||
end | ||
|
||
########### | ||
# Helpers # | ||
########### | ||
|
||
# Convenience statement for initializing the tree (there is no included | ||
# `before` to do this automatically | ||
let(:init_full_tree) { vm_rels } | ||
end |