Skip to content

Commit

Permalink
Merge pull request #13786 from imtayadeway/fix/miq-expression-is-field
Browse files Browse the repository at this point in the history
Ensure field model name is model
  • Loading branch information
gtanzillo authored Feb 10, 2017
2 parents e0b2859 + 83cf72c commit 83fc4e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/miq_expression/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def date?
end

def self.is_field?(field)
if field.kind_of?(String)
match = FIELD_REGEX.match(field)
match.present? && match[:model_name].safe_constantize.present?
end
return false unless field.kind_of?(String)
match = FIELD_REGEX.match(field)
return false unless match
model = match[:model_name].safe_constantize
return false unless model
!!(model < ApplicationRecord)
end

def datetime?
Expand Down
1 change: 1 addition & 0 deletions spec/lib/miq_expression/field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@

it "does not detect a string to looks like a field but isn't" do
expect(MiqExpression::Field.is_field?("NetworkManager-team")).to be_falsey
expect(described_class.is_field?("ManageIQ-name")).to be(false)
end
end
end

0 comments on commit 83fc4e2

Please sign in to comment.