elasticsearch-model 6.1.1 → 7.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/Gemfile +17 -0
  4. data/LICENSE.txt +199 -10
  5. data/README.md +17 -16
  6. data/Rakefile +18 -1
  7. data/elasticsearch-model.gemspec +19 -2
  8. data/examples/activerecord_article.rb +17 -0
  9. data/examples/activerecord_associations.rb +17 -0
  10. data/examples/activerecord_custom_analyzer.rb +17 -0
  11. data/examples/activerecord_mapping_completion.rb +17 -0
  12. data/examples/activerecord_mapping_edge_ngram.rb +17 -0
  13. data/examples/couchbase_article.rb +17 -0
  14. data/examples/datamapper_article.rb +17 -0
  15. data/examples/mongoid_article.rb +17 -0
  16. data/examples/ohm_article.rb +17 -0
  17. data/examples/riak_article.rb +17 -0
  18. data/gemfiles/3.0.gemfile +18 -1
  19. data/gemfiles/4.0.gemfile +20 -4
  20. data/gemfiles/5.0.gemfile +18 -1
  21. data/gemfiles/6.0.gemfile +21 -3
  22. data/lib/elasticsearch/model.rb +25 -15
  23. data/lib/elasticsearch/model/adapter.rb +17 -0
  24. data/lib/elasticsearch/model/adapters/active_record.rb +18 -1
  25. data/lib/elasticsearch/model/adapters/default.rb +17 -0
  26. data/lib/elasticsearch/model/adapters/mongoid.rb +17 -0
  27. data/lib/elasticsearch/model/adapters/multiple.rb +29 -4
  28. data/lib/elasticsearch/model/callbacks.rb +17 -0
  29. data/lib/elasticsearch/model/client.rb +17 -0
  30. data/lib/elasticsearch/model/ext/active_record.rb +17 -0
  31. data/lib/elasticsearch/model/hash_wrapper.rb +17 -0
  32. data/lib/elasticsearch/model/importing.rb +17 -0
  33. data/lib/elasticsearch/model/indexing.rb +29 -8
  34. data/lib/elasticsearch/model/multimodel.rb +17 -0
  35. data/lib/elasticsearch/model/naming.rb +19 -10
  36. data/lib/elasticsearch/model/proxy.rb +17 -0
  37. data/lib/elasticsearch/model/response.rb +17 -0
  38. data/lib/elasticsearch/model/response/aggregations.rb +17 -0
  39. data/lib/elasticsearch/model/response/base.rb +22 -1
  40. data/lib/elasticsearch/model/response/pagination.rb +17 -0
  41. data/lib/elasticsearch/model/response/pagination/kaminari.rb +17 -0
  42. data/lib/elasticsearch/model/response/pagination/will_paginate.rb +17 -0
  43. data/lib/elasticsearch/model/response/records.rb +17 -0
  44. data/lib/elasticsearch/model/response/result.rb +17 -0
  45. data/lib/elasticsearch/model/response/results.rb +17 -0
  46. data/lib/elasticsearch/model/response/suggestions.rb +17 -0
  47. data/lib/elasticsearch/model/searching.rb +17 -0
  48. data/lib/elasticsearch/model/serializing.rb +17 -0
  49. data/lib/elasticsearch/model/version.rb +18 -1
  50. data/spec/elasticsearch/model/adapter_spec.rb +17 -0
  51. data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +17 -0
  52. data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +281 -226
  53. data/spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb +17 -0
  54. data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +17 -0
  55. data/spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb +17 -0
  56. data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +18 -1
  57. data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +17 -0
  58. data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +18 -1
  59. data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +17 -0
  60. data/spec/elasticsearch/model/adapters/active_record_spec.rb +17 -0
  61. data/spec/elasticsearch/model/adapters/default_spec.rb +17 -0
  62. data/spec/elasticsearch/model/adapters/mongoid/basic_spec.rb +17 -0
  63. data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +17 -0
  64. data/spec/elasticsearch/model/adapters/mongoid_spec.rb +17 -0
  65. data/spec/elasticsearch/model/adapters/multiple_spec.rb +17 -0
  66. data/spec/elasticsearch/model/callbacks_spec.rb +17 -0
  67. data/spec/elasticsearch/model/client_spec.rb +17 -0
  68. data/spec/elasticsearch/model/hash_wrapper_spec.rb +17 -0
  69. data/spec/elasticsearch/model/importing_spec.rb +17 -0
  70. data/spec/elasticsearch/model/indexing_spec.rb +108 -12
  71. data/spec/elasticsearch/model/module_spec.rb +17 -25
  72. data/spec/elasticsearch/model/multimodel_spec.rb +17 -0
  73. data/spec/elasticsearch/model/naming_inheritance_spec.rb +82 -143
  74. data/spec/elasticsearch/model/naming_spec.rb +22 -5
  75. data/spec/elasticsearch/model/proxy_spec.rb +17 -0
  76. data/spec/elasticsearch/model/response/aggregations_spec.rb +17 -0
  77. data/spec/elasticsearch/model/response/base_spec.rb +17 -0
  78. data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +85 -23
  79. data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +17 -0
  80. data/spec/elasticsearch/model/response/records_spec.rb +17 -0
  81. data/spec/elasticsearch/model/response/response_spec.rb +17 -0
  82. data/spec/elasticsearch/model/response/result_spec.rb +17 -0
  83. data/spec/elasticsearch/model/response/results_spec.rb +17 -0
  84. data/spec/elasticsearch/model/searching_search_request_spec.rb +17 -0
  85. data/spec/elasticsearch/model/searching_spec.rb +17 -0
  86. data/spec/elasticsearch/model/serializing_spec.rb +17 -0
  87. data/spec/spec_helper.rb +18 -0
  88. data/spec/support/app.rb +18 -0
  89. data/spec/support/app/answer.rb +17 -0
  90. data/spec/support/app/article.rb +17 -0
  91. data/spec/support/app/article_for_pagination.rb +17 -0
  92. data/spec/support/app/article_no_type.rb +37 -0
  93. data/spec/support/app/article_with_custom_serialization.rb +17 -0
  94. data/spec/support/app/article_with_dynamic_index_name.rb +17 -0
  95. data/spec/support/app/author.rb +17 -0
  96. data/spec/support/app/authorship.rb +17 -0
  97. data/spec/support/app/category.rb +17 -0
  98. data/spec/support/app/comment.rb +17 -0
  99. data/spec/support/app/episode.rb +17 -0
  100. data/spec/support/app/image.rb +17 -0
  101. data/spec/support/app/import_article.rb +17 -0
  102. data/spec/support/app/mongoid_article.rb +17 -0
  103. data/spec/support/app/namespaced_book.rb +17 -0
  104. data/spec/support/app/parent_and_child_searchable.rb +21 -4
  105. data/spec/support/app/post.rb +17 -0
  106. data/spec/support/app/question.rb +17 -0
  107. data/spec/support/app/searchable.rb +17 -0
  108. data/spec/support/app/series.rb +17 -0
  109. metadata +12 -10
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model do
@@ -72,30 +89,5 @@ describe Elasticsearch::Model do
72
89
  expect(Elasticsearch::Model.settings[:foo]).to eq('bar')
