Skip to content

Commit

Permalink
Update miq_query specs to prevent failures
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Apr 22, 2020
1 parent 87de914 commit 6f099e9
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion spec/lib/miq_expression_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@
expect(sql).to eq("\"vms\".\"name\" IS NOT NULL AND \"vms\".\"name\" != ''")
end

it "generates the SQL for a CONTAINS expression with field" do
it "generates the SQL for a CONTAINS expression with has_many field" do
sql, * = MiqExpression.new("CONTAINS" => {"field" => "Vm.guest_applications-name", "value" => "foo"}).to_sql
expect(sql).to eq("\"vms\".\"id\" IN (SELECT DISTINCT \"guest_applications\".\"vm_or_template_id\" FROM \"guest_applications\" WHERE \"guest_applications\".\"name\" = 'foo')")
end
Expand All @@ -498,12 +498,32 @@
expect(sql).to be_nil
end

it "can't generate the SQL for a CONTAINS expression with belongs_to field" do
sql, * = MiqExpression.new("CONTAINS" => {"field" => "Vm.host-name", "value" => "foo"}).to_sql
expect(sql).to be_nil
end

it "can't generate the SQL for multi level contains with a scope" do
sql, _ = MiqExpression.new("CONTAINS" => {"field" => "ExtManagementSystem.clustered_hosts.operating_system-name", "value" => "RHEL"}).to_sql
expect(sql).to be_nil
end

it "can't generate the SQL for field belongs to 'has_and_belongs_to_many' association" do
sql, _ = MiqExpression.new("CONTAINS" => {"field" => "ManageIQ::Providers::InfraManager::Vm.storages-name", "value" => "abc"}).to_sql
expect(sql).to be_nil
end

it "can't generate the SQL for a CONTAINS expression virtualassociation" do
sql, * = MiqExpression.new("CONTAINS" => {"field" => "Vm.processes-name", "value" => "foo"}).to_sql
expect(sql).to be_nil
end

it "can't generate the SQL for a CONTAINS expression with [association.virtualassociation]" do
sql, * = MiqExpression.new("CONTAINS" => {"field" => "Vm.evm_owner.active_vms-name", "value" => "foo"}).to_sql
expect(sql).to be_nil
end

it "can't generate the SQL for a CONTAINS expression with invalid associations" do
sql, * = MiqExpression.new("CONTAINS" => {"field" => "Vm.users.active_vms-name", "value" => "foo"}).to_sql
expect(sql).to be_nil
end
Expand All @@ -515,6 +535,11 @@
expect(sql).to eq(expected)
end

it "can't generate the SQL for a CONTAINS in the main table" do
sql, * = MiqExpression.new("CONTAINS" => {"field" => "Vm-name", "value" => "foo"}).to_sql
expect(sql).to be_nil
end

it "generates the SQL for a CONTAINS expression with tag" do
tag = FactoryBot.create(:tag, :name => "/managed/operations/analysis_failed")
vm = FactoryBot.create(:vm_vmware, :tags => [tag])
Expand Down

0 comments on commit 6f099e9

Please sign in to comment.