elasticsearch-model 5.1.0 → 6.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -3
  3. data/Gemfile +5 -0
  4. data/README.md +18 -11
  5. data/Rakefile +27 -36
  6. data/elasticsearch-model.gemspec +6 -6
  7. data/examples/activerecord_custom_analyzer.rb +135 -0
  8. data/examples/activerecord_mapping_completion.rb +3 -18
  9. data/examples/datamapper_article.rb +11 -1
  10. data/gemfiles/3.0.gemfile +6 -1
  11. data/gemfiles/4.0.gemfile +8 -1
  12. data/gemfiles/5.0.gemfile +7 -1
  13. data/gemfiles/6.0.gemfile +18 -0
  14. data/lib/elasticsearch/model/adapters/active_record.rb +8 -24
  15. data/lib/elasticsearch/model/adapters/mongoid.rb +10 -3
  16. data/lib/elasticsearch/model/importing.rb +1 -1
  17. data/lib/elasticsearch/model/indexing.rb +6 -4
  18. data/lib/elasticsearch/model/naming.rb +9 -2
  19. data/lib/elasticsearch/model/response/aggregations.rb +1 -1
  20. data/lib/elasticsearch/model/response/base.rb +3 -2
  21. data/lib/elasticsearch/model/response/pagination/kaminari.rb +109 -0
  22. data/lib/elasticsearch/model/response/pagination/will_paginate.rb +95 -0
  23. data/lib/elasticsearch/model/response/pagination.rb +2 -192
  24. data/lib/elasticsearch/model/response/result.rb +1 -1
  25. data/lib/elasticsearch/model/response/suggestions.rb +1 -1
  26. data/lib/elasticsearch/model/response.rb +11 -10
  27. data/lib/elasticsearch/model/version.rb +1 -1
  28. data/lib/elasticsearch/model.rb +15 -8
  29. data/spec/elasticsearch/model/adapter_spec.rb +119 -0
  30. data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +334 -0
  31. data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +340 -0
  32. data/spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb +18 -0
  33. data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +187 -0
  34. data/spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb +110 -0
  35. data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +38 -0
  36. data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +315 -0
  37. data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +75 -0
  38. data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +61 -0
  39. data/spec/elasticsearch/model/adapters/active_record_spec.rb +207 -0
  40. data/spec/elasticsearch/model/adapters/default_spec.rb +41 -0
  41. data/spec/elasticsearch/model/adapters/mongoid/basic_spec.rb +267 -0
  42. data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +66 -0
  43. data/spec/elasticsearch/model/adapters/mongoid_spec.rb +235 -0
  44. data/spec/elasticsearch/model/adapters/multiple_spec.rb +125 -0
  45. data/spec/elasticsearch/model/callbacks_spec.rb +33 -0
  46. data/spec/elasticsearch/model/client_spec.rb +66 -0
  47. data/spec/elasticsearch/model/hash_wrapper_spec.rb +12 -0
  48. data/spec/elasticsearch/model/importing_spec.rb +214 -0
  49. data/spec/elasticsearch/model/indexing_spec.rb +918 -0
  50. data/spec/elasticsearch/model/module_spec.rb +101 -0
  51. data/spec/elasticsearch/model/multimodel_spec.rb +55 -0
  52. data/spec/elasticsearch/model/naming_inheritance_spec.rb +184 -0
  53. data/spec/elasticsearch/model/naming_spec.rb +186 -0
  54. data/spec/elasticsearch/model/proxy_spec.rb +107 -0
  55. data/spec/elasticsearch/model/response/aggregations_spec.rb +66 -0
  56. data/spec/elasticsearch/model/response/base_spec.rb +90 -0
  57. data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +410 -0
  58. data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +262 -0
  59. data/spec/elasticsearch/model/response/records_spec.rb +118 -0
  60. data/spec/elasticsearch/model/response/response_spec.rb +131 -0
  61. data/spec/elasticsearch/model/response/result_spec.rb +122 -0
  62. data/spec/elasticsearch/model/response/results_spec.rb +56 -0
  63. data/spec/elasticsearch/model/searching_search_request_spec.rb +112 -0
  64. data/spec/elasticsearch/model/searching_spec.rb +49 -0
  65. data/spec/elasticsearch/model/serializing_spec.rb +22 -0
  66. data/spec/spec_helper.rb +161 -0
  67. data/spec/support/app/answer.rb +33 -0
  68. data/spec/support/app/article.rb +22 -0
  69. data/spec/support/app/article_for_pagination.rb +12 -0
  70. data/spec/support/app/article_with_custom_serialization.rb +13 -0
  71. data/spec/support/app/article_with_dynamic_index_name.rb +15 -0
  72. data/spec/support/app/author.rb +9 -0
  73. data/spec/support/app/authorship.rb +4 -0
  74. data/spec/support/app/category.rb +3 -0
  75. data/spec/support/app/comment.rb +3 -0
  76. data/spec/support/app/episode.rb +11 -0
  77. data/spec/support/app/image.rb +19 -0
  78. data/spec/support/app/import_article.rb +12 -0
  79. data/spec/support/app/mongoid_article.rb +21 -0
  80. data/spec/support/app/namespaced_book.rb +10 -0
  81. data/spec/support/app/parent_and_child_searchable.rb +24 -0
  82. data/spec/support/app/post.rb +14 -0
  83. data/spec/support/app/question.rb +27 -0
  84. data/spec/support/app/searchable.rb +48 -0
  85. data/spec/support/app/series.rb +11 -0
  86. data/spec/support/app.rb +21 -0
  87. data/spec/support/model.json +1 -0
  88. data/{test → spec}/support/model.yml +0 -0
  89. metadata +134 -89
  90. data/test/integration/active_record_associations_parent_child_test.rb +0 -147
  91. data/test/integration/active_record_associations_test.rb +0 -339
  92. data/test/integration/active_record_basic_test.rb +0 -251
  93. data/test/integration/active_record_custom_serialization_test.rb +0 -67
  94. data/test/integration/active_record_import_test.rb +0 -115
  95. data/test/integration/active_record_namespaced_model_test.rb +0 -54
  96. data/test/integration/active_record_pagination_test.rb +0 -149
  97. data/test/integration/dynamic_index_name_test.rb +0 -52
  98. data/test/integration/mongoid_basic_test.rb +0 -176
  99. data/test/integration/multiple_models_test.rb +0 -176
  100. data/test/support/model.json +0 -1
  101. data/test/test_helper.rb +0 -92
  102. data/test/unit/adapter_active_record_test.rb +0 -157
  103. data/test/unit/adapter_default_test.rb +0 -41
  104. data/test/unit/adapter_mongoid_test.rb +0 -104
  105. data/test/unit/adapter_multiple_test.rb +0 -106
  106. data/test/unit/adapter_test.rb +0 -69
  107. data/test/unit/callbacks_test.rb +0 -31
  108. data/test/unit/client_test.rb +0 -27
  109. data/test/unit/hash_wrapper_test.rb +0 -13
  110. data/test/unit/importing_test.rb +0 -203
  111. data/test/unit/indexing_test.rb +0 -687
  112. data/test/unit/module_test.rb +0 -68
  113. data/test/unit/multimodel_test.rb +0 -38
  114. data/test/unit/naming_inheritance_test.rb +0 -94
  115. data/test/unit/naming_test.rb +0 -103
  116. data/test/unit/proxy_test.rb +0 -98
  117. data/test/unit/response_aggregations_test.rb +0 -46
  118. data/test/unit/response_base_test.rb +0 -40
  119. data/test/unit/response_pagination_kaminari_test.rb +0 -433
  120. data/test/unit/response_pagination_will_paginate_test.rb +0 -398
  121. data/test/unit/response_records_test.rb +0 -91
  122. data/test/unit/response_result_test.rb +0 -90
  123. data/test/unit/response_results_test.rb +0 -31
  124. data/test/unit/response_test.rb +0 -104
  125. data/test/unit/searching_search_request_test.rb +0 -78
  126. data/test/unit/searching_test.rb +0 -41
  127. data/test/unit/serializing_test.rb +0 -17