73
90
  end
74
91
  end
75
-
76
- context 'when \'inheritance_enabled\' is set' do
77
-
78
- around do |example|
79
- original_value = Elasticsearch::Model.settings[:inheritance_enabled]
80
- example.run
81
- Elasticsearch::Model.settings[:inheritance_enabled] = original_value
82
- end
83
-
84
- context 'when \'inheritance_enabled\' is true' do
85
-
86
- it 'warns with a deprecation message' do
87
- expect(Elasticsearch::Model).to receive(:warn)
88
- Elasticsearch::Model.inheritance_enabled = true
89
- end
90
- end
91
-
92
- context 'when \'inheritance_enabled\' is false' do
93
-
94
- it 'does not warn' do
95
- expect(Elasticsearch::Model).not_to receive(:warn)
96
- Elasticsearch::Model.inheritance_enabled = false
97
- end
98
- end
99
- end
100
92
  end
101
93
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model::Multimodel do
@@ -1,184 +1,123 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe 'naming inheritance' do
4
21
 
5
- context 'without using proxy' do
6
- before(:all) do
7
- TestBase = Class.new do
8
- extend ActiveModel::Naming
9
-
10
- extend Elasticsearch::Model::Naming::ClassMethods
11
- include Elasticsearch::Model::Naming::InstanceMethods
12
- end
13
-
14
- Animal = Class.new TestBase do
15
- extend ActiveModel::Naming
16
-
17
- extend Elasticsearch::Model::Naming::ClassMethods
18
- include Elasticsearch::Model::Naming::InstanceMethods
19
-
20
- index_name "mammals"
21
- document_type "mammal"
22
- end
23
-
24
- Dog = Class.new Animal
25
-
26
- module ::MyNamespace
27
- Dog = Class.new Animal
28
- end
29
-
30
- Cat = Class.new Animal do
31
- extend ActiveModel::Naming
22
+ before(:all) do
23
+ class ::TestBase
24
+ extend ActiveModel::Naming
32
25
 
