Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query by multiple tags #15557

Merged
merged 1 commit into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Expand Down