Commit 746b16022411b23f97187594441dc219d4f7d3ee

Authored by Rajesh Kumar
1 parent 82116bec

[Facets] test for field support

Showing 1 changed file with 8 additions and 2 deletions   Show diff stats
test/facets_test.rb
... ... @@ -21,6 +21,12 @@ class TestFacets < Minitest::Test
21 21 assert_equal ({1 => 1}), store_facet(facets: {store_id: {where: {in_stock: true}}})
22 22 end
23 23  
  24 + def test_field
  25 + assert_equal ({1 => 1, 2 => 2}), store_facet(facets: {store_id: {}})
  26 + assert_equal ({1 => 1, 2 => 2}), store_facet(facets: {store_id: {field: "store_id"}})
  27 + assert_equal ({1 => 1, 2 => 2}), store_facet({facets: {store_id_new: {field: "store_id"}}}, "store_id_new")
  28 + end
  29 +
24 30 def test_limit
25 31 facet = Product.search("Product", facets: {store_id: {limit: 1}}).facets["store_id"]
26 32 assert_equal 1, facet["terms"].size
... ... @@ -78,8 +84,8 @@ class TestFacets < Minitest::Test
78 84  
79 85 protected
80 86  
81   - def store_facet(options)
82   - Hash[Product.search("Product", options).facets["store_id"]["terms"].map { |v| [v["term"], v["count"]] }]
  87 + def store_facet(options, facet_key="store_id")
  88 + Hash[Product.search("Product", options).facets[facet_key]["terms"].map { |v| [v["term"], v["count"]] }]
83 89 end
84 90  
85 91 end
... ...