filterable-by 0.6.3 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/Gemfile +5 -0
- data/Gemfile.lock +46 -40
- data/Gemfile.rails6 +4 -0
- data/Gemfile.rails6.lock +45 -41
- data/filterable-by.gemspec +1 -7
- metadata +4 -78
- data/spec/active_record/filterable_by_spec.rb +0 -104
- data/spec/spec_helper.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c57b10c81d4b78878b5cdbfc68e2205b8cdb391e7cae8c73b9afa9db40df00e
|
4
|
+
data.tar.gz: 41b64f997571c523d6ae7bde2d90d4e23066f7cdf0a234090e7419231c0bdf50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 047cc3045205b8aa82c66331115b1917591bab4f2162be44d817a65636af5a823289a8407b120a0da622ad1da50f43d6a0fe2eeed3bc0cce04522fdee62ce424
|
7
|
+
data.tar.gz: 2448f827a7c2e69639b77ea030b9b6bee410b1afda68252e8c729d7ba6de79bff0f4ab0f8a6089e1dad0de4730eaa05f2fef87a6843e5562223d1ee4495a8ead
|
data/.github/workflows/test.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,83 +1,89 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
filterable-by (0.6.
|
4
|
+
filterable-by (0.6.5)
|
5
5
|
activerecord
|
6
6
|
activesupport
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (7.0.
|
12
|
-
activesupport (= 7.0.
|
13
|
-
activerecord (7.0.
|
14
|
-
activemodel (= 7.0.
|
15
|
-
activesupport (= 7.0.
|
16
|
-
activesupport (7.0.
|
11
|
+
activemodel (7.0.4.3)
|
12
|
+
activesupport (= 7.0.4.3)
|
13
|
+
activerecord (7.0.4.3)
|
14
|
+
activemodel (= 7.0.4.3)
|
15
|
+
activesupport (= 7.0.4.3)
|
16
|
+
activesupport (7.0.4.3)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 1.6, < 2)
|
19
19
|
minitest (>= 5.1)
|
20
20
|
tzinfo (~> 2.0)
|
21
21
|
ast (2.4.2)
|
22
|
-
concurrent-ruby (1.
|
22
|
+
concurrent-ruby (1.2.2)
|
23
23
|
diff-lcs (1.5.0)
|
24
|
-
i18n (1.
|
24
|
+
i18n (1.12.0)
|
25
25
|
concurrent-ruby (~> 1.0)
|
26
|
-
|
26
|
+
json (2.6.3)
|
27
|
+
mini_portile2 (2.8.1)
|
28
|
+
minitest (5.18.0)
|
27
29
|
parallel (1.22.1)
|
28
|
-
parser (3.1.1
|
30
|
+
parser (3.2.1.1)
|
29
31
|
ast (~> 2.4.1)
|
30
32
|
rainbow (3.1.1)
|
31
33
|
rake (13.0.6)
|
32
|
-
regexp_parser (2.
|
34
|
+
regexp_parser (2.7.0)
|
33
35
|
rexml (3.2.5)
|
34
|
-
rspec (3.
|
35
|
-
rspec-core (~> 3.
|
36
|
-
rspec-expectations (~> 3.
|
37
|
-
rspec-mocks (~> 3.
|
38
|
-
rspec-core (3.
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-expectations (3.
|
36
|
+
rspec (3.12.0)
|
37
|
+
rspec-core (~> 3.12.0)
|
38
|
+
rspec-expectations (~> 3.12.0)
|
39
|
+
rspec-mocks (~> 3.12.0)
|
40
|
+
rspec-core (3.12.1)
|
41
|
+
rspec-support (~> 3.12.0)
|
42
|
+
rspec-expectations (3.12.2)
|
41
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-mocks (3.
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-mocks (3.12.4)
|
44
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.
|
46
|
-
rspec-support (3.
|
47
|
-
rubocop (1.
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-support (3.12.0)
|
49
|
+
rubocop (1.48.1)
|
50
|
+
json (~> 2.3)
|
48
51
|
parallel (~> 1.10)
|
49
|
-
parser (>= 3.
|
52
|
+
parser (>= 3.2.0.0)
|
50
53
|
rainbow (>= 2.2.2, < 4.0)
|
51
54
|
regexp_parser (>= 1.8, < 3.0)
|
52
|
-
rexml
|
53
|
-
rubocop-ast (>= 1.
|
55
|
+
rexml (>= 3.2.5, < 4.0)
|
56
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
54
57
|
ruby-progressbar (~> 1.7)
|
55
|
-
unicode-display_width (>=
|
56
|
-
rubocop-ast (1.
|
57
|
-
parser (>= 3.
|
58
|
-
rubocop-bsm (0.6.
|
58
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
59
|
+
rubocop-ast (1.27.0)
|
60
|
+
parser (>= 3.2.1.0)
|
61
|
+
rubocop-bsm (0.6.1)
|
59
62
|
rubocop (~> 1.0)
|
60
63
|
rubocop-performance
|
61
64
|
rubocop-rake
|
62
65
|
rubocop-rspec
|
63
|
-
rubocop-
|
66
|
+
rubocop-capybara (2.17.1)
|
67
|
+
rubocop (~> 1.41)
|
68
|
+
rubocop-performance (1.16.0)
|
64
69
|
rubocop (>= 1.7.0, < 2.0)
|
65
70
|
rubocop-ast (>= 0.4.0)
|
66
71
|
rubocop-rake (0.6.0)
|
67
72
|
rubocop (~> 1.0)
|
68
|
-
rubocop-rspec (2.
|
69
|
-
rubocop (~> 1.
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
+
rubocop-rspec (2.19.0)
|
74
|
+
rubocop (~> 1.33)
|
75
|
+
rubocop-capybara (~> 2.17)
|
76
|
+
ruby-progressbar (1.13.0)
|
77
|
+
sqlite3 (1.6.1)
|
78
|
+
mini_portile2 (~> 2.8.0)
|
79
|
+
tzinfo (2.0.6)
|
73
80
|
concurrent-ruby (~> 1.0)
|
74
|
-
unicode-display_width (2.
|
81
|
+
unicode-display_width (2.4.2)
|
75
82
|
|
76
83
|
PLATFORMS
|
77
84
|
ruby
|
78
85
|
|
79
86
|
DEPENDENCIES
|
80
|
-
bundler
|
81
87
|
filterable-by!
|
82
88
|
rake
|
83
89
|
rspec
|
@@ -85,4 +91,4 @@ DEPENDENCIES
|
|
85
91
|
sqlite3
|
86
92
|
|
87
93
|
BUNDLED WITH
|
88
|
-
2.3.
|
94
|
+
2.3.9
|
data/Gemfile.rails6
CHANGED
data/Gemfile.rails6.lock
CHANGED
@@ -1,86 +1,90 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
filterable-by (0.6.
|
4
|
+
filterable-by (0.6.5)
|
5
5
|
activerecord
|
6
6
|
activesupport
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (6.1.
|
12
|
-
activesupport (= 6.1.
|
13
|
-
activerecord (6.1.
|
14
|
-
activemodel (= 6.1.
|
15
|
-
activesupport (= 6.1.
|
16
|
-
activesupport (6.1.
|
11
|
+
activemodel (6.1.7.3)
|
12
|
+
activesupport (= 6.1.7.3)
|
13
|
+
activerecord (6.1.7.3)
|
14
|
+
activemodel (= 6.1.7.3)
|
15
|
+
activesupport (= 6.1.7.3)
|
16
|
+
activesupport (6.1.7.3)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 1.6, < 2)
|
19
19
|
minitest (>= 5.1)
|
20
20
|
tzinfo (~> 2.0)
|
21
21
|
zeitwerk (~> 2.3)
|
22
22
|
ast (2.4.2)
|
23
|
-
concurrent-ruby (1.
|
23
|
+
concurrent-ruby (1.2.2)
|
24
24
|
diff-lcs (1.5.0)
|
25
|
-
i18n (1.
|
25
|
+
i18n (1.12.0)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
json (2.6.3)
|
28
|
+
minitest (5.18.0)
|
29
|
+
parallel (1.22.1)
|
30
|
+
parser (3.2.1.1)
|
30
31
|
ast (~> 2.4.1)
|
31
32
|
rainbow (3.1.1)
|
32
33
|
rake (13.0.6)
|
33
|
-
regexp_parser (2.
|
34
|
+
regexp_parser (2.7.0)
|
34
35
|
rexml (3.2.5)
|
35
|
-
rspec (3.
|
36
|
-
rspec-core (~> 3.
|
37
|
-
rspec-expectations (~> 3.
|
38
|
-
rspec-mocks (~> 3.
|
39
|
-
rspec-core (3.
|
40
|
-
rspec-support (~> 3.
|
41
|
-
rspec-expectations (3.
|
36
|
+
rspec (3.12.0)
|
37
|
+
rspec-core (~> 3.12.0)
|
38
|
+
rspec-expectations (~> 3.12.0)
|
39
|
+
rspec-mocks (~> 3.12.0)
|
40
|
+
rspec-core (3.12.1)
|
41
|
+
rspec-support (~> 3.12.0)
|
42
|
+
rspec-expectations (3.12.2)
|
42
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-mocks (3.
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-mocks (3.12.4)
|
45
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-support (3.
|
48
|
-
rubocop (1.
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-support (3.12.0)
|
49
|
+
rubocop (1.48.1)
|
50
|
+
json (~> 2.3)
|
49
51
|
parallel (~> 1.10)
|
50
|
-
parser (>= 3.
|
52
|
+
parser (>= 3.2.0.0)
|
51
53
|
rainbow (>= 2.2.2, < 4.0)
|
52
54
|
regexp_parser (>= 1.8, < 3.0)
|
53
|
-
rexml
|
54
|
-
rubocop-ast (>= 1.
|
55
|
+
rexml (>= 3.2.5, < 4.0)
|
56
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
55
57
|
ruby-progressbar (~> 1.7)
|
56
|
-
unicode-display_width (>=
|
57
|
-
rubocop-ast (1.
|
58
|
-
parser (>= 3.
|
59
|
-
rubocop-bsm (0.6.
|
58
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
59
|
+
rubocop-ast (1.27.0)
|
60
|
+
parser (>= 3.2.1.0)
|
61
|
+
rubocop-bsm (0.6.1)
|
60
62
|
rubocop (~> 1.0)
|
61
63
|
rubocop-performance
|
62
64
|
rubocop-rake
|
63
65
|
rubocop-rspec
|
64
|
-
rubocop-
|
66
|
+
rubocop-capybara (2.17.1)
|
67
|
+
rubocop (~> 1.41)
|
68
|
+
rubocop-performance (1.16.0)
|
65
69
|
rubocop (>= 1.7.0, < 2.0)
|
66
70
|
rubocop-ast (>= 0.4.0)
|
67
71
|
rubocop-rake (0.6.0)
|
68
72
|
rubocop (~> 1.0)
|
69
|
-
rubocop-rspec (2.
|
70
|
-
rubocop (~> 1.
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
rubocop-rspec (2.19.0)
|
74
|
+
rubocop (~> 1.33)
|
75
|
+
rubocop-capybara (~> 2.17)
|
76
|
+
ruby-progressbar (1.13.0)
|
77
|
+
sqlite3 (1.6.1-x86_64-linux)
|
78
|
+
tzinfo (2.0.6)
|
74
79
|
concurrent-ruby (~> 1.0)
|
75
|
-
unicode-display_width (2.
|
76
|
-
zeitwerk (2.
|
80
|
+
unicode-display_width (2.4.2)
|
81
|
+
zeitwerk (2.6.7)
|
77
82
|
|
78
83
|
PLATFORMS
|
79
84
|
x86_64-linux
|
80
85
|
|
81
86
|
DEPENDENCIES
|
82
87
|
activerecord (~> 6.1)
|
83
|
-
bundler
|
84
88
|
filterable-by!
|
85
89
|
rake
|
86
90
|
rspec
|
data/filterable-by.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'filterable-by'
|
3
|
-
s.version = '0.6.
|
3
|
+
s.version = '0.6.5'
|
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'
|
@@ -9,17 +9,11 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.license = 'MIT'
|
10
10
|
|
11
11
|
s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^spec/}) }
|
12
|
-
s.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
13
12
|
s.require_paths = ['lib']
|
14
13
|
s.required_ruby_version = '>= 2.7'
|
15
14
|
|
16
15
|
s.add_dependency 'activerecord'
|
17
16
|
s.add_dependency 'activesupport'
|
18
17
|
|
19
|
-
s.add_development_dependency 'bundler'
|
20
|
-
s.add_development_dependency 'rake'
|
21
|
-
s.add_development_dependency 'rspec'
|
22
|
-
s.add_development_dependency 'rubocop-bsm'
|
23
|
-
s.add_development_dependency 'sqlite3'
|
24
18
|
s.metadata['rubygems_mfa_required'] = 'true'
|
25
19
|
end
|
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.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -38,76 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-bsm
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: sqlite3
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
41
|
description: ActiveRecord plugin
|
112
42
|
email:
|
113
43
|
- dimitrij@blacksquaremedia.com
|
@@ -128,8 +58,6 @@ files:
|
|
128
58
|
- filterable-by.gemspec
|
129
59
|
- lib/filterable-by.rb
|
130
60
|
- lib/filterable_by.rb
|
131
|
-
- spec/active_record/filterable_by_spec.rb
|
132
|
-
- spec/spec_helper.rb
|
133
61
|
homepage: https://github.com/bsm/filterable-by
|
134
62
|
licenses:
|
135
63
|
- MIT
|
@@ -150,10 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
78
|
- !ruby/object:Gem::Version
|
151
79
|
version: '0'
|
152
80
|
requirements: []
|
153
|
-
rubygems_version: 3.
|
81
|
+
rubygems_version: 3.4.6
|
154
82
|
signing_key:
|
155
83
|
specification_version: 4
|
156
84
|
summary: Generate white-listed filter scopes from URL parameter values
|
157
|
-
test_files:
|
158
|
-
- spec/active_record/filterable_by_spec.rb
|
159
|
-
- spec/spec_helper.rb
|
85
|
+
test_files: []
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ActiveRecord::FilterableBy do
|
4
|
-
let(:alice) { AUTHORS[:alice] }
|
5
|
-
let(:bob) { AUTHORS[:bob] }
|
6
|
-
|
7
|
-
let(:apost) { POSTS[:alices] }
|
8
|
-
let(:bpost) { POSTS[:bobs] }
|
9
|
-
|
10
|
-
it 'has config' do
|
11
|
-
expect(Comment.send(:_filterable_by_config).count).to eq(5)
|
12
|
-
expect(Rating.send(:_filterable_by_config).count).to eq(4)
|
13
|
-
expect(Post.send(:_filterable_by_config).count).to eq(2)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'ignores bad inputs' do
|
17
|
-
expect(Comment.filter_by.count).to eq(4)
|
18
|
-
expect(Comment.filter_by(nil).count).to eq(4)
|
19
|
-
expect(Comment.filter_by(nil, extra: true).count).to eq(4)
|
20
|
-
expect(Comment.filter_by('bad').count).to eq(4)
|
21
|
-
|
22
|
-
expect(Comment.filter_by('author_id' => '').count).to eq(4)
|
23
|
-
expect(Comment.filter_by('author_id' => []).count).to eq(4)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'generates simple scopes' do
|
27
|
-
expect(Comment.filter_by('author_id' => alice.id).pluck(:title)).to match_array(%w[AA AB])
|
28
|
-
expect(Comment.filter_by('author_id' => bob.id).pluck(:title)).to match_array(%w[BA BB])
|
29
|
-
expect(Comment.filter_by('author_id' => [alice.id, '']).pluck(:title)).to match_array(%w[AA AB])
|
30
|
-
|
31
|
-
expect(Comment.filter_by('post_id' => apost.id).pluck(:title)).to match_array(%w[AA BA])
|
32
|
-
expect(Comment.filter_by('post_id' => bpost.id).pluck(:title)).to match_array(%w[AB BB])
|
33
|
-
|
34
|
-
expect(Comment.filter_by('post_author_id' => alice.id).pluck(:title)).to match_array(%w[AA BA])
|
35
|
-
expect(Comment.filter_by('post_author_id' => bob.id).pluck(:title)).to match_array(%w[AB BB])
|
36
|
-
|
37
|
-
expect(Rating.filter_by('author_id' => alice.id).count).to eq(0)
|
38
|
-
expect(Rating.filter_by('author_id' => bob.id).count).to eq(1)
|
39
|
-
|
40
|
-
expect(Post.filter_by('author_id' => bob.id).count).to eq(1)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'generates combined scopes' do
|
44
|
-
expect(Comment.filter_by('author_id' => alice.id, 'post_id' => apost.id).pluck(:title)).to match_array(['AA'])
|
45
|
-
expect(Comment.filter_by('author_id' => alice.id, 'post_id' => bpost.id).pluck(:title)).to match_array(['AB'])
|
46
|
-
expect(Comment.filter_by('author_id' => bob.id, 'post_id' => apost.id).pluck(:title)).to match_array(['BA'])
|
47
|
-
expect(Comment.filter_by('author_id' => bob.id, 'post_id' => bpost.id).pluck(:title)).to match_array(['BB'])
|
48
|
-
|
49
|
-
scope = Comment.filter_by('author_id' => [alice.id, bob.id], 'post_id' => bpost.id)
|
50
|
-
expect(scope.pluck(:title)).to match_array(%w[AB BB])
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'generates negated scopes' do
|
54
|
-
expect(Comment.filter_by('author_id_not' => alice.id).pluck(:title)).to match_array(%w[BA BB])
|
55
|
-
expect(Comment.filter_by('author_id_not' => [alice.id, bob.id]).pluck(:title)).to match_array(%w[])
|
56
|
-
expect(Comment.filter_by('post_id_not' => apost.id).pluck(:title)).to match_array(%w[AB BB])
|
57
|
-
expect(Comment.filter_by('post_author_id_not' => alice.id).pluck(:title)).to match_array(%w[AB BB])
|
58
|
-
expect(Comment.filter_by('author_id' => bob.id, 'post_id_not' => bpost.id).pluck(:title)).to match_array(['BA'])
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'combines with other scopes' do
|
62
|
-
scope = Comment.where(author_id: alice.id).filter_by('post_id' => apost.id)
|
63
|
-
expect(scope.pluck(:title)).to match_array(['AA'])
|
64
|
-
|
65
|
-
expect(alice.posts.filter_by('post_id' => apost.id).count).to be(1)
|
66
|
-
expect(alice.posts.filter_by('author_id' => alice.id).count).to be(1)
|
67
|
-
expect(alice.posts.filter_by('author_id_not' => bob.id).count).to be(1)
|
68
|
-
expect(alice.posts.filter_by('author_id' => bob.id).count).to be_zero
|
69
|
-
expect(alice.posts.filter_by('author_id_not' => alice.id).count).to be_zero
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'allows custom options' do
|
73
|
-
scope = Post.filter_by({ 'only' => 'me' }, user_id: alice.id)
|
74
|
-
expect(scope).to match_array([apost])
|
75
|
-
|
76
|
-
scope = Post.filter_by({ 'only' => '??' }, user_id: alice.id)
|
77
|
-
expect(scope.count).to eq(2)
|
78
|
-
|
79
|
-
scope = Post.filter_by({ 'only' => 'me' })
|
80
|
-
expect(scope.count).to eq(0)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'allows custom options from params' do
|
84
|
-
filter = { 'only' => 'me' }
|
85
|
-
expect(Post.filter_by(filter, user_id: alice.id)).to match_array([apost])
|
86
|
-
expect(Post.filter_by(filter).count).to eq(0)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'ignores invalid scopes' do
|
90
|
-
expect(Comment.filter_by('invalid' => 1).count).to eq(4)
|
91
|
-
expect(Post.filter_by('post_id' => bpost.id).count).to eq(2)
|
92
|
-
expect(Rating.filter_by('post_author_id' => bob.id).count).to eq(1)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'supports deprecated scoping' do
|
96
|
-
expect(Comment.filter_by('deprecated' => alice.id).pluck(:title)).to match_array(%w[AA AB])
|
97
|
-
expect(Comment.filter_by('deprecated_with_opts' => alice.id).pluck(:title)).to match_array(%w[AA AB])
|
98
|
-
expect(Comment.filter_by('deprecated_not' => alice.id).pluck(:title)).to match_array(%w[BA BB])
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'supports abstract classes' do
|
102
|
-
expect(Post.filter_by('author_id' => bob.id).count).to eq(1)
|
103
|
-
end
|
104
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
ENV['RACK_ENV'] ||= 'test'
|
2
|
-
require 'filterable-by'
|
3
|
-
require 'rspec'
|
4
|
-
|
5
|
-
ActiveRecord::Base.configurations = { 'test' => { 'adapter' => 'sqlite3', 'database' => ':memory:' } }
|
6
|
-
ActiveRecord::Base.establish_connection :test
|
7
|
-
|
8
|
-
ActiveRecord::Base.connection.instance_eval do
|
9
|
-
create_table :authors do |_|
|
10
|
-
# no columns
|
11
|
-
end
|
12
|
-
create_table :posts do |t|
|
13
|
-
t.integer :author_id, null: false
|
14
|
-
end
|
15
|
-
create_table :feedbacks do |t|
|
16
|
-
t.string :type, null: false
|
17
|
-
t.string :title
|
18
|
-
t.integer :stars, null: false, default: 0
|
19
|
-
t.integer :post_id, null: false
|
20
|
-
t.integer :author_id, null: false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Author < ActiveRecord::Base
|
25
|
-
has_many :posts
|
26
|
-
end
|
27
|
-
|
28
|
-
class AbstractPost < ActiveRecord::Base
|
29
|
-
self.abstract_class = true
|
30
|
-
|
31
|
-
filterable_by :author_id
|
32
|
-
filterable_by :only do |value, **opts|
|
33
|
-
case value
|
34
|
-
when 'me'
|
35
|
-
where(author_id: opts[:user_id]) if opts[:user_id]
|
36
|
-
else
|
37
|
-
all
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class Post < AbstractPost
|
43
|
-
belongs_to :author
|
44
|
-
end
|
45
|
-
|
46
|
-
class Feedback < ActiveRecord::Base
|
47
|
-
belongs_to :author
|
48
|
-
belongs_to :post
|
49
|
-
|
50
|
-
filterable_by :post_id, :author_id
|
51
|
-
|
52
|
-
ActiveSupport::Deprecation.silence do
|
53
|
-
filterable_by :deprecated do |scope, value|
|
54
|
-
scope.where(author_id: value)
|
55
|
-
end
|
56
|
-
filterable_by :deprecated_with_opts do |scope, value, **_opts|
|
57
|
-
scope.where(author_id: value)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class Comment < Feedback
|
63
|
-
filterable_by :post_author_id do |value|
|
64
|
-
joins(:post).where(Post.arel_table[:author_id].eq(value))
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class Rating < Feedback
|
69
|
-
end
|
70
|
-
|
71
|
-
AUTHORS = {
|
72
|
-
alice: Author.create!,
|
73
|
-
bob: Author.create!,
|
74
|
-
}.freeze
|
75
|
-
|
76
|
-
POSTS = {
|
77
|
-
alices: Post.create!(author_id: AUTHORS[:alice].id),
|
78
|
-
bobs: Post.create!(author_id: AUTHORS[:bob].id),
|
79
|
-
}.freeze
|
80
|
-
|
81
|
-
COMMENTS = {
|
82
|
-
alice_on_alice: Comment.create!(title: 'AA', post_id: POSTS[:alices].id, author_id: AUTHORS[:alice].id),
|
83
|
-
bob_on_alice: Comment.create!(title: 'BA', post_id: POSTS[:alices].id, author_id: AUTHORS[:bob].id),
|
84
|
-
alice_on_bob: Comment.create!(title: 'AB', post_id: POSTS[:bobs].id, author_id: AUTHORS[:alice].id),
|
85
|
-
bob_on_bob: Comment.create!(title: 'BB', post_id: POSTS[:bobs].id, author_id: AUTHORS[:bob].id),
|
86
|
-
boa_rating: Rating.create!(stars: 5, post_id: POSTS[:alices].id, author_id: AUTHORS[:bob].id),
|
87
|
-
}.freeze
|