inquisitio 1.2.4 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/inquisitio/search_url_builder.rb +2 -0
- data/lib/inquisitio/searcher.rb +9 -1
- data/lib/inquisitio/version.rb +1 -1
- data/test/test_searcher.rb +31 -10
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35812975d269869fb5fb249d158726a592ef548b
|
4
|
+
data.tar.gz: bb8169aaec4ec7c056c7acc8ec490ecd2babd242
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5cc4b3fd919ef34495ca4abc3fcfcc4c71b7da1caf36df2604ccec85e21150437c8edc4b93c8464bd84dceceb1e8f1afed2ae5eb998aab2fd40690d0ecd2d75
|
7
|
+
data.tar.gz: 99cb031e9cd75f5fa20f76b86477e09918d51fe394c4c5278756215e0d6cd8f76383ecac2ace084c5e9c8a9e9712817560ef42fd9a40eda6e615ed419924c7fb
|
data/CHANGELOG.md
CHANGED
@@ -12,6 +12,7 @@ module Inquisitio
|
|
12
12
|
@return_fields = options[:return_fields]
|
13
13
|
@size = options[:size] || Inquisitio.config.default_search_size
|
14
14
|
@start = options[:start] || 0
|
15
|
+
@sort = options[:sort] || {}
|
15
16
|
end
|
16
17
|
|
17
18
|
def build
|
@@ -22,6 +23,7 @@ module Inquisitio
|
|
22
23
|
components << arguments
|
23
24
|
components << "&size=#{@size}" unless @arguments[:size]
|
24
25
|
components << "&start=#{@start}" unless @arguments[:start] || @start == 0 || @start == '0'
|
26
|
+
components << '&sort=' + @sort.map {|k,v| "#{k}%20#{v}"}.join(',') unless @sort.empty?
|
25
27
|
components.join("")
|
26
28
|
end
|
27
29
|
|
data/lib/inquisitio/searcher.rb
CHANGED
@@ -16,7 +16,8 @@ module Inquisitio
|
|
16
16
|
per: 10,
|
17
17
|
page: 1,
|
18
18
|
returns: [],
|
19
|
-
with: {}
|
19
|
+
with: {},
|
20
|
+
sort: {}
|
20
21
|
}
|
21
22
|
@failed_attempts = 0
|
22
23
|
|
@@ -109,6 +110,12 @@ module Inquisitio
|
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
113
|
+
def sort(value)
|
114
|
+
clone do |s|
|
115
|
+
s.params[:sort].merge!(value)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
112
119
|
# Proxy everything to the results so that this this class
|
113
120
|
# transparently acts as an Array.
|
114
121
|
def method_missing(name, *args, &block)
|
@@ -157,6 +164,7 @@ module Inquisitio
|
|
157
164
|
arguments: params[:with],
|
158
165
|
size: params[:per],
|
159
166
|
start: params[:per] * (params[:page] - 1),
|
167
|
+
sort: params[:sort],
|
160
168
|
return_fields: return_fields
|
161
169
|
)
|
162
170
|
end
|
data/lib/inquisitio/version.rb
CHANGED
data/test/test_searcher.rb
CHANGED
@@ -4,6 +4,7 @@ module Inquisitio
|
|
4
4
|
|
5
5
|
class Elephant
|
6
6
|
attr_accessor :id, :name
|
7
|
+
|
7
8
|
def initialize(_id, _name)
|
8
9
|
@id, @name = _id, _name
|
9
10
|
end
|
@@ -11,6 +12,7 @@ module Inquisitio
|
|
11
12
|
|
12
13
|
class Giraffe
|
13
14
|
attr_accessor :id, :name
|
15
|
+
|
14
16
|
def initialize(_id, _name)
|
15
17
|
@id, @name = _id, _name
|
16
18
|
end
|
@@ -227,12 +229,12 @@ module Inquisitio
|
|
227
229
|
|
228
230
|
def test_with_saves_variable
|
229
231
|
searcher = Searcher.with(foo: 'bar')
|
230
|
-
assert_equal({foo:'bar'}, searcher.params[:with])
|
232
|
+
assert_equal({foo: 'bar'}, searcher.params[:with])
|
231
233
|
end
|
232
234
|
|
233
235
|
def test_with_appends_to_variable
|
234
236
|
searcher = Searcher.with(foo: 'bar').with(cat: 'dog')
|
235
|
-
assert_equal({foo:'bar', cat:'dog'}, searcher.params[:with])
|
237
|
+
assert_equal({foo: 'bar', cat: 'dog'}, searcher.params[:with])
|
236
238
|
end
|
237
239
|
|
238
240
|
def test_with_gets_correct_url
|
@@ -258,7 +260,7 @@ module Inquisitio
|
|
258
260
|
end
|
259
261
|
|
260
262
|
def test_search_raises_exception_when_excon_exception_thrown
|
261
|
-
Excon.stub({}, lambda { |_| raise Excon::Errors::Timeout})
|
263
|
+
Excon.stub({}, lambda { |_| raise Excon::Errors::Timeout })
|
262
264
|
|
263
265
|
searcher = Searcher.where('Star Wars')
|
264
266
|
searcher.instance_variable_set(:@failed_attempts, 3)
|
@@ -280,21 +282,21 @@ module Inquisitio
|
|
280
282
|
def test_that_iterating_calls_results
|
281
283
|
searcher = Searcher.where("star_wars")
|
282
284
|
searcher.expects(results: [])
|
283
|
-
searcher.each {
|
285
|
+
searcher.each {}
|
284
286
|
end
|
285
287
|
|
286
288
|
def test_that_iterating_calls_each
|
287
289
|
searcher = Searcher.where("star_wars")
|
288
290
|
searcher.search
|
289
291
|
searcher.send(:results).expects(:each)
|
290
|
-
searcher.each {
|
292
|
+
searcher.each {}
|
291
293
|
end
|
292
294
|
|
293
295
|
def test_that_select_calls_each
|
294
296
|
searcher = Searcher.where("star_wars")
|
295
297
|
searcher.search
|
296
298
|
searcher.send(:results).expects(:select)
|
297
|
-
searcher.select {
|
299
|
+
searcher.select {}
|
298
300
|
end
|
299
301
|
|
300
302
|
def test_search_should_set_results
|
@@ -331,7 +333,7 @@ module Inquisitio
|
|
331
333
|
|
332
334
|
def test_should_return_ids
|
333
335
|
searcher = Searcher.where('Star Wars')
|
334
|
-
assert_equal [1,2,20], searcher.ids
|
336
|
+
assert_equal [1, 2, 20], searcher.ids
|
335
337
|
end
|
336
338
|
|
337
339
|
def test_should_return_records_in_results_order
|
@@ -339,19 +341,38 @@ module Inquisitio
|
|
339
341
|
expected_2 = Giraffe.new(20, 'Wolf')
|
340
342
|
expected_3 = Elephant.new(1, 'Gobbolino')
|
341
343
|
|
342
|
-
Elephant.expects(:where).with(id: ['2','1']).returns([expected_3, expected_1])
|
344
|
+
Elephant.expects(:where).with(id: ['2', '1']).returns([expected_3, expected_1])
|
343
345
|
Giraffe.expects(:where).with(id: ['20']).returns([expected_2])
|
344
346
|
|
345
347
|
searcher = Searcher.new
|
346
348
|
result = [
|
347
|
-
{'data' => {'id' => ['2'],
|
349
|
+
{'data' => {'id' => ['2'], 'type' => ['Inquisitio_Elephant']}},
|
348
350
|
{'data' => {'id' => ['20'], 'type' => ['Inquisitio_Giraffe']}},
|
349
|
-
{'data' => {'id' => ['1'],
|
351
|
+
{'data' => {'id' => ['1'], 'type' => ['Inquisitio_Elephant']}}
|
350
352
|
]
|
351
353
|
searcher.instance_variable_set("@results", result)
|
352
354
|
expected_records = [expected_1, expected_2, expected_3]
|
353
355
|
actual_records = searcher.records
|
354
356
|
assert_equal expected_records, actual_records
|
355
357
|
end
|
358
|
+
|
359
|
+
def test_should_sort_field_ascending
|
360
|
+
searcher = Searcher.where('Star Wars').sort(year: :asc)
|
361
|
+
search_url = searcher.send(:search_url)
|
362
|
+
assert search_url.include?('sort=year%20asc'), "search url should include sort parameter:\n#{search_url}"
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_should_sort_field_descending
|
366
|
+
searcher = Searcher.where('Star Wars').sort(year: :desc)
|
367
|
+
search_url = searcher.send(:search_url)
|
368
|
+
assert search_url.include?('sort=year%20desc'), "search url should include sort parameter:\n#{search_url}"
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_should_sort_multiple_fields
|
372
|
+
searcher = Searcher.where('Star Wars').sort(year: :desc, foo: :asc)
|
373
|
+
search_url = searcher.send(:search_url)
|
374
|
+
assert search_url.include?('sort=year%20desc,foo%20asc'), "search url should include sort parameter:\n#{search_url}"
|
375
|
+
end
|
376
|
+
|
356
377
|
end
|
357
378
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inquisitio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-11-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: excon
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
164
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.
|
165
|
+
rubygems_version: 2.2.2
|
166
166
|
signing_key:
|
167
167
|
specification_version: 4
|
168
168
|
summary: This wraps AWS CloudSearch in a Ruby Gem
|