Skip to content

Commit

Permalink
Merge pull request #18369 from lpichler/remove_value2tag_for_count_fi…
Browse files Browse the repository at this point in the history
…eld_in_miq_expression

Remove value2tag for count field in MiqExpression
  • Loading branch information
kbrock authored Apr 23, 2019
2 parents 96b4737 + c080a86 commit 1d064e3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/miq_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,9 @@ def self.operands2rubyvalue(operator, ops, context_type)
end
end
elsif ops["count"]
ref, count = value2tag(ops["count"])
field = "<count ref=#{ref}>#{count}</count>"
[field, quote(ops["value"], "integer")]
target = parse_field_or_tag(ops["count"])
fld = "<count ref=#{target.model.to_s.downcase}>#{target.tag_path_with}</count>"
[fld, quote(ops["value"], target.column_type)]
elsif ops["regkey"]
if operator == "key exists"
"<registry key_exists=1, type=boolean>#{ops["regkey"].strip}</registry> == 'true'"
Expand Down
4 changes: 4 additions & 0 deletions lib/miq_expression/count_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def to_s
[model, *associations].join(".")
end

def column_type
:integer
end

private

def tag_values
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/miq_expression_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@

describe "#to_ruby" do
it "generates the ruby for a = expression with count" do
actual = described_class.new("=" => {"count" => "Vm-snapshots", "value" => "1"}).to_ruby
actual = described_class.new("=" => {"count" => "Vm.snapshots", "value" => "1"}).to_ruby
expected = "<count ref=vm>/virtual/snapshots</count> == 1"
expect(actual).to eq(expected)
end
Expand All @@ -985,7 +985,7 @@
end

it "generates the ruby for a < expression with count" do
actual = described_class.new("<" => {"count" => "Vm-snapshots", "value" => "2"}).to_ruby
actual = described_class.new("<" => {"count" => "Vm.snapshots", "value" => "2"}).to_ruby
expected = "<count ref=vm>/virtual/snapshots</count> < 2"
expect(actual).to eq(expected)
end
Expand All @@ -997,7 +997,7 @@
end

it "generates the ruby for a > expression with count" do
actual = described_class.new(">" => {"count" => "Vm-snapshots", "value" => "2"}).to_ruby
actual = described_class.new(">" => {"count" => "Vm.snapshots", "value" => "2"}).to_ruby
expected = "<count ref=vm>/virtual/snapshots</count> > 2"
expect(actual).to eq(expected)
end
Expand All @@ -1009,7 +1009,7 @@
end

it "generates the ruby for a >= expression with count" do
actual = described_class.new(">=" => {"count" => "Vm-snapshots", "value" => "2"}).to_ruby
actual = described_class.new(">=" => {"count" => "Vm.snapshots", "value" => "2"}).to_ruby
expected = "<count ref=vm>/virtual/snapshots</count> >= 2"
expect(actual).to eq(expected)
end
Expand All @@ -1021,7 +1021,7 @@
end

it "generates the ruby for a <= expression with count" do
actual = described_class.new("<=" => {"count" => "Vm-snapshots", "value" => "2"}).to_ruby
actual = described_class.new("<=" => {"count" => "Vm.snapshots", "value" => "2"}).to_ruby
expected = "<count ref=vm>/virtual/snapshots</count> <= 2"
expect(actual).to eq(expected)
end
Expand All @@ -1033,7 +1033,7 @@
end

it "generates the ruby for a != expression with count" do
actual = described_class.new("!=" => {"count" => "Vm-snapshots", "value" => "2"}).to_ruby
actual = described_class.new("!=" => {"count" => "Vm.snapshots", "value" => "2"}).to_ruby
expected = "<count ref=vm>/virtual/snapshots</count> != 2"
expect(actual).to eq(expected)
end
Expand Down

0 comments on commit 1d064e3

Please sign in to comment.