Skip to content

Commit

Permalink
Merge pull request ManageIQ#21471 from jrafanie/exclude_deprecated_te…
Browse files Browse the repository at this point in the history
…mplates_cleanup_array_condition_syntax

Use hash condition syntax and add missing test
  • Loading branch information
kbrock authored Oct 12, 2021
2 parents ce8ed7c + 3b6d85c commit 878bc6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/miq_provision_virt_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def allowed_templates(options = {})
def allowed_template_condition
return ["vms.ems_id IS NOT NULL"] unless self.class.respond_to?(:provider_model)

["vms.ems_id in (?)", self.class.provider_model.pluck(:id)]
{"vms.ems_id" => self.class.provider_model.pluck(:id)}
end

def source_vm_rbac_filter(vms, condition = nil, *extra_cols)
Expand Down
13 changes: 12 additions & 1 deletion spec/models/miq_provision_virt_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
workflow = FactoryBot.create(:miq_provision_virt_workflow_vmware)

expect(workflow.class).to receive(:provider_model).once.and_return(ems.class)
expect(workflow.allowed_template_condition).to eq(["vms.ems_id in (?)", [ems.id]])
expect(workflow.allowed_template_condition).to eq({"vms.ems_id" => [ems.id]})
end
end

Expand Down Expand Up @@ -407,5 +407,16 @@
FactoryBot.create(:template_vmware, :ext_management_system => nil, :deprecated => false)
expect(workflow.allowed_templates.count).to eq(0)
end

it "excludes templates not matching the provider_model" do
local_google = FactoryBot.create(:ems_google_with_authentication)
allow(workflow.class).to receive(:provider_model).and_return(local_google.class)
FactoryBot.create(:template_vmware, :ext_management_system => local_vmware, :deprecated => false) # to be excluded
cloud_template = FactoryBot.create(:template_google, :ext_management_system => local_google, :deprecated => false) # to be included

allowed = workflow.allowed_templates
expect(allowed.length).to eq(1)
expect(allowed.first.id).to eq(cloud_template.id)
end
end
end

0 comments on commit 878bc6d

Please sign in to comment.