Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions spec/factories/vm_or_template.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FactoryBot.define do
factory :vm_or_template do
factory :vm_or_template, :class => "ManageIQ::Providers::Vmware::InfraManager::Vm" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a separate factory vm_vmware which already does this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that vm, vm_or_template, and vm_vmware would be interchangeable. They instantiate a vm.

Or maybe they pick a random child? (though we need consistency with that and the corresponding ems)

I do like when tests link to "any vm or template".
But I don't think we should instantiate that class.

I couldn't declare the parent of vm to be vm_vmware since we needed it to still flow up to vm_or_template.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VmOrTemplate is a real class, not something abstract.

I don't think we should change factory :vm_or_template to return Vmware::InfraManager::Vm, I think we should change any specs that use FactoryBot.build(:vm_or_template) if that isn't what they really mean.

sequence(:name) { |n| "vm_#{seq_padded_for_sorting(n)}" }
location { "unknown" }
uid_ems { SecureRandom.uuid }
Expand All @@ -12,13 +12,13 @@
end
end

factory :template, :class => "MiqTemplate", :parent => :vm_or_template do
factory :template, :class => "ManageIQ::Providers::Vmware::InfraManager::Template", :parent => :vm_or_template do
sequence(:name) { |n| "template_#{seq_padded_for_sorting(n)}" }
template { true }
raw_power_state { "never" }
end

factory(:vm, :class => "Vm", :parent => :vm_or_template)
factory(:vm, :class => "ManageIQ::Providers::Vmware::InfraManager::Vm", :parent => :vm_or_template)
factory(:vm_cloud, :class => "VmCloud", :parent => :vm) { cloud { true } }
factory(:vm_infra, :class => "VmInfra", :parent => :vm)
factory(:vm_server, :class => "VmServer", :parent => :vm)
Expand All @@ -38,7 +38,7 @@
vendor { "openstack" }
end

factory :miq_template do
factory :miq_template, :class => "ManageIQ::Providers::Vmware::InfraManager::Template" do
name { "ubuntu-16.04-stable" }
location { "Minneapolis, MN" }
vendor { "openstack" }
Expand Down
4 changes: 3 additions & 1 deletion spec/models/miq_report/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@
FactoryBot.create(:template) # filtered out by report.where_clause
vm = FactoryBot.create(:vm, :vendor => "redhat")

expect(vm.type).to match(/Vm/)

rpt = FactoryBot.create(
:miq_report,
:db => "VmOrTemplate",
:where_clause => ["vms.type = ?", "Vm"],
:where_clause => ["vms.type = ?", vm.type],
:col_order => %w[id name host.name vendor]
)
rpt.generate_table(:userid => @user.userid, :where_clause => {"vms.vendor" => "redhat"})
Expand Down
12 changes: 8 additions & 4 deletions spec/models/vm_or_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,35 @@
end

context "with attrs template => true, ems_id => nil, host_id => nil" do
let(:attrs) { {:template => true, :ems_id => nil, :host_id => nil} }
subject { FactoryBot.create(:miq_template, attrs) }
let(:attrs) { {:ems_id => nil, :host_id => nil} }

it("is not #registered?") { expect(subject.registered?).to be false }
it("is not in registered_vms") { expect(registered_vms).to_not include subject }
it("is in unregistered_vms") { expect(unregistered_vms).to include subject }
end

context "with attrs if template => true, ems_id => nil, host_id => [ID]" do
let(:attrs) { {:template => true, :ems_id => nil, :host_id => host.id} }
subject { FactoryBot.create(:miq_template, attrs) }
let(:attrs) { {:ems_id => nil, :host_id => host.id} }

it("is not #registered?") { expect(subject.registered?).to be false }
it("is not in registered_vms") { expect(registered_vms).to_not include subject }
it("is in unregistered_vms") { expect(unregistered_vms).to include subject }
end

context "with attrs if template => true, ems_id => [ID], host_id => nil" do
let(:attrs) { {:template => true, :ems_id => ems.id, :host_id => nil} }
subject { FactoryBot.create(:miq_template, attrs) }
let(:attrs) { {:ems_id => ems.id, :host_id => nil} }

it("is not #registered?") { expect(subject.registered?).to be false }
it("is not in registered_vms") { expect(registered_vms).to_not include subject }
it("is in unregistered_vms") { expect(unregistered_vms).to include subject }
end

context "with attrs if template => true, ems_id => [ID], host_id => [ID]" do
let(:attrs) { {:template => true, :ems_id => ems.id, :host_id => host.id} }
subject { FactoryBot.create(:miq_template, attrs) }
let(:attrs) { {:ems_id => ems.id, :host_id => host.id} }

it("is #registered?") { expect(subject.registered?).to be true }
it("is in registered_vms") { expect(registered_vms).to include subject }
Expand Down