Skip to content

Commit

Permalink
Merge pull request ManageIQ#15557 from jntullo/allow_comma_separated_…
Browse files Browse the repository at this point in the history
…tags

Query by multiple tags
  • Loading branch information
abellotti authored Jul 24, 2017
2 parents 60e09b3 + 9ac1929 commit 71d244b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/base_controller/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def collection_search(is_subcollection, type, klass)
if is_subcollection
send("#{type}_query_resource", parent_resource_obj)
elsif by_tag_param
klass.find_tagged_with(:all => by_tag_param, :ns => TAG_NAMESPACE)
klass.find_tagged_with(:all => by_tag_param, :ns => TAG_NAMESPACE, :separator => ',')
else
klass.all
end
Expand Down
19 changes: 19 additions & 0 deletions spec/requests/api/querying_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,25 @@ def create_vms_by_name(names)
expect_query_result(:vms, 2, 3)
expect_result_resources_to_include_data("resources", "name" => [vm1.name, vm3.name])
end

it "supports multiple comma separated tags" do
api_basic_authorize collection_action_identifier(:vms, :read, :get)
vm1, _vm2, vm3 = create_vms_by_name(%w(aa bb cc))

dept = FactoryGirl.create(:classification_department)
cc = FactoryGirl.create(:classification_cost_center)
FactoryGirl.create(:classification_tag, :name => "finance", :description => "Finance", :parent => dept)
FactoryGirl.create(:classification_tag, :name => "cc01", :description => "Cost Center 1", :parent => cc)

Classification.classify(vm1, "department", "finance")
Classification.classify(vm1, "cc", "cc01")
Classification.classify(vm3, "department", "finance")

run_get vms_url, :expand => "resources", :by_tag => "/department/finance,/cc/cc01"

expect_query_result(:vms, 1, 3)
expect_result_resources_to_include_data("resources", "name" => [vm1.name])
end
end

describe "Querying vms" do
Expand Down

0 comments on commit 71d244b

Please sign in to comment.