forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse_test.rb
57 lines (44 loc) · 1.91 KB
/
response_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'test_helper'
class Elasticsearch::Model::ResponseTest < Test::Unit::TestCase
context "Response" do
class OriginClass
def self.index_name; 'foo'; end
def self.document_type; 'bar'; end
end
RESPONSE = { 'took' => '5', 'timed_out' => false, '_shards' => {'one' => 'OK'}, 'hits' => { 'hits' => [] } }
setup do
@search = Elasticsearch::Model::Searching::SearchRequest.new OriginClass, '*'
@search.stubs(:execute!).returns(RESPONSE)
end
should "access klass, response, took, timed_out, shards" do
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
assert_equal OriginClass, response.klass
assert_equal @search, response.search
assert_equal RESPONSE, response.response
assert_equal '5', response.took
assert_equal false, response.timed_out
assert_equal 'OK', response.shards.one
end
should "load and access the results" do
@search.expects(:execute!).returns(RESPONSE)
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
assert_instance_of Elasticsearch::Model::Response::Results, response.results
assert_equal 0, response.size
end
should "load and access the records" do
@search.expects(:execute!).returns(RESPONSE)
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
assert_instance_of Elasticsearch::Model::Response::Records, response.records
assert_equal 0, response.size
end
should "delegate Enumerable methods to results" do
@search.expects(:execute!).returns(RESPONSE)
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
assert response.empty?
end
should "be initialized lazily" do
@search.expects(:execute!).never
Elasticsearch::Model::Response::Response.new OriginClass, @search
end
end
end