From 746b16022411b23f97187594441dc219d4f7d3ee Mon Sep 17 00:00:00 2001 From: Rajesh Kumar Date: Tue, 2 Jun 2015 16:13:01 -0700 Subject: [PATCH] [Facets] test for field support --- test/facets_test.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/facets_test.rb b/test/facets_test.rb index c888777..6c0fe42 100644 --- a/test/facets_test.rb +++ b/test/facets_test.rb @@ -21,6 +21,12 @@ class TestFacets < Minitest::Test assert_equal ({1 => 1}), store_facet(facets: {store_id: {where: {in_stock: true}}}) end + def test_field + assert_equal ({1 => 1, 2 => 2}), store_facet(facets: {store_id: {}}) + assert_equal ({1 => 1, 2 => 2}), store_facet(facets: {store_id: {field: "store_id"}}) + assert_equal ({1 => 1, 2 => 2}), store_facet({facets: {store_id_new: {field: "store_id"}}}, "store_id_new") + end + def test_limit facet = Product.search("Product", facets: {store_id: {limit: 1}}).facets["store_id"] assert_equal 1, facet["terms"].size @@ -78,8 +84,8 @@ class TestFacets < Minitest::Test protected - def store_facet(options) - Hash[Product.search("Product", options).facets["store_id"]["terms"].map { |v| [v["term"], v["count"]] }] + def store_facet(options, facet_key="store_id") + Hash[Product.search("Product", options).facets[facet_key]["terms"].map { |v| [v["term"], v["count"]] }] end end -- libgit2 0.21.0