From 17ed24fda3d6c63c40960cb983c2795856ca5078 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 4 Feb 2014 00:48:16 -0800 Subject: [PATCH] Ensure can always sort on id --- lib/searchkick/search.rb | 2 +- test/sql_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/searchkick/search.rb b/lib/searchkick/search.rb index ef2026d..5dc4e53 100644 --- a/lib/searchkick/search.rb +++ b/lib/searchkick/search.rb @@ -179,7 +179,7 @@ module Searchkick # order if options[:order] order = options[:order].is_a?(Enumerable) ? options[:order] : {options[:order] => :asc} - payload[:sort] = order + payload[:sort] = Hash[ order.map{|k, v| [k.to_s == "id" ? :_id : k, v] } ] end term_filters = diff --git a/test/sql_test.rb b/test/sql_test.rb index 03584c9..52f7d59 100644 --- a/test/sql_test.rb +++ b/test/sql_test.rb @@ -148,6 +148,13 @@ class TestSql < Minitest::Unit::TestCase assert_order "product", ["Product A", "Product B", "Product C", "Product D"], order: "name" end + def test_order_id + store_names ["Product A", "Product B"] + product_a = Product.where(name: "Product A").first + product_b = Product.where(name: "Product B").first + assert_order "product", [product_a, product_b].sort_by(&:id).map(&:name), order: {id: :asc} + end + def test_order_multiple store [ {name: "Product A", color: "blue", store_id: 1}, -- libgit2 0.21.0