33
- extend Elasticsearch::Model::Naming::ClassMethods
34
- include Elasticsearch::Model::Naming::InstanceMethods
26
+ extend Elasticsearch::Model::Naming::ClassMethods
27
+ include Elasticsearch::Model::Naming::InstanceMethods
28
+ end
35
29
 
36
- index_name "cats"
37
- document_type "cat"
38
- end
30
+ class ::Animal < ::TestBase
31
+ extend ActiveModel::Naming
39
32
 
40
- end
33
+ extend Elasticsearch::Model::Naming::ClassMethods
34
+ include Elasticsearch::Model::Naming::InstanceMethods
41
35
 
42
- after(:all) do
43
- remove_classes(TestBase, Animal, MyNamespace, Cat)
36
+ index_name "mammals"
37
+ document_type "mammal"
44
38
  end
45
39
 
46
- around(:all) do |example|
47
- original_value = Elasticsearch::Model.inheritance_enabled
48
- Elasticsearch::Model.inheritance_enabled = true
49
- example.run
50
- Elasticsearch::Model.inheritance_enabled = original_value
40
+ class ::Dog < ::Animal
51
41
  end
52
42
 
53
- describe '#index_name' do
54
-
55
- it 'returns the default index name' do
56
- expect(TestBase.index_name).to eq('test_bases')
57
- expect(TestBase.new.index_name).to eq('test_bases')
58
- end
59
-
60
- it 'returns the explicit index name' do
61
- expect(Animal.index_name).to eq('mammals')
62
- expect(Animal.new.index_name).to eq('mammals')
63
-
64
- expect(Cat.index_name).to eq('cats')
65
- expect(Cat.new.index_name).to eq('cats')
66
- end
67
-
68
- it 'returns the ancestor index name' do
69
- expect(Dog.index_name).to eq('mammals')
70
- expect(Dog.new.index_name).to eq('mammals')
71
- end
72
-
73
- it 'returns the ancestor index name for namespaced models' do
74
- expect(::MyNamespace::Dog.index_name).to eq('mammals')
75
- expect(::MyNamespace::Dog.new.index_name).to eq('mammals')
43
+ module ::MyNamespace
44
+ class Dog < ::Animal
76
45
  end
77
46
  end
78
47
 
79
- describe '#document_type' do
80
-
81
- it 'returns nil' do
82
- expect(TestBase.document_type).to eq('_doc')
83
- expect(TestBase.new.document_type).to eq('_doc')
84
- end
48
+ class ::Cat < ::Animal
49
+ extend ActiveModel::Naming
85
50
 
86
- it 'returns the explicit document type' do
87
- expect(Animal.document_type).to eq('mammal')
88
- expect(Animal.new.document_type).to eq('mammal')
51
+ extend Elasticsearch::Model::Naming::ClassMethods
52
+ include Elasticsearch::Model::Naming::InstanceMethods
89
53
 
90
- expect(Cat.document_type).to eq('cat')
91
- expect(Cat.new.document_type).to eq('cat')
92
- end
54
+ index_name "cats"
55
+ document_type "cat"
56
+ end
93
57
 
94
- it 'returns the ancestor document type' do
95
- expect(Dog.document_type).to eq('mammal')
96
- expect(Dog.new.document_type).to eq('mammal')
97
- end
58
+ end
98
59
 
99
- it 'returns the ancestor document type for namespaced models' do
100
- expect(::MyNamespace::Dog.document_type).to eq('mammal')
101
- expect(::MyNamespace::Dog.new.document_type).to eq('mammal')
102
- end
103
- end
60
+ after(:all) do
61
+ remove_classes(TestBase, Animal, MyNamespace, Cat)
104
62
  end
105
63
 
106
- context 'when using proxy' do
107
- before(:all) do
108
- TestBase = Class.new do
109
- extend ActiveModel::Naming
64
+ around(:all) do |example|
65
+ original_value = Elasticsearch::Model.settings[:inheritance_enabled]
66
+ Elasticsearch::Model.settings[:inheritance_enabled] = true
67
+ example.run
68
+ Elasticsearch::Model.settings[:inheritance_enabled] = original_value
69
+ end
110
70
 
111
- include Elasticsearch::Model
112
- end
113
71
 
114
- Animal = Class.new TestBase do
115
- index_name "mammals"
116
- document_type "mammal"
117
- end
72
+ describe '#index_name' do
118
73
 
