forked from elastic/elasticsearch-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse_result_test.rb
52 lines (37 loc) · 1.58 KB
/
response_result_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
require 'test_helper'
class Elasticsearch::Model::ResultTest < Test::Unit::TestCase
context "Response result" do
should "have method access to properties" do
result = Elasticsearch::Model::Response::Result.new foo: 'bar', bar: { bam: 'baz' }
assert_respond_to result, :foo
assert_respond_to result, :bar
assert_equal 'bar', result.foo
assert_equal 'baz', result.bar.bam
assert_raise(NoMethodError) { result.xoxo }
end
should "delegate method calls to `_source` when available" do
result = Elasticsearch::Model::Response::Result.new foo: 'bar', _source: { bar: 'baz' }
assert_respond_to result, :foo
assert_respond_to result, :_source
assert_respond_to result, :bar
assert_equal 'bar', result.foo
assert_equal 'baz', result._source.bar
assert_equal 'baz', result.bar
end
should "delegate methods to @result" do
result = Elasticsearch::Model::Response::Result.new foo: 'bar'
assert_equal 'bar', result.foo
assert_equal 'bar', result.fetch('foo')
assert_equal 'moo', result.fetch('NOT_EXIST', 'moo')
assert_respond_to result, :to_hash
assert_equal({'foo' => 'bar'}, result.to_hash)
assert_raise(NoMethodError) { result.does_not_exist }
end
should "delegate as_json to @result even when ActiveSupport changed half of Ruby" do
require 'active_support/json/encoding'
result = Elasticsearch::Model::Response::Result.new foo: 'bar'
result.instance_variable_get(:@result).expects(:as_json)
result.as_json(except: 'foo')
end
end
end