filterable-by 0.6.1 → 0.6.2

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: e0b24315b28f7b165d4158fe6ef43860a346e342732ef53ffd02595bbd34e511
4
- data.tar.gz: 90b3ec26188bf9337758320f222730bfaf19f0b2525bfec8b25080f0c6d5f258
3
+ metadata.gz: a92cb2cde41910a93ed81348238f61031c3e5c8071ab2b118bfceb25307a8c14
4
+ data.tar.gz: 231b7712b1fe257b34ab63d8a3dc362304c45318984c3eb1a2c8cf004ef2ee44
5
5
  SHA512:
6
- metadata.gz: c84a6573838b6acd0f7c9136cfdd2853146edaff7dd9e9fb74967bd7dedce782a54ed800674489717ade4b6923d882de9f53ba4ad0ff3d7e8444807e925435a0
7
- data.tar.gz: 11aa00c16d9e85daab300757381e783d6006fa874d3a33a7f40a412c176a6ca75120cee413409a1434c59d33658443f2f3af68168abfaa99eb6287db29509ee6
6
+ metadata.gz: 8ca4f69341eaa58f296280b703398c5ce6ad1dcd6551758322c36a03db7f2b9af7e37defeb96c205a5a1520f40e154d4ebd2f5c6110591ccb1505f55f99ac870
7
+ data.tar.gz: 10691ed7dc8e33b7c6920e8a8e6e670b854bc51d6155baa0923d0cfe363ec2fb8824ed79f3cc635cc9b68f824e3c1951ea32cda8e320e0f40b5ad12fbfa37c2f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- filterable-by (0.6.1)
4
+ filterable-by (0.6.2)
5
5
  activerecord
6
6
  activesupport
7
7
 
@@ -19,12 +19,12 @@ GEM
19
19
  minitest (>= 5.1)
20
20
  tzinfo (~> 2.0)
21
21
  ast (2.4.2)
22
- concurrent-ruby (1.1.9)
22
+ concurrent-ruby (1.1.10)
23
23
  diff-lcs (1.5.0)
24
24
  i18n (1.10.0)
25
25
  concurrent-ruby (~> 1.0)
26
26
  minitest (5.15.0)
27
- parallel (1.21.0)
27
+ parallel (1.22.1)
28
28
  parser (3.1.1.0)
29
29
  ast (~> 2.4.1)
30
30
  rainbow (3.1.1)
@@ -40,11 +40,11 @@ GEM
40
40
  rspec-expectations (3.11.0)
41
41
  diff-lcs (>= 1.2.0, < 2.0)
42
42
  rspec-support (~> 3.11.0)
43
- rspec-mocks (3.11.0)
43
+ rspec-mocks (3.11.1)
44
44
  diff-lcs (>= 1.2.0, < 2.0)
45
45
  rspec-support (~> 3.11.0)
46
46
  rspec-support (3.11.0)
47
- rubocop (1.26.0)
47
+ rubocop (1.26.1)
48
48
  parallel (~> 1.10)
49
49
  parser (>= 3.1.0.0)
50
50
  rainbow (>= 2.2.2, < 4.0)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'filterable-by'
3
- s.version = '0.6.1'
3
+ s.version = '0.6.2'
4
4
  s.authors = ['Dimitrij Denissenko']
5
5
  s.email = ['dimitrij@blacksquaremedia.com']
6
6
  s.summary = 'Generate white-listed filter scopes from URL parameter values'
data/lib/filterable_by.rb CHANGED
@@ -58,7 +58,7 @@ module ActiveRecord
58
58
  end
59
59
 
60
60
  names.each do |name|
61
- _filterable_by_config[name.to_s] = block || ->(value, **) { where(name.to_sym => value) }
61
+ _filterable_by_config[name.to_s] = block
62
62
  end
63
63
  end
64
64
 
@@ -74,6 +74,7 @@ module ActiveRecord
74
74
  return scope unless hash.respond_to?(:key?) && hash.respond_to?(:[])
75
75
 
76
76
  _filterable_by_config.each do |name, block|
77
+ block = ->(value, **) { where(name.to_sym => value) } if block.nil?
77
78
  scope = FilterableBy.merge(scope, unscoped, hash, name, **opts, &block)
78
79
  break unless scope
79
80
  end
@@ -97,4 +97,8 @@ describe ActiveRecord::FilterableBy do
97
97
  expect(Comment.filter_by('deprecated_with_opts' => alice.id).pluck(:title)).to match_array(%w[AA AB])
98
98
  expect(Comment.filter_by('deprecated_not' => alice.id).pluck(:title)).to match_array(%w[BA BB])
99
99
  end
100
+
101
+ it 'supports abstract classes' do
102
+ expect(Post.filter_by('author_id' => bob.id).count).to eq(1)
103
+ end
100
104
  end
data/spec/spec_helper.rb CHANGED
@@ -25,10 +25,14 @@ class Author < ActiveRecord::Base
25
25
  has_many :posts
26
26
  end
27
27
 
28
- class Post < ActiveRecord::Base
28
+ class AbstractPost < ActiveRecord::Base
29
+ self.abstract_class = true
30
+ filterable_by :author_id
31
+ end
32
+
33
+ class Post < AbstractPost
29
34
  belongs_to :author
30
35
 
31
- filterable_by :author_id
32
36
  filterable_by :only do |value, **opts|
33
37
  case value
34
38
  when 'me'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filterable-by
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-11 00:00:00.000000000 Z
11
+ date: 2022-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord