rack-reducer 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c069005f0502425e332cd99bb9b27d11ab257baa937be74ce96b120e6af1cb70
4
- data.tar.gz: 7c818a942e2d5b6fe50aa6832c74d11592d76e16d6cd92d31aeb4bc608092a3e
3
+ metadata.gz: e312a258354056f9bef8a2f93b29a9e3e4c31a0b23da64e62c0af818635e625e
4
+ data.tar.gz: a59b978264b8b389d8a8c37b430fa6bb84c22265c1d324d9f3196cee706ce93d
5
5
  SHA512:
6
- metadata.gz: 3db32664cc591ecb2efa31d9bb39a4c3efb321e21a8fcabd5355416b7fca771ef9c2c90be57913f9b44bad100c95900e0ca8e2b14fcf3931f32cad8d70cd62e8
7
- data.tar.gz: fc199821f33b07ae4f3684dd2f56367d89415bd16385ae6bb383df220e4266564ca8d6092443dea1bafbb50378660d173caceef36dd3f3c17d4afe52f7da81fa
6
+ metadata.gz: 5982daa61e38075b2c69f8e3e8353d6ad59c49dbcfa28c27fe2ddb2abd76061d6d299df0e75ee201dbf16420716bf45814571ace71dba44d7339e15e44f173ec
7
+ data.tar.gz: 18edac04f31cb923cb6dbf4ee9592cf85cd6a52aab2da679aa398e8340d0c0109842751f5dcfd9852d63172ad95b13472ce03920097d901100c8bec146c824f5
@@ -57,7 +57,7 @@ module Rack
57
57
  filters, params = @default_filters, EMPTY_PARAMS
58
58
  else
59
59
  # This request really does want filtering; run a full reduction
60
- filters, params = @filters, url_params.to_unsafe_h.symbolize_keys
60
+ filters, params = @filters, url_params.to_unsafe_h.deep_symbolize_keys
61
61
  end
62
62
 
63
63
  reduce(params, filters)
@@ -29,9 +29,9 @@ module Rack
29
29
  end
30
30
 
31
31
  refine Hash do
32
- def symbolize_keys
32
+ def deep_symbolize_keys
33
33
  each_with_object({}) do |(key, val), hash|
34
- hash[key.to_sym] = val.is_a?(Hash) ? val.symbolize_keys : val
34
+ hash[key.to_sym] = val.is_a?(Hash) ? val.deep_symbolize_keys : val
35
35
  end
36
36
  end
37
37
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class Reducer
5
- VERSION = '2.0.2'
5
+ VERSION = '2.0.3'
6
6
  end
7
7
  end
@@ -1,11 +1,11 @@
1
1
  module Fixtures
2
2
  DB = {
3
3
  artists: [
4
- { name: 'Blake Mills', genre: 'alternative', release_count: 3 },
4
+ { name: 'Blake Mills', genre: 'alternative', release_count: 2 },
5
5
  { name: 'Björk', genre: 'electronic', release_count: 3 },
6
6
  { name: 'James Blake', genre: 'electronic', release_count: 3 },
7
- { name: 'Janelle Monae', genre: 'alt-soul', release_count: 3 },
8
- { name: 'SZA', genre: 'alt-soul', release_count: 3 },
7
+ { name: 'Janelle Monae', genre: 'alt-soul', release_count: 2 },
8
+ { name: 'SZA', genre: 'alt-soul', release_count: 1 },
9
9
  { name: 'Chris Frank', genre: 'alt-soul', release_count: nil },
10
10
  ]
11
11
  }
@@ -20,6 +20,10 @@ module Fixtures
20
20
  ->(releases:) {
21
21
  select { |item| item[:release_count].to_i == releases.to_i }
22
22
  },
23
+ ->(prolificacy:) {
24
+ range = prolificacy[:min].to_i..prolificacy[:max].to_i
25
+ select { |item| range.include? item[:release_count].to_i }
26
+ },
23
27
  ]
24
28
 
25
29
  ArtistReducer = Rack::Reducer.new(DB[:artists], *FILTERS)
@@ -38,6 +38,10 @@ Process.respond_to?(:fork) && RSpec.describe('in a Rails app') do
38
38
  Artist.all,
39
39
  ->(name:) { where('lower(name) like ?', "%#{name.downcase}%") },
40
40
  ->(genre:) { where(genre: genre) },
41
+ ->(prolificacy:) {
42
+ range = prolificacy[:min].to_i..prolificacy[:max].to_i
43
+ where(release_count: range)
44
+ },
41
45
  )
42
46
 
43
47
  def index
@@ -59,6 +63,9 @@ Process.respond_to?(:fork) && RSpec.describe('in a Rails app') do
59
63
  it 'works with ActionController::Parameters' do
60
64
  pid = Process.fork do
61
65
  get('/') { |res| expect(res.status).to eq(200) }
66
+ get('/?prolificacy[min]=2&prolificacy[max]=3') { |res|
67
+ expect(res.json.count).to eq(4)
68
+ }
62
69
  end
63
70
  Process.wait pid
64
71
  end
@@ -66,6 +73,9 @@ Process.respond_to?(:fork) && RSpec.describe('in a Rails app') do
66
73
  it 'works with request.query_parameters' do
67
74
  pid = Process.fork do
68
75
  get('/query') { |res| expect(res.status).to eq(200) }
76
+ get('/query?prolificacy[min]=2&prolificacy[max]=3') { |res|
77
+ expect(res.json.count).to eq(4)
78
+ }
69
79
  end
70
80
  Process.wait(pid)
71
81
  end
@@ -128,9 +128,9 @@ RSpec.describe 'Rack::Reducer' do
128
128
  expect(Rack::Reducer.create({}, -> { 'hi' })).to be_a(Rack::Reducer)
129
129
  end
130
130
 
131
- it 'accepts nested params' do
132
- get('/artists?range[min]=1&range[max]=100') do |response|
133
- expect(response.status).to eq(200)
131
+ it 'can filter by nested params' do
132
+ get('/artists?prolificacy[min]=2&prolificacy[max]=3') do |response|
133
+ expect(response.json.count).to eq(4)
134
134
  end
135
135
  end
136
136
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-reducer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-05 00:00:00.000000000 Z
11
+ date: 2019-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack