Skip to content

Commit 0e66341

Browse files
committed
[STORE] Added a unit test for searching in type based on document_type
Related: elastic#77
1 parent afafa12 commit 0e66341

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

elasticsearch-persistence/lib/elasticsearch/persistence/repository/search.rb

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module Search
4141
#
4242
def search(query_or_definition, options={})
4343
type = document_type || (klass ? __get_type_from_class(klass) : nil )
44+
4445
case
4546
when query_or_definition.respond_to?(:to_hash)
4647
response = client.search( { index: index_name, type: type, body: query_or_definition.to_hash }.merge(options) )

elasticsearch-persistence/test/unit/repository_search_test.rb

+15
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,22 @@ class MyDocument; end
2828
subject.search foo: 'bar'
2929
end
3030

31+
should "search in type based on document_type" do
32+
subject.expects(:document_type).returns('my_special_document').at_least_once
33+
subject.expects(:__get_type_from_class).never
34+
35+
@client.expects(:search).with do |arguments|
36+
assert_equal 'test', arguments[:index]
37+
assert_equal 'my_special_document', arguments[:type]
38+
39+
assert_equal({foo: 'bar'}, arguments[:body])
40+
end
41+
42+
subject.search foo: 'bar'
43+
end
44+
3145
should "search across all types" do
46+
subject.expects(:document_type).returns(nil).at_least_once
3247
subject.expects(:klass).returns(nil).at_least_once
3348
subject.expects(:__get_type_from_class).never
3449

0 commit comments

Comments
 (0)