Commit 8ed11f94789516cb9bc89ea09fb0eec0accf4fce

Authored by Andrew Kane
1 parent eb3e4f30
Exists in relation

Test multiple relations [skip ci]

Showing 1 changed file with 10 additions and 0 deletions   Show diff stats
test/sql_test.rb
... ... @@ -173,6 +173,16 @@ class SqlTest < Minitest::Test
173 173 assert_equal 1, result.store_id
174 174 end
175 175  
  176 + def test_select_multiple_relation
  177 + store [{name: "Product A", store_id: 1}]
  178 + # only last select applies - different from Active Record
  179 + # since we have to allow for boolean, array, and hash values
  180 + result = Product.search("product").load(false).select(:name).select(:store_id).first
  181 + assert_equal %w(id store_id), result.keys.reject { |k| k.start_with?("_") }.sort
  182 + assert_nil result.name
  183 + assert_equal 1, result.store_id
  184 + end
  185 +
176 186 def test_select_array_relation
177 187 store [{name: "Product A", user_ids: [1, 2]}]
178 188 result = Product.search("product").load(false).select(:user_ids).first
... ...