119
- Dog = Class.new Animal
74
+ it 'returns the default index name' do
75
+ expect(TestBase.index_name).to eq('test_bases')
76
+ expect(TestBase.new.index_name).to eq('test_bases')
77
+ end
120
78
 
121
- module MyNamespace
122
- Dog = Class.new Animal
123
- end
79
+ it 'returns the explicit index name' do
80
+ expect(Animal.index_name).to eq('mammals')
81
+ expect(Animal.new.index_name).to eq('mammals')
124
82
 
125
- Cat = Class.new Animal do
126
- index_name "cats"
127
- document_type "cat"
128
- end
83
+ expect(Cat.index_name).to eq('cats')
84
+ expect(Cat.new.index_name).to eq('cats')
129
85
  end
130
86
 
131
- after(:all) do
132
- remove_classes(TestBase, Animal, MyNamespace, Cat)
87
+ it 'returns the ancestor index name' do
88
+ expect(Dog.index_name).to eq('mammals')
89
+ expect(Dog.new.index_name).to eq('mammals')
133
90
  end
134
91
 
135
- around(:all) do |example|
136
- original_value = Elasticsearch::Model.settings[:inheritance_enabled]
137
- Elasticsearch::Model.settings[:inheritance_enabled] = true
138
- example.run
139
- Elasticsearch::Model.settings[:inheritance_enabled] = original_value
92
+ it 'returns the ancestor index name for namespaced models' do
93
+ expect(::MyNamespace::Dog.index_name).to eq('mammals')
94
+ expect(::MyNamespace::Dog.new.index_name).to eq('mammals')
140
95
  end
96
+ end
141
97
 
142
- describe '#index_name' do
143
-
144
- it 'returns the default index name' do
145
- expect(TestBase.index_name).to eq('test_bases')
146
- end
147
-
148
- it 'returns the explicit index name' do
149
- expect(Animal.index_name).to eq('mammals')
150
-
151
- expect(Cat.index_name).to eq('cats')
152
- end
153
-
154
- it 'returns the ancestor index name' do
155
- expect(Dog.index_name).to eq('mammals')
156
- end
98
+ describe '#document_type' do
157
99
 
158
- it 'returns the ancestor index name for namespaced models' do
159
- expect(::MyNamespace::Dog.index_name).to eq('mammals')
160
- end
100
+ it 'returns nil' do
101
+ expect(TestBase.document_type).to be_nil
102
+ expect(TestBase.new.document_type).to be_nil
161
103
  end
162
104
 
163
- describe '#document_type' do
164
-
165
- it 'returns nil' do
166
- expect(TestBase.document_type).to eq('_doc')
167
- end
105
+ it 'returns the explicit document type' do
106
+ expect(Animal.document_type).to eq('mammal')
107
+ expect(Animal.new.document_type).to eq('mammal')
168
108
 
169
- it 'returns the explicit document type' do
170
- expect(Animal.document_type).to eq('mammal')
171
-
172
- expect(Cat.document_type).to eq('cat')
173
- end
109
+ expect(Cat.document_type).to eq('cat')
110
+ expect(Cat.new.document_type).to eq('cat')
111
+ end
174
112
 
175
- it 'returns the ancestor document type' do
176
- expect(Dog.document_type).to eq('mammal')
177
- end
113
+ it 'returns the ancestor document type' do
114
+ expect(Dog.document_type).to eq('mammal')
115
+ expect(Dog.new.document_type).to eq('mammal')
116
+ end
178
117
 
179
- it 'returns the ancestor document type for namespaced models' do
180
- expect(::MyNamespace::Dog.document_type).to eq('mammal')
181
- end
118
+ it 'returns the ancestor document type for namespaced models' do
119
+ expect(::MyNamespace::Dog.document_type).to eq('mammal')
120
+ expect(::MyNamespace::Dog.new.document_type).to eq('mammal')
182
121
  end
183
122
  end
184
123
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe 'naming' do
@@ -34,9 +51,9 @@ describe 'naming' do
34
51
  expect(::MyNamespace::DummyNamingModelInNamespace.new.index_name).to eq('my_namespace-dummy_naming_model_in_namespaces')
35
52
  end
36
53
 
37
- it 'returns the document type' do
38
- expect(DummyNamingModel.document_type).to eq('_doc')
39
- expect(DummyNamingModel.new.document_type).to eq('_doc')
54
+ it 'returns nil' do
55
+ expect(DummyNamingModel.document_type).to be_nil
56
+ expect(DummyNamingModel.new.document_type).to be_nil
40
57
  end