@@ -1,68 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Elasticsearch::Model::ModuleTest < Test::Unit::TestCase
4
- context "The main module" do
5
-
6
- context "client" do
7
- should "have a default" do
8
- client = Elasticsearch::Model.client
9
- assert_not_nil client
10
- assert_instance_of Elasticsearch::Transport::Client, client
11
- end
12
-
13
- should "be settable" do
14
- begin
15
- Elasticsearch::Model.client = "Foobar"
16
- assert_equal "Foobar", Elasticsearch::Model.client
17
- ensure
18
- Elasticsearch::Model.client = nil
19
- end
20
- end
21
- end
22
-
23
- context "when included in module/class, " do
24
- class ::DummyIncludingModel; end
25
- class ::DummyIncludingModelWithSearchMethodDefined
26
- def self.search(query, options={})
27
- "SEARCH"
28
- end
29
- end
30
-
31
- should "include and set up the proxy" do
32
- DummyIncludingModel.__send__ :include, Elasticsearch::Model
33
-
34
- assert_respond_to DummyIncludingModel, :__elasticsearch__
35
- assert_respond_to DummyIncludingModel.new, :__elasticsearch__
36
- end
37
-
38
- should "delegate important methods to the proxy" do
39
- DummyIncludingModel.__send__ :include, Elasticsearch::Model
40
-
41
- assert_respond_to DummyIncludingModel, :search
42
- assert_respond_to DummyIncludingModel, :mappings
43
- assert_respond_to DummyIncludingModel, :settings
44
- assert_respond_to DummyIncludingModel, :index_name
45
- assert_respond_to DummyIncludingModel, :document_type
46
- assert_respond_to DummyIncludingModel, :import
47
- end
48
-
49
- should "not override existing method" do
50
- DummyIncludingModelWithSearchMethodDefined.__send__ :include, Elasticsearch::Model
51
-
52
- assert_equal 'SEARCH', DummyIncludingModelWithSearchMethodDefined.search('foo')
53
- end
54
- end
55
-
56
- context "settings" do
57
- should "access the settings" do
58
- assert_not_nil Elasticsearch::Model.settings
59
- end
60
-
61
- should "allow to set settings" do
62
- assert_nothing_raised { Elasticsearch::Model.settings[:foo] = 'bar' }
63
- assert_equal 'bar', Elasticsearch::Model.settings[:foo]
64
- end
65
- end
66
-
67
- end
68
- end
@@ -1,38 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Elasticsearch::Model::MultimodelTest < Test::Unit::TestCase
4
-
5
- context "Multimodel class" do
6
- setup do
7
- title = stub('Foo', index_name: 'foo_index', document_type: 'foo', to_ary: nil)
8
- series = stub('Bar', index_name: 'bar_index', document_type: 'bar', to_ary: nil)
9
- @multimodel = Elasticsearch::Model::Multimodel.new(title, series)
10
- end
11
-
12
- should "have an index_name" do
13
- assert_equal ['foo_index', 'bar_index'], @multimodel.index_name
14
- end
15
-
16
- should "have a document_type" do
17
- assert_equal ['foo', 'bar'], @multimodel.document_type
18
- end
19
-
20
- should "have a client" do
21
- assert_equal Elasticsearch::Model.client, @multimodel.client
22
- end
23
-
24
- should "include models in the registry" do
25
- class ::JustAModel
26
- include Elasticsearch::Model
27
- end
28
-
29
- class ::JustAnotherModel
30
- include Elasticsearch::Model
31
- end
32
-
33
- multimodel = Elasticsearch::Model::Multimodel.new
34
- assert multimodel.models.include?(::JustAModel)
35
- assert multimodel.models.include?(::JustAnotherModel)
36
- end
37
- end
38
- end
@@ -1,94 +0,0 @@
1
- require "test_helper"
2
-
3
- class Elasticsearch::Model::NamingInheritanceTest < Test::Unit::TestCase
4
- def setup
5
- Elasticsearch::Model.settings[:inheritance_enabled] = true
6
- end
7
-
8
- def teardown
9
- Elasticsearch::Model.settings[:inheritance_enabled] = false
10
- end
11
-
12
- context "Naming module with inheritance" do
13
- class ::TestBase
14
- extend ActiveModel::Naming
15
-
16
- extend Elasticsearch::Model::Naming::ClassMethods
17
- include Elasticsearch::Model::Naming::InstanceMethods
18
- end
19
-
20
- class ::Animal < ::TestBase
21
- extend ActiveModel::Naming
22
-
23
- extend Elasticsearch::Model::Naming::ClassMethods
24
- include Elasticsearch::Model::Naming::InstanceMethods
25
-
26
- index_name "mammals"
27
- document_type "mammal"
28
- end
29
-
30
- class ::Dog < ::Animal
31
- end
32
-
33
- module ::MyNamespace
34
- class Dog < ::Animal
35
- end
36
- end
37
-
38
- class ::Cat < ::Animal
39
- extend ActiveModel::Naming
40
-
41
- extend Elasticsearch::Model::Naming::ClassMethods
42
- include Elasticsearch::Model::Naming::InstanceMethods
43
-
44
- index_name "cats"
45
- document_type "cat"
46
- end
47
-
48
- should "return the default index_name" do
49
- assert_equal "test_bases", TestBase.index_name
50
- assert_equal "test_bases", TestBase.new.index_name
51
- end
52
-
53
- should "return the explicit index_name" do
54
- assert_equal "mammals", Animal.index_name
55
- assert_equal "mammals", Animal.new.index_name
56
-
57
- assert_equal "cats", Cat.index_name
58
- assert_equal "cats", Cat.new.index_name
59
- end
60
-
61
- should "return the ancestor index_name" do
62
- assert_equal "mammals", Dog.index_name
63
- assert_equal "mammals", Dog.new.index_name
64
- end
65
-
66
- should "return the ancestor index_name for namespaced model" do
67
- assert_equal "mammals", ::MyNamespace::Dog.index_name
68
- assert_equal "mammals", ::MyNamespace::Dog.new.index_name
69
- end
70
-
71
- should "return the default document_type" do
72
- assert_equal "test_base", TestBase.document_type
73
- assert_equal "test_base", TestBase.new.document_type
74
- end
75
-
76
- should "return the explicit document_type" do
77
- assert_equal "mammal", Animal.document_type
78
- assert_equal "mammal", Animal.new.document_type
79
-
80
- assert_equal "cat", Cat.document_type
81
- assert_equal "cat", Cat.new.document_type
82
- end
83
-
84
- should "return the ancestor document_type" do
85
- assert_equal "mammal", Dog.document_type
86
- assert_equal "mammal", Dog.new.document_type
87
- end
88
-
89
- should "return the ancestor document_type for namespaced model" do
90
- assert_equal "mammal", ::MyNamespace::Dog.document_type
91
- assert_equal "mammal", ::MyNamespace::Dog.new.document_type
92
- end
93
- end
94
- end
@@ -1,103 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Elasticsearch::Model::NamingTest < Test::Unit::TestCase
4
- context "Naming module" do
5
- class ::DummyNamingModel
6
- extend ActiveModel::Naming
7
-
8
- extend Elasticsearch::Model::Naming::ClassMethods
9
- include Elasticsearch::Model::Naming::InstanceMethods
10
- end
11
-
12
- module ::MyNamespace
13
- class DummyNamingModelInNamespace
14
- extend ActiveModel::Naming
15
-
16
- extend Elasticsearch::Model::Naming::ClassMethods
17
- include Elasticsearch::Model::Naming::InstanceMethods
18
- end
19
- end
20
-
21
- should "return the default index_name" do
22
- assert_equal 'dummy_naming_models', DummyNamingModel.index_name
23
- assert_equal 'dummy_naming_models', DummyNamingModel.new.index_name
24
- end
25
-
26
- should "return the sanitized default index_name for namespaced model" do
27
- assert_equal 'my_namespace-dummy_naming_model_in_namespaces', ::MyNamespace::DummyNamingModelInNamespace.index_name
28
- assert_equal 'my_namespace-dummy_naming_model_in_namespaces', ::MyNamespace::DummyNamingModelInNamespace.new.index_name
29
- end
30
-
31
- should "return the default document_type" do
32
- assert_equal 'dummy_naming_model', DummyNamingModel.document_type
33
- assert_equal 'dummy_naming_model', DummyNamingModel.new.document_type
34
- end
35
-
36
- should "set and return the index_name" do
37
- DummyNamingModel.index_name 'foobar'
38
- assert_equal 'foobar', DummyNamingModel.index_name
39
-
40
- d = DummyNamingModel.new
41
- d.index_name 'foobar_d'
42
- assert_equal 'foobar_d', d.index_name
43
-
44
- modifier = 'r'
45
- d.index_name Proc.new{ "foobar_#{modifier}" }
46
- assert_equal 'foobar_r', d.index_name
47
-
48
- modifier = 'z'
49
- assert_equal 'foobar_z', d.index_name
50
-
51
- modifier = 'f'
52
- d.index_name { "foobar_#{modifier}" }
53
- assert_equal 'foobar_f', d.index_name
54
-
55
- modifier = 't'
56
- assert_equal 'foobar_t', d.index_name
57
- end
58
-
59
- should "set the index_name with setter" do
60
- DummyNamingModel.index_name = 'foobar_index_S'
61
- assert_equal 'foobar_index_S', DummyNamingModel.index_name
62
-
63
- d = DummyNamingModel.new
64
- d.index_name = 'foobar_index_s'
65
- assert_equal 'foobar_index_s', d.index_name
66
-
67
- assert_equal 'foobar_index_S', DummyNamingModel.index_name
68
-
69
- modifier2 = 'y'
70
- DummyNamingModel.index_name = Proc.new{ "foobar_index_#{modifier2}" }
71
- assert_equal 'foobar_index_y', DummyNamingModel.index_name
72
-
73
- modifier = 'r'
74
- d.index_name = Proc.new{ "foobar_index_#{modifier}" }
75
- assert_equal 'foobar_index_r', d.index_name
76
-
77
- modifier = 'z'
78
- assert_equal 'foobar_index_z', d.index_name
79
-
80
- assert_equal 'foobar_index_y', DummyNamingModel.index_name
81
- end
82
-
83
- should "set and return the document_type" do
84
- DummyNamingModel.document_type 'foobar'
85
- assert_equal 'foobar', DummyNamingModel.document_type
86
-
87
- d = DummyNamingModel.new
88
- d.document_type 'foobar_d'
89
- assert_equal 'foobar_d', d.document_type
90
- end
91
-
92
- should "set the document_type with setter" do
93
- DummyNamingModel.document_type = 'foobar_type_S'
94
- assert_equal 'foobar_type_S', DummyNamingModel.document_type
95
-
96
- d = DummyNamingModel.new
97
- d.document_type = 'foobar_type_s'
98
- assert_equal 'foobar_type_s', d.document_type
99
-
100
- assert_equal 'foobar_type_S', DummyNamingModel.document_type
101
- end
102
- end
103
- end
@@ -1,98 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Elasticsearch::Model::SearchTest < Test::Unit::TestCase
4
- context "Searching module" do
5
- class ::DummyProxyModel
6
- include Elasticsearch::Model::Proxy
7
-
8
- def self.foo
9
- 'classy foo'
10
- end
11
-
12
- def bar
13
- 'insta barr'
14
- end
15
-
16
- def as_json(options)
17
- {foo: 'bar'}
18
- end
19
- end
20
-
21
- class ::DummyProxyModelWithCallbacks
22
- def self.before_save(&block)
23
- (@callbacks ||= {})[block.hash] = block
24
- end
25
-
26
- def changes_to_save
27
- {:foo => ['One', 'Two']}
28
- end
29
- end
30
-
31
- should "setup the class proxy method" do
32
- assert_respond_to DummyProxyModel, :__elasticsearch__
33
- end
34
-
35
- should "setup the instance proxy method" do
36
- assert_respond_to DummyProxyModel.new, :__elasticsearch__
37
- end
38
-
39
- should "register the hook for before_save callback" do
40
- ::DummyProxyModelWithCallbacks.expects(:before_save).returns(true)
41
- DummyProxyModelWithCallbacks.__send__ :include, Elasticsearch::Model::Proxy
42
- end
43
-
44
- should "set the @__changed_model_attributes variable before save" do
45
- instance = ::DummyProxyModelWithCallbacks.new
46
- instance.__elasticsearch__.expects(:instance_variable_set).with do |name, value|
47
- assert_equal :@__changed_model_attributes, name
48
- assert_equal({foo: 'Two'}, value)
49
- true
50
- end
51
-
52
- ::DummyProxyModelWithCallbacks.__send__ :include, Elasticsearch::Model::Proxy
53
-
54
- ::DummyProxyModelWithCallbacks.instance_variable_get(:@callbacks).each do |n,b|
55
- instance.instance_eval(&b)
56
- end
57
- end
58
-
59
- should "delegate methods to the target" do
60
- assert_respond_to DummyProxyModel.__elasticsearch__, :foo
61
- assert_respond_to DummyProxyModel.new.__elasticsearch__, :bar
62
-
63
- assert_raise(NoMethodError) { DummyProxyModel.__elasticsearch__.xoxo }
64
- assert_raise(NoMethodError) { DummyProxyModel.new.__elasticsearch__.xoxo }
65
-
66
- assert_equal 'classy foo', DummyProxyModel.__elasticsearch__.foo
67
- assert_equal 'insta barr', DummyProxyModel.new.__elasticsearch__.bar
68
- end
69
-
70
- should "reset the proxy target for duplicates" do
71
- model = DummyProxyModel.new
72
- model_target = model.__elasticsearch__.target
73
- duplicate = model.dup
74
- duplicate_target = duplicate.__elasticsearch__.target
75
-
76
- assert_not_equal model, duplicate
77
- assert_equal model, model_target
78
- assert_equal duplicate, duplicate_target
79
- end
80
-
81
- should "return the proxy class from instance proxy" do
82
- assert_equal Elasticsearch::Model::Proxy::ClassMethodsProxy, DummyProxyModel.new.__elasticsearch__.class.class
83
- end
84
-
85
- should "return the origin class from instance proxy" do
86
- assert_equal DummyProxyModel, DummyProxyModel.new.__elasticsearch__.klass
87
- end
88
-
89
- should "delegate as_json from the proxy to target" do
90
- assert_equal({foo: 'bar'}, DummyProxyModel.new.__elasticsearch__.as_json)
91
- end
92
-
93
- should "have inspect method indicating the proxy" do
94
- assert_match /PROXY/, DummyProxyModel.__elasticsearch__.inspect
95
- assert_match /PROXY/, DummyProxyModel.new.__elasticsearch__.inspect
96
- end
97
- end
98
- end
@@ -1,46 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Elasticsearch::Model::ResponseAggregationsTest < Test::Unit::TestCase
4
- context "Response aggregations" do
5
- class OriginClass
6
- def self.index_name; 'foo'; end
7
- def self.document_type; 'bar'; end
8
- end
9
-
10
- RESPONSE = {
11
- 'aggregations' => {
12
- 'foo' => {'bar' => 10 },
13
- 'price' => { 'doc_count' => 123,
14
- 'min' => { 'value' => 1.0},
15
- 'max' => { 'value' => 99 }
16
- }
17
- }
18
- }
19
-
20
- setup do
21
- @search = Elasticsearch::Model::Searching::SearchRequest.new OriginClass, '*'
22
- @search.stubs(:execute!).returns(RESPONSE)
23
- end
24
-
25
- should "access the aggregations" do
26
- @search.expects(:execute!).returns(RESPONSE)
27
-
28
- response = Elasticsearch::Model::Response::Response.new OriginClass, @search
29
- assert_respond_to response, :aggregations
30
- assert_kind_of Elasticsearch::Model::Response::Aggregations, response.aggregations
31
- assert_kind_of Hashie::Mash, response.aggregations.foo
32
- assert_equal 10, response.aggregations.foo.bar
33
- end
34
-
35
- should "properly return min and max values" do
36
- @search.expects(:execute!).returns(RESPONSE)
37
-
38
- response = Elasticsearch::Model::Response::Response.new OriginClass, @search
39
-
40
- assert_equal 123, response.aggregations.price.doc_count
41
- assert_equal 1, response.aggregations.price.min.value
42
- assert_equal 99, response.aggregations.price.max.value
43
- end
44
-
45
- end
46
- end
@@ -1,40 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Elasticsearch::Model::BaseTest < Test::Unit::TestCase
4
- context "Response base module" do
5
- class OriginClass
6
- def self.index_name; 'foo'; end
7
- def self.document_type; 'bar'; end
8
- end
9
-
10
- class DummyBaseClass
11
- include Elasticsearch::Model::Response::Base
12
- end
13
-
14
- RESPONSE = { 'hits' => { 'total' => 123, 'max_score' => 456, 'hits' => [] } }
15
-
16
- setup do
17
- @search = Elasticsearch::Model::Searching::SearchRequest.new OriginClass, '*'
18
- @response = Elasticsearch::Model::Response::Response.new OriginClass, @search
19
- @search.stubs(:execute!).returns(RESPONSE)
20
- end
21
-
22
- should "access klass, response, total and max_score" do
23
- r = DummyBaseClass.new OriginClass, @response
24
-
25
- assert_equal OriginClass, r.klass
26
- assert_equal @response, r.response
27
- assert_equal RESPONSE, r.response.response
28
- assert_equal 123, r.total
29
- assert_equal 456, r.max_score
30
- end
31
-
32
- should "have abstract methods results and records" do
33
- r = DummyBaseClass.new OriginClass, @response
34
-
35
- assert_raise(Elasticsearch::Model::NotImplemented) { |e| r.results }
36
- assert_raise(Elasticsearch::Model::NotImplemented) { |e| r.records }
37
- end
38
-
39
- end
40
- end