Commit c0c8a77ee815231ece99ebed1ba9a86862214d25

Authored by Andrew Kane
2 parents c2128652 fb3aaae8

Merge pull request #621 from meetrajesh/select_v2_tests

More select_v2 tests
Showing 1 changed file with 27 additions and 0 deletions   Show diff stats
test/sql_test.rb
... ... @@ -146,6 +146,33 @@ class SqlTest < Minitest::Test
146 146 store [{name: "Product A", user_ids: [1, 2]}]
147 147 hit = Product.search("product", select_v2: []).hits.first
148 148 assert_nil hit["_source"]
  149 + hit = Product.search("product", select_v2: false).hits.first
  150 + assert_nil hit["_source"]
  151 + end
  152 +
  153 + def test_select_v2_include
  154 + store [{name: "Product A", user_ids: [1, 2]}]
  155 + result = Product.search("product", load: false, select_v2: {include: [:name]}).first
  156 + assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort
  157 + assert_equal "Product A", result.name
  158 + assert_nil result.store_id
  159 + end
  160 +
  161 + def test_select_v2_exclude
  162 + store [{name: "Product A", user_ids: [1, 2], store_id: 1}]
  163 + result = Product.search("product", load: false, select_v2: {exclude: [:name]}).first
  164 + assert_nil result.name
  165 + assert_equal [1, 2], result.user_ids
  166 + assert_equal 1, result.store_id
  167 + end
  168 +
  169 + def test_select_v2_include_and_exclude
  170 + # let's take this to the next level
  171 + store [{name: "Product A", user_ids: [1, 2], store_id: 1}]
  172 + result = Product.search("product", load: false, select_v2: {include: [:store_id], exclude: [:name]}).first
  173 + assert_equal 1, result.store_id
  174 + assert_nil result.name
  175 + assert_nil result.user_ids
149 176 end
150 177  
151 178 # other tests
... ...