From 9ac1929f6a8ff7938fc6f0b26d650bb6f3a101c5 Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Wed, 12 Jul 2017 14:25:44 -0400 Subject: [PATCH] allow comma separated tags --- .../api/base_controller/renderer.rb | 2 +- spec/requests/api/querying_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/base_controller/renderer.rb b/app/controllers/api/base_controller/renderer.rb index 037821e2907..654d9788d2a 100644 --- a/app/controllers/api/base_controller/renderer.rb +++ b/app/controllers/api/base_controller/renderer.rb @@ -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 diff --git a/spec/requests/api/querying_spec.rb b/spec/requests/api/querying_spec.rb index 95c162a4d65..4245b9442df 100644 --- a/spec/requests/api/querying_spec.rb +++ b/spec/requests/api/querying_spec.rb @@ -557,6 +557,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