Permalink
Browse files

[MODEL] Fixed, that `klass.primary_key` is used instead of `ids` in t…

…he ActiveRecord adapter


Closes #11
  • Loading branch information...
ayamomiji authored and karmi committed Feb 7, 2014
1 parent fc96638 commit 72f0e7690bd0d6eef85f1e8816914732bbaa8abc
@@ -13,7 +13,7 @@ module Records
# Returns an `ActiveRecord::Relation` instance
#
def records
- sql_records = klass.where(id: ids)
+ sql_records = klass.where(klass.primary_key => ids)
# Re-order records based on the order from Elasticsearch hits
# by redefining `to_a`, unless the user has called `order()`
@@ -40,7 +40,7 @@ def ids
assert_instance_of Module, Elasticsearch::Model::Adapter::ActiveRecord::Records
instance = DummyClassForActiveRecord.new
- instance.expects(:klass).returns(mock('class', where: @records))
+ instance.expects(:klass).returns(mock('class', primary_key: :some_key, where: @records)).at_least_once
assert_equal @records, instance.records
end
@@ -55,7 +55,7 @@ def ids
@records.instance_variable_set(:@records, @records)
instance = DummyClassForActiveRecord.new
- instance.expects(:klass).returns(mock('class', where: @records))
+ instance.expects(:klass).returns(mock('class', primary_key: :some_key, where: @records)).at_least_once
assert_equal [1, 2], @records. to_a.map(&:id)
assert_equal [2, 1], instance.records.to_a.map(&:id)
@@ -65,7 +65,7 @@ def ids
@records.instance_variable_set(:@records, @records)
instance = DummyClassForActiveRecord.new
- instance.expects(:klass).returns(stub('class', where: @records)).at_least_once
+ instance.expects(:klass).returns(stub('class', primary_key: :some_key, where: @records)).at_least_once
instance.records.expects(:order).returns(@records)
assert_equal [2, 1], instance.records. to_a.map(&:id)

0 comments on commit 72f0e76

Please sign in to comment.