Skip to content

Commit

Permalink
Merge pull request #16704 from imtayadeway/bug/miq-expression-model-n…
Browse files Browse the repository at this point in the history
…amespaces

Parse models of > 3 namespaces
  • Loading branch information
Fryguy authored Dec 20, 2017
2 parents 2b27e62 + e0fa9a8 commit faeac8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/miq_expression/tag.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class MiqExpression::Tag < MiqExpression::Target
REGEX = /
(?<model_name>([[:alnum:]]*(::)?){4})
(?<model_name>(?:[[:upper:]][[:alnum:]]*(?:::[[:upper:]][[:alnum:]]*)*)?)
\.?(?<associations>([a-z_]+\.)*)
(?<namespace>\bmanaged|user_tag\b)
-(?<column>[a-z]+[_[:alnum:]]+)
Expand Down
17 changes: 13 additions & 4 deletions spec/lib/miq_expression/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@
end

it "with model.associations.managed-in_tag" do
tag = "service.user.managed-service_level"
tag = "Service.user.managed-service_level"
expect(described_class.parse(tag)).to have_attributes(:model => Service,
:associations => ['user'],
:namespace => "/managed/service_level")
end

it "with model.associations.user_tag-in_tag" do
tag = "service.user.user_tag-service_level"
tag = "Service.user.user_tag-service_level"
expect(described_class.parse(tag)).to have_attributes(:model => Service,
:associations => ['user'],
:namespace => "/user/service_level")
end

it "with invalid case model.associations.managed-in_tag" do
tag = "service.user.mXaXnXaXged-service_level"
tag = "Service.user.mXaXnXaXged-service_level"
expect(described_class.parse(tag)).to be_nil
end

Expand All @@ -72,9 +72,18 @@
end

it "returns nil with invalid case parent-model::model::somethingmanaged-se" do
tag = "ManageIQ::Providers::CloudManagermanaged-se'"
tag = "ManageIQ::Providers::CloudManagermanaged-se"
expect(described_class.parse(tag)).to be_nil
end

it "can parse models in deeply nested namespaces" do
tag = "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem.managed-cc"

expected = {
:model => ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem
}
expect(described_class.parse(tag)).to have_attributes(expected)
end
end

describe "#to_s" do
Expand Down

0 comments on commit faeac8b

Please sign in to comment.