41
58
 
42
59
  describe '#index_name' do
@@ -124,8 +141,8 @@ describe 'naming' do
124
141
 
125
142
  describe '#document_type' do
126
143
 
127
- it 'returns the document type' do
128
- expect(DummyNamingModel.document_type).to eq('_doc')
144
+ it 'returns nil' do
145
+ expect(DummyNamingModel.document_type).to be_nil
129
146
  end
130
147
 
131
148
  context 'when the method is called with an argument' do
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model::Proxy do
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model::Response::Aggregations do
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe Elasticsearch::Model::Response::Base do
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  require 'spec_helper'
2
19
 
3
20
  describe 'Elasticsearch::Model::Response::Response Kaminari' do
@@ -14,11 +31,6 @@ describe 'Elasticsearch::Model::Response::Response Kaminari' do
14
31
  remove_classes(ModelClass)
15
32
  end
16
33
 
17
- let(:response_document) do
18
- { 'took' => '5', 'timed_out' => false, '_shards' => {'one' => 'OK'},
19
- 'hits' => { 'total' => 100, 'hits' => (1..100).to_a.map { |i| { _id: i } } } }
20
- end
21
-
22
34
  let(:search) do
23
35
  Elasticsearch::Model::Searching::SearchRequest.new(model, '*')
24
36
  end
@@ -374,37 +386,87 @@ describe 'Elasticsearch::Model::Response::Response Kaminari' do
374
386
  end
375
387
  end
376
388
 
377
- context 'when the model is a single one' do
389
+ context 'when Elasticsearch version is < 7.0' do
378
390
 
379
- let(:model) do
380
- ModelClass
391
+ let(:response_document) do
392
+ { 'took' => '5', 'timed_out' => false, '_shards' => {'one' => 'OK'},
393
+ 'hits' => { 'total' => 100, 'hits' => (1..100).to_a.map { |i| { _id: i } } } }
381
394
  end
382
395
 
383
- let(:type_field) do
384
- 'bar'
385
- end
396
+ context 'when the model is a single one' do
386
397
 
387
- let(:index_field) do
388
- 'foo'
398
+ let(:model) do
399
+ ModelClass
400
+ end
401
+
402
+ let(:type_field) do
403
+ 'bar'
404
+ end
405
+
406
+ let(:index_field) do
407
+ 'foo'
408
+ end
409
+
410
+ it_behaves_like 'a search request that can be paginated'
389
411
  end
390
412
 
391
- it_behaves_like 'a search request that can be paginated'
392
- end
413
+ context 'when the model is a multimodel' do
414
+
415
+ let(:model) do
416
+ Elasticsearch::Model::Multimodel.new(ModelClass)
417
+ end
393
418
 
394
- context 'when the model is a multimodel' do
419
+ let(:type_field) do
420
+ ['bar']
421
+ end
422
+
423
+ let(:index_field) do
424
+ ['foo']
425
+ end
395
426
 
396
- let(:model) do
397
- Elasticsearch::Model::Multimodel.new(ModelClass)
427
+ it_behaves_like 'a search request that can be paginated'
398
428
  end
429
+ end
399
430
 
400
- let(:type_field) do
401
- ['bar']
431
+ context 'when Elasticsearch version is >= 7.0' do
432
+
433
+ let(:response_document) do
434
+ { 'took' => '5', 'timed_out' => false, '_shards' => {'one' => 'OK'},
435
+ 'hits' => { 'total' => { 'value' => 100, 'relation' => 'eq' }, 'hits' => (1..100).to_a.map { |i| { _id: i } } } }
402
436
  end
403
437
 
404
- let(:index_field) do
405
- ['foo']
438
+ context 'when the model is a single one' do
439
+
440
+ let(:model) do
441
+ ModelClass
442
+ end
443
+
444
+ let(:type_field) do
445
+ 'bar'
446
+ end
447
+
448
+ let(:index_field) do
449
+ 'foo'
450
+ end
451
+
452
+ it_behaves_like 'a search request that can be paginated'
406
453
  end
407
454
 
408
- it_behaves_like 'a search request that can be paginated'
455
+ context 'when the model is a multimodel' do
456
+
457
+ let(:model) do
458
+ Elasticsearch::Model::Multimodel.new(ModelClass)
459
+ end
460
+
461
+ let(:type_field) do
462
+ ['bar']
463
+ end
464
+
465
+ let(:index_field) do
466
+ ['foo']
467
+ end
468
+
469
+ it_behaves_like 'a search request that can be paginated'
470
+ end
409
471
  end
410
472
  end