elasticsearch-model 6.0.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/README.md +14 -7
- data/Rakefile +27 -36
- data/elasticsearch-model.gemspec +1 -1
- data/examples/activerecord_mapping_completion.rb +2 -15
- data/gemfiles/3.0.gemfile +6 -1
- data/gemfiles/4.0.gemfile +7 -1
- data/gemfiles/5.0.gemfile +6 -0
- data/lib/elasticsearch/model.rb +15 -8
- data/lib/elasticsearch/model/adapters/active_record.rb +7 -26
- data/lib/elasticsearch/model/indexing.rb +5 -3
- data/lib/elasticsearch/model/naming.rb +6 -1
- data/lib/elasticsearch/model/response.rb +2 -2
- data/lib/elasticsearch/model/response/pagination.rb +2 -192
- data/lib/elasticsearch/model/response/pagination/kaminari.rb +109 -0
- data/lib/elasticsearch/model/response/pagination/will_paginate.rb +95 -0
- data/lib/elasticsearch/model/response/result.rb +1 -1
- data/lib/elasticsearch/model/version.rb +1 -1
- data/spec/elasticsearch/model/adapter_spec.rb +119 -0
- data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +334 -0
- data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +340 -0
- data/spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb +18 -0
- data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +187 -0
- data/spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb +110 -0
- data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +38 -0
- data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +315 -0
- data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +75 -0
- data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +61 -0
- data/spec/elasticsearch/model/adapters/active_record_spec.rb +207 -0
- data/spec/elasticsearch/model/adapters/default_spec.rb +41 -0
- data/spec/elasticsearch/model/adapters/mongoid/basic_spec.rb +267 -0
- data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +66 -0
- data/spec/elasticsearch/model/adapters/mongoid_spec.rb +235 -0
- data/spec/elasticsearch/model/adapters/multiple_spec.rb +125 -0
- data/spec/elasticsearch/model/callbacks_spec.rb +33 -0
- data/spec/elasticsearch/model/client_spec.rb +66 -0
- data/spec/elasticsearch/model/hash_wrapper_spec.rb +12 -0
- data/spec/elasticsearch/model/importing_spec.rb +214 -0
- data/spec/elasticsearch/model/indexing_spec.rb +918 -0
- data/spec/elasticsearch/model/module_spec.rb +101 -0
- data/spec/elasticsearch/model/multimodel_spec.rb +55 -0
- data/spec/elasticsearch/model/naming_inheritance_spec.rb +184 -0
- data/spec/elasticsearch/model/naming_spec.rb +186 -0
- data/spec/elasticsearch/model/proxy_spec.rb +107 -0
- data/spec/elasticsearch/model/response/aggregations_spec.rb +66 -0
- data/spec/elasticsearch/model/response/base_spec.rb +90 -0
- data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +410 -0
- data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +262 -0
- data/spec/elasticsearch/model/response/records_spec.rb +118 -0
- data/spec/elasticsearch/model/response/response_spec.rb +131 -0
- data/spec/elasticsearch/model/response/result_spec.rb +122 -0
- data/spec/elasticsearch/model/response/results_spec.rb +56 -0
- data/spec/elasticsearch/model/searching_search_request_spec.rb +112 -0
- data/spec/elasticsearch/model/searching_spec.rb +49 -0
- data/spec/elasticsearch/model/serializing_spec.rb +22 -0
- data/spec/spec_helper.rb +161 -0
- data/spec/support/app.rb +21 -0
- data/spec/support/app/answer.rb +33 -0
- data/spec/support/app/article.rb +22 -0
- data/spec/support/app/article_for_pagination.rb +12 -0
- data/spec/support/app/article_with_custom_serialization.rb +13 -0
- data/spec/support/app/article_with_dynamic_index_name.rb +15 -0
- data/spec/support/app/author.rb +9 -0
- data/spec/support/app/authorship.rb +4 -0
- data/spec/support/app/category.rb +3 -0
- data/spec/support/app/comment.rb +3 -0
- data/spec/support/app/episode.rb +11 -0
- data/spec/support/app/image.rb +19 -0
- data/spec/support/app/import_article.rb +12 -0
- data/spec/support/app/mongoid_article.rb +21 -0
- data/spec/support/app/namespaced_book.rb +10 -0
- data/spec/support/app/parent_and_child_searchable.rb +24 -0
- data/spec/support/app/post.rb +14 -0
- data/spec/support/app/question.rb +27 -0
- data/spec/support/app/searchable.rb +48 -0
- data/spec/support/app/series.rb +11 -0
- data/spec/support/model.json +1 -0
- data/{test → spec}/support/model.yml +0 -0
- metadata +129 -86
- data/test/integration/active_record_associations_parent_child_test.rb +0 -188
- data/test/integration/active_record_associations_test.rb +0 -339
- data/test/integration/active_record_basic_test.rb +0 -255
- data/test/integration/active_record_custom_serialization_test.rb +0 -67
- data/test/integration/active_record_import_test.rb +0 -168
- data/test/integration/active_record_namespaced_model_test.rb +0 -56
- data/test/integration/active_record_pagination_test.rb +0 -149
- data/test/integration/dynamic_index_name_test.rb +0 -52
- data/test/integration/mongoid_basic_test.rb +0 -240
- data/test/integration/multiple_models_test.rb +0 -176
- data/test/support/model.json +0 -1
- data/test/test_helper.rb +0 -92
- data/test/unit/adapter_active_record_test.rb +0 -157
- data/test/unit/adapter_default_test.rb +0 -41
- data/test/unit/adapter_mongoid_test.rb +0 -161
- data/test/unit/adapter_multiple_test.rb +0 -106
- data/test/unit/adapter_test.rb +0 -69
- data/test/unit/callbacks_test.rb +0 -31
- data/test/unit/client_test.rb +0 -27
- data/test/unit/hash_wrapper_test.rb +0 -13
- data/test/unit/importing_test.rb +0 -224
- data/test/unit/indexing_test.rb +0 -720
- data/test/unit/module_test.rb +0 -68
- data/test/unit/multimodel_test.rb +0 -38
- data/test/unit/naming_inheritance_test.rb +0 -94
- data/test/unit/naming_test.rb +0 -103
- data/test/unit/proxy_test.rb +0 -98
- data/test/unit/response_aggregations_test.rb +0 -46
- data/test/unit/response_base_test.rb +0 -40
- data/test/unit/response_pagination_kaminari_test.rb +0 -433
- data/test/unit/response_pagination_will_paginate_test.rb +0 -398
- data/test/unit/response_records_test.rb +0 -91
- data/test/unit/response_result_test.rb +0 -90
- data/test/unit/response_results_test.rb +0 -34
- data/test/unit/response_test.rb +0 -104
- data/test/unit/searching_search_request_test.rb +0 -78
- data/test/unit/searching_test.rb +0 -41
- data/test/unit/serializing_test.rb +0 -17
@@ -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
|
@@ -1,433 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class Elasticsearch::Model::ResponsePaginationKaminariTest < Test::Unit::TestCase
|
4
|
-
class ModelClass
|
5
|
-
include ::Kaminari::ConfigurationMethods
|
6
|
-
|
7
|
-
def self.index_name; 'foo'; end
|
8
|
-
def self.document_type; 'bar'; end
|
9
|
-
end
|
10
|
-
|
11
|
-
RESPONSE = { 'took' => '5', 'timed_out' => false, '_shards' => {'one' => 'OK'},
|
12
|
-
'hits' => { 'total' => 100, 'hits' => (1..100).to_a.map { |i| { _id: i } } } }
|
13
|
-
|
14
|
-
context "Response pagination" do
|
15
|
-
|
16
|
-
setup do
|
17
|
-
@search = Elasticsearch::Model::Searching::SearchRequest.new ModelClass, '*'
|
18
|
-
@response = Elasticsearch::Model::Response::Response.new ModelClass, @search, RESPONSE
|
19
|
-
@response.klass.stubs(:client).returns mock('client')
|
20
|
-
end
|
21
|
-
|
22
|
-
should "have pagination methods" do
|
23
|
-
assert_respond_to @response, :page
|
24
|
-
assert_respond_to @response, :limit_value
|
25
|
-
assert_respond_to @response, :offset_value
|
26
|
-
assert_respond_to @response, :limit
|
27
|
-
assert_respond_to @response, :offset
|
28
|
-
assert_respond_to @response, :total_count
|
29
|
-
end
|
30
|
-
|
31
|
-
context "#page method" do
|
32
|
-
should "advance the from/size" do
|
33
|
-
@response.klass.client
|
34
|
-
.expects(:search)
|
35
|
-
.with do |definition|
|
36
|
-
assert_equal 25, definition[:from]
|
37
|
-
assert_equal 25, definition[:size]
|
38
|
-
true
|
39
|
-
end
|
40
|
-
.returns(RESPONSE)
|
41
|
-
|
42
|
-
assert_nil @response.search.definition[:from]
|
43
|
-
assert_nil @response.search.definition[:size]
|
44
|
-
|
45
|
-
@response.page(2).to_a
|
46
|
-
assert_equal 25, @response.search.definition[:from]
|
47
|
-
assert_equal 25, @response.search.definition[:size]
|
48
|
-
end
|
49
|
-
|
50
|
-
should "advance the from/size further" do
|
51
|
-
@response.klass.client
|
52
|
-
.expects(:search)
|
53
|
-
.with do |definition|
|
54
|
-
assert_equal 75, definition[:from]
|
55
|
-
assert_equal 25, definition[:size]
|
56
|
-
true
|
57
|
-
end
|
58
|
-
.returns(RESPONSE)
|
59
|
-
|
60
|
-
@response.page(4).to_a
|
61
|
-
assert_equal 75, @response.search.definition[:from]
|
62
|
-
assert_equal 25, @response.search.definition[:size]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "limit/offset readers" do
|
67
|
-
should "return the default" do
|
68
|
-
assert_equal Kaminari.config.default_per_page, @response.limit_value
|
69
|
-
assert_equal 0, @response.offset_value
|
70
|
-
end
|
71
|
-
|
72
|
-
should "return the value from URL parameters" do
|
73
|
-
search = Elasticsearch::Model::Searching::SearchRequest.new ModelClass, '*', size: 10, from: 50
|
74
|
-
@response = Elasticsearch::Model::Response::Response.new ModelClass, search, RESPONSE
|
75
|
-
|
76
|
-
assert_equal 10, @response.limit_value
|
77
|
-
assert_equal 50, @response.offset_value
|
78
|
-
end
|
79
|
-
|
80
|
-
should "ignore the value from request body" do
|
81
|
-
search = Elasticsearch::Model::Searching::SearchRequest.new ModelClass,
|
82
|
-
{ query: { match_all: {} }, from: 333, size: 999 }
|
83
|
-
@response = Elasticsearch::Model::Response::Response.new ModelClass, search, RESPONSE
|
84
|
-
|
85
|
-
assert_equal Kaminari.config.default_per_page, @response.limit_value
|
86
|
-
assert_equal 0, @response.offset_value
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "limit setter" do
|
91
|
-
setup do
|
92
|
-
@response.records
|
93
|
-
@response.results
|
94
|
-
end
|
95
|
-
|
96
|
-
should "set the values" do
|
97
|
-
@response.limit(35)
|
98
|
-
assert_equal 35, @response.search.definition[:size]
|
99
|
-
end
|
100
|
-
|
101
|
-
should "reset the variables" do
|
102
|
-
@response.limit(35)
|
103
|
-
|
104
|
-
assert_nil @response.instance_variable_get(:@response)
|
105
|
-
assert_nil @response.instance_variable_get(:@records)
|
106
|
-
assert_nil @response.instance_variable_get(:@results)
|
107
|
-
end
|
108
|
-
|
109
|
-
should 'coerce string parameters' do
|
110
|
-
@response.limit("35")
|
111
|
-
assert_equal 35, @response.search.definition[:size]
|
112
|
-
end
|
113
|
-
|
114
|
-
should 'ignore invalid string parameters' do
|
115
|
-
@response.limit(35)
|
116
|
-
@response.limit("asdf")
|
117
|
-
assert_equal 35, @response.search.definition[:size]
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "with the page() and limit() methods" do
|
122
|
-
setup do
|
123
|
-
@response.records
|
124
|
-
@response.results
|
125
|
-
end
|
126
|
-
|
127
|
-
should "set the values" do
|
128
|
-
@response.page(3).limit(35)
|
129
|
-
assert_equal 35, @response.search.definition[:size]
|
130
|
-
assert_equal 70, @response.search.definition[:from]
|
131
|
-
end
|
132
|
-
|
133
|
-
should "set the values when limit is called first" do
|
134
|
-
@response.limit(35).page(3)
|
135
|
-
assert_equal 35, @response.search.definition[:size]
|
136
|
-
assert_equal 70, @response.search.definition[:from]
|
137
|
-
end
|
138
|
-
|
139
|
-
should "reset the instance variables" do
|
140
|
-
@response.page(3).limit(35)
|
141
|
-
|
142
|
-
assert_nil @response.instance_variable_get(:@response)
|
143
|
-
assert_nil @response.instance_variable_get(:@records)
|
144
|
-
assert_nil @response.instance_variable_get(:@results)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context "offset setter" do
|
149
|
-
setup do
|
150
|
-
@response.records
|
151
|
-
@response.results
|
152
|
-
end
|
153
|
-
|
154
|
-
should "set the values" do
|
155
|
-
@response.offset(15)
|
156
|
-
assert_equal 15, @response.search.definition[:from]
|
157
|
-
end
|
158
|
-
|
159
|
-
should "reset the variables" do
|
160
|
-
@response.offset(35)
|
161
|
-
|
162
|
-
assert_nil @response.instance_variable_get(:@response)
|
163
|
-
assert_nil @response.instance_variable_get(:@records)
|
164
|
-
assert_nil @response.instance_variable_get(:@results)
|
165
|
-
end
|
166
|
-
|
167
|
-
should 'coerce string parameters' do
|
168
|
-
@response.offset("35")
|
169
|
-
assert_equal 35, @response.search.definition[:from]
|
170
|
-
end
|
171
|
-
|
172
|
-
should 'coerce invalid string parameters' do
|
173
|
-
@response.offset(35)
|
174
|
-
@response.offset("asdf")
|
175
|
-
assert_equal 0, @response.search.definition[:from]
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
context "total" do
|
180
|
-
should "return the number of hits" do
|
181
|
-
@response.expects(:results).returns(mock('results', total: 100))
|
182
|
-
assert_equal 100, @response.total_count
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context "results" do
|
187
|
-
setup do
|
188
|
-
@search.stubs(:execute!).returns RESPONSE
|
189
|
-
end
|
190
|
-
|
191
|
-
should "return current page and total count" do
|
192
|
-
assert_equal 1, @response.page(1).results.current_page
|
193
|
-
assert_equal 100, @response.results.total_count
|
194
|
-
|
195
|
-
assert_equal 5, @response.page(5).results.current_page
|
196
|
-
end
|
197
|
-
|
198
|
-
should "return previous page and next page" do
|
199
|
-
assert_equal nil, @response.page(1).results.prev_page
|
200
|
-
assert_equal 2, @response.page(1).results.next_page
|
201
|
-
|
202
|
-
assert_equal 3, @response.page(4).results.prev_page
|
203
|
-
assert_equal nil, @response.page(4).results.next_page
|
204
|
-
|
205
|
-
assert_equal 2, @response.page(3).results.prev_page
|
206
|
-
assert_equal 4, @response.page(3).results.next_page
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
context "records" do
|
211
|
-
setup do
|
212
|
-
@search.stubs(:execute!).returns RESPONSE
|
213
|
-
end
|
214
|
-
|
215
|
-
should "return current page and total count" do
|
216
|
-
assert_equal 1, @response.page(1).records.current_page
|
217
|
-
assert_equal 100, @response.records.total_count
|
218
|
-
|
219
|
-
assert_equal 5, @response.page(5).records.current_page
|
220
|
-
end
|
221
|
-
|
222
|
-
should "return previous page and next page" do
|
223
|
-
assert_equal nil, @response.page(1).records.prev_page
|
224
|
-
assert_equal 2, @response.page(1).records.next_page
|
225
|
-
|
226
|
-
assert_equal 3, @response.page(4).records.prev_page
|
227
|
-
assert_equal nil, @response.page(4).records.next_page
|
228
|
-
|
229
|
-
assert_equal 2, @response.page(3).records.prev_page
|
230
|
-
assert_equal 4, @response.page(3).records.next_page
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
context "Multimodel response pagination" do
|
236
|
-
setup do
|
237
|
-
@multimodel = Elasticsearch::Model::Multimodel.new(ModelClass)
|
238
|
-
@search = Elasticsearch::Model::Searching::SearchRequest.new @multimodel, '*'
|
239
|
-
@response = Elasticsearch::Model::Response::Response.new @multimodel, @search, RESPONSE
|
240
|
-
@response.klass.stubs(:client).returns mock('client')
|
241
|
-
end
|
242
|
-
|
243
|
-
should "have pagination methods" do
|
244
|
-
assert_respond_to @response, :page
|
245
|
-
assert_respond_to @response, :limit_value
|
246
|
-
assert_respond_to @response, :offset_value
|
247
|
-
assert_respond_to @response, :limit
|
248
|
-
assert_respond_to @response, :offset
|
249
|
-
assert_respond_to @response, :total_count
|
250
|
-
end
|
251
|
-
|
252
|
-
context "#page method" do
|
253
|
-
should "advance the from/size" do
|
254
|
-
@response.klass.client
|
255
|
-
.expects(:search)
|
256
|
-
.with do |definition|
|
257
|
-
assert_equal 25, definition[:from]
|
258
|
-
assert_equal 25, definition[:size]
|
259
|
-
true
|
260
|
-
end
|
261
|
-
.returns(RESPONSE)
|
262
|
-
|
263
|
-
assert_nil @response.search.definition[:from]
|
264
|
-
assert_nil @response.search.definition[:size]
|
265
|
-
|
266
|
-
@response.page(2).to_a
|
267
|
-
assert_equal 25, @response.search.definition[:from]
|
268
|
-
assert_equal 25, @response.search.definition[:size]
|
269
|
-
end
|
270
|
-
|
271
|
-
should "advance the from/size further" do
|
272
|
-
@response.klass.client
|
273
|
-
.expects(:search)
|
274
|
-
.with do |definition|
|
275
|
-
assert_equal 75, definition[:from]
|
276
|
-
assert_equal 25, definition[:size]
|
277
|
-
true
|
278
|
-
end
|
279
|
-
.returns(RESPONSE)
|
280
|
-
|
281
|
-
@response.page(4).to_a
|
282
|
-
assert_equal 75, @response.search.definition[:from]
|
283
|
-
assert_equal 25, @response.search.definition[:size]
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
context "limit/offset readers" do
|
288
|
-
should "return the default" do
|
289
|
-
assert_equal Kaminari.config.default_per_page, @response.limit_value
|
290
|
-
assert_equal 0, @response.offset_value
|
291
|
-
end
|
292
|
-
|
293
|
-
should "return the value from URL parameters" do
|
294
|
-
search = Elasticsearch::Model::Searching::SearchRequest.new ModelClass, '*', size: 10, from: 50
|
295
|
-
@response = Elasticsearch::Model::Response::Response.new ModelClass, search, RESPONSE
|
296
|
-
|
297
|
-
assert_equal 10, @response.limit_value
|
298
|
-
assert_equal 50, @response.offset_value
|
299
|
-
end
|
300
|
-
|
301
|
-
should "ignore the value from request body" do
|
302
|
-
search = Elasticsearch::Model::Searching::SearchRequest.new ModelClass,
|
303
|
-
{ query: { match_all: {} }, from: 333, size: 999 }
|
304
|
-
@response = Elasticsearch::Model::Response::Response.new ModelClass, search, RESPONSE
|
305
|
-
|
306
|
-
assert_equal Kaminari.config.default_per_page, @response.limit_value
|
307
|
-
assert_equal 0, @response.offset_value
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
context "limit setter" do
|
312
|
-
setup do
|
313
|
-
@response.records
|
314
|
-
@response.results
|
315
|
-
end
|
316
|
-
|
317
|
-
should "set the values" do
|
318
|
-
@response.limit(35)
|
319
|
-
assert_equal 35, @response.search.definition[:size]
|
320
|
-
end
|
321
|
-
|
322
|
-
should "reset the variables" do
|
323
|
-
@response.limit(35)
|
324
|
-
|
325
|
-
assert_nil @response.instance_variable_get(:@response)
|
326
|
-
assert_nil @response.instance_variable_get(:@records)
|
327
|
-
assert_nil @response.instance_variable_get(:@results)
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
context "with the page() and limit() methods" do
|
332
|
-
setup do
|
333
|
-
@response.records
|
334
|
-
@response.results
|
335
|
-
end
|
336
|
-
|
337
|
-
should "set the values" do
|
338
|
-
@response.page(3).limit(35)
|
339
|
-
assert_equal 35, @response.search.definition[:size]
|
340
|
-
assert_equal 70, @response.search.definition[:from]
|
341
|
-
end
|
342
|
-
|
343
|
-
should "set the values when limit is called first" do
|
344
|
-
@response.limit(35).page(3)
|
345
|
-
assert_equal 35, @response.search.definition[:size]
|
346
|
-
assert_equal 70, @response.search.definition[:from]
|
347
|
-
end
|
348
|
-
|
349
|
-
should "reset the instance variables" do
|
350
|
-
@response.page(3).limit(35)
|
351
|
-
|
352
|
-
assert_nil @response.instance_variable_get(:@response)
|
353
|
-
assert_nil @response.instance_variable_get(:@records)
|
354
|
-
assert_nil @response.instance_variable_get(:@results)
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
context "offset setter" do
|
359
|
-
setup do
|
360
|
-
@response.records
|
361
|
-
@response.results
|
362
|
-
end
|
363
|
-
|
364
|
-
should "set the values" do
|
365
|
-
@response.offset(15)
|
366
|
-
assert_equal 15, @response.search.definition[:from]
|
367
|
-
end
|
368
|
-
|
369
|
-
should "reset the variables" do
|
370
|
-
@response.offset(35)
|
371
|
-
|
372
|
-
assert_nil @response.instance_variable_get(:@response)
|
373
|
-
assert_nil @response.instance_variable_get(:@records)
|
374
|
-
assert_nil @response.instance_variable_get(:@results)
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
context "total" do
|
379
|
-
should "return the number of hits" do
|
380
|
-
@response.expects(:results).returns(mock('results', total: 100))
|
381
|
-
assert_equal 100, @response.total_count
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
context "results" do
|
386
|
-
setup do
|
387
|
-
@search.stubs(:execute!).returns RESPONSE
|
388
|
-
end
|
389
|
-
|
390
|
-
should "return current page and total count" do
|
391
|
-
assert_equal 1, @response.page(1).results.current_page
|
392
|
-
assert_equal 100, @response.results.total_count
|
393
|
-
|
394
|
-
assert_equal 5, @response.page(5).results.current_page
|
395
|
-
end
|
396
|
-
|
397
|
-
should "return previous page and next page" do
|
398
|
-
assert_equal nil, @response.page(1).results.prev_page
|
399
|
-
assert_equal 2, @response.page(1).results.next_page
|
400
|
-
|
401
|
-
assert_equal 3, @response.page(4).results.prev_page
|
402
|
-
assert_equal nil, @response.page(4).results.next_page
|
403
|
-
|
404
|
-
assert_equal 2, @response.page(3).results.prev_page
|
405
|
-
assert_equal 4, @response.page(3).results.next_page
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
|
-
context "records" do
|
410
|
-
setup do
|
411
|
-
@search.stubs(:execute!).returns RESPONSE
|
412
|
-
end
|
413
|
-
|
414
|
-
should "return current page and total count" do
|
415
|
-
assert_equal 1, @response.page(1).records.current_page
|
416
|
-
assert_equal 100, @response.records.total_count
|
417
|
-
|
418
|
-
assert_equal 5, @response.page(5).records.current_page
|
419
|
-
end
|
420
|
-
|
421
|
-
should "return previous page and next page" do
|
422
|
-
assert_equal nil, @response.page(1).records.prev_page
|
423
|
-
assert_equal 2, @response.page(1).records.next_page
|
424
|
-
|
425
|
-
assert_equal 3, @response.page(4).records.prev_page
|
426
|
-
assert_equal nil, @response.page(4).records.next_page
|
427
|
-
|
428
|
-
assert_equal 2, @response.page(3).records.prev_page
|
429
|
-
assert_equal 4, @response.page(3).records.next_page
|
430
|
-
end
|
431
|
-
end
|
432
|
-
end
|
433
|
-
end
|