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 +4 -4
- data/lib/rack/reducer.rb +1 -1
- data/lib/rack/reducer/refinements.rb +2 -2
- data/lib/rack/reducer/version.rb +1 -1
- data/spec/fixtures.rb +7 -3
- data/spec/rails_spec.rb +10 -0
- data/spec/reducer_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e312a258354056f9bef8a2f93b29a9e3e4c31a0b23da64e62c0af818635e625e
|
4
|
+
data.tar.gz: a59b978264b8b389d8a8c37b430fa6bb84c22265c1d324d9f3196cee706ce93d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5982daa61e38075b2c69f8e3e8353d6ad59c49dbcfa28c27fe2ddb2abd76061d6d299df0e75ee201dbf16420716bf45814571ace71dba44d7339e15e44f173ec
|
7
|
+
data.tar.gz: 18edac04f31cb923cb6dbf4ee9592cf85cd6a52aab2da679aa398e8340d0c0109842751f5dcfd9852d63172ad95b13472ce03920097d901100c8bec146c824f5
|
data/lib/rack/reducer.rb
CHANGED
@@ -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.
|
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
|
32
|
+
def deep_symbolize_keys
|
33
33
|
each_with_object({}) do |(key, val), hash|
|
34
|
-
hash[key.to_sym] = val.is_a?(Hash) ? val.
|
34
|
+
hash[key.to_sym] = val.is_a?(Hash) ? val.deep_symbolize_keys : val
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
data/lib/rack/reducer/version.rb
CHANGED
data/spec/fixtures.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Fixtures
|
2
2
|
DB = {
|
3
3
|
artists: [
|
4
|
-
{ name: 'Blake Mills', genre: 'alternative', release_count:
|
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:
|
8
|
-
{ name: 'SZA', genre: 'alt-soul', release_count:
|
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)
|
data/spec/rails_spec.rb
CHANGED
@@ -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
|
data/spec/reducer_spec.rb
CHANGED
@@ -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 '
|
132
|
-
get('/artists?
|
133
|
-
expect(response.
|
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.
|
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-
|
11
|
+
date: 2019-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|