forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse_aggregations_test.rb
46 lines (37 loc) · 1.45 KB
/
response_aggregations_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
require 'test_helper'
class Elasticsearch::Model::ResponseAggregationsTest < Test::Unit::TestCase
context "Response aggregations" do
class OriginClass
def self.index_name; 'foo'; end
def self.document_type; 'bar'; end
end
RESPONSE = {
'aggregations' => {
'foo' => {'bar' => 10 },
'price' => { 'doc_count' => 123,
'min' => { 'value' => 1.0},
'max' => { 'value' => 99 }
}
}
}
setup do
@search = Elasticsearch::Model::Searching::SearchRequest.new OriginClass, '*'
@search.stubs(:execute!).returns(RESPONSE)
end
should "access the aggregations" do
@search.expects(:execute!).returns(RESPONSE)
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
assert_respond_to response, :aggregations
assert_kind_of Elasticsearch::Model::Response::Aggregations, response.aggregations
assert_kind_of Hashie::Mash, response.aggregations.foo
assert_equal 10, response.aggregations.foo.bar
end
should "properly return min and max values" do
@search.expects(:execute!).returns(RESPONSE)
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
assert_equal 123, response.aggregations.price.doc_count
assert_equal 1, response.aggregations.price.min.value
assert_equal 99, response.aggregations.price.max.value
end
end
end