sortable-by 0.11.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +21 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +10 -24
- data/Gemfile.lock +68 -45
- data/README.md +12 -12
- data/lib/sortable_by.rb +25 -24
- data/sortable-by.gemspec +4 -5
- data/spec/{sortable_by_spec.rb → active_record/sortable_by_spec.rb} +6 -6
- data/spec/spec_helper.rb +9 -7
- metadata +8 -9
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bb07dd11741d2ea29ae694e1e6bc11711e8427b137855ff84fe6760e182e59e
|
4
|
+
data.tar.gz: a5d2b6e874053630307e891855e542b6874adad75788e6a0c822a2e9336d490d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95feb9e2a5ba054e128572c35da39246760472ecb12c456976e267cac7eaa425c61505bce2037af98c5e33d5f20513571405395f1c462ad2054f6032d6600a5c
|
7
|
+
data.tar.gz: 610babd95b3ba593f9f566720e549929e13aef5031aa7330f7e87a07feac48b68483f2c5d2bc14489d81dd0728e39d405aeeb6d7681437598a98078e10f2e437
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [main]
|
6
|
+
pull_request:
|
7
|
+
branches: [main]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ["2.6", "2.7", "3.0"]
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
bundler-cache: true
|
21
|
+
- run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,29 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
inherit_gem:
|
2
|
+
rubocop-bsm:
|
3
|
+
- default.yml
|
4
|
+
inherit_mode:
|
5
|
+
merge:
|
6
|
+
- Exclude
|
3
7
|
|
8
|
+
AllCops:
|
9
|
+
TargetRubyVersion: 2.6
|
10
|
+
Naming/MethodParameterName:
|
11
|
+
MinNameLength: 2
|
4
12
|
Naming/MemoizedInstanceVariableName:
|
5
13
|
Enabled: false
|
6
|
-
|
7
|
-
Metrics/AbcSize:
|
8
|
-
Enabled: false
|
9
|
-
Metrics/CyclomaticComplexity:
|
10
|
-
Enabled: false
|
11
|
-
Metrics/PerceivedComplexity:
|
12
|
-
Enabled: false
|
13
14
|
Naming/FileName:
|
14
15
|
Exclude: [lib/sortable-by.rb]
|
15
|
-
Metrics/BlockLength:
|
16
|
-
Exclude: [spec/**]
|
17
|
-
Metrics/MethodLength:
|
18
|
-
Enabled: false
|
19
|
-
Metrics/LineLength:
|
20
|
-
Max: 120
|
21
|
-
|
22
|
-
Style/NumericLiterals:
|
23
|
-
Exclude: [spec/**]
|
24
|
-
Style/TrailingCommaInArguments:
|
25
|
-
EnforcedStyleForMultiline: consistent_comma
|
26
|
-
Style/TrailingCommaInArrayLiteral:
|
27
|
-
EnforcedStyleForMultiline: consistent_comma
|
28
|
-
Style/TrailingCommaInHashLiteral:
|
29
|
-
EnforcedStyleForMultiline: consistent_comma
|
data/Gemfile.lock
CHANGED
@@ -1,63 +1,86 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sortable-by (0.
|
4
|
+
sortable-by (0.13.1)
|
5
5
|
activerecord
|
6
6
|
activesupport
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activemodel (
|
12
|
-
activesupport (=
|
13
|
-
activerecord (
|
14
|
-
activemodel (=
|
15
|
-
activesupport (=
|
16
|
-
|
17
|
-
activesupport (5.2.0)
|
11
|
+
activemodel (6.1.3)
|
12
|
+
activesupport (= 6.1.3)
|
13
|
+
activerecord (6.1.3)
|
14
|
+
activemodel (= 6.1.3)
|
15
|
+
activesupport (= 6.1.3)
|
16
|
+
activesupport (6.1.3)
|
18
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
-
i18n (>=
|
20
|
-
minitest (
|
21
|
-
tzinfo (~>
|
22
|
-
|
23
|
-
ast (2.4.
|
24
|
-
concurrent-ruby (1.
|
25
|
-
diff-lcs (1.
|
26
|
-
i18n (1.
|
18
|
+
i18n (>= 1.6, < 2)
|
19
|
+
minitest (>= 5.1)
|
20
|
+
tzinfo (~> 2.0)
|
21
|
+
zeitwerk (~> 2.3)
|
22
|
+
ast (2.4.2)
|
23
|
+
concurrent-ruby (1.1.8)
|
24
|
+
diff-lcs (1.4.4)
|
25
|
+
i18n (1.8.9)
|
27
26
|
concurrent-ruby (~> 1.0)
|
28
|
-
minitest (5.
|
29
|
-
parallel (1.
|
30
|
-
parser (
|
31
|
-
ast (~> 2.4.
|
32
|
-
|
27
|
+
minitest (5.14.4)
|
28
|
+
parallel (1.20.1)
|
29
|
+
parser (3.0.0.0)
|
30
|
+
ast (~> 2.4.1)
|
31
|
+
rack (2.2.3)
|
33
32
|
rainbow (3.0.0)
|
34
|
-
rake (
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
rspec-
|
39
|
-
|
40
|
-
rspec-
|
41
|
-
rspec-
|
33
|
+
rake (13.0.3)
|
34
|
+
regexp_parser (2.1.1)
|
35
|
+
rexml (3.2.4)
|
36
|
+
rspec (3.10.0)
|
37
|
+
rspec-core (~> 3.10.0)
|
38
|
+
rspec-expectations (~> 3.10.0)
|
39
|
+
rspec-mocks (~> 3.10.0)
|
40
|
+
rspec-core (3.10.1)
|
41
|
+
rspec-support (~> 3.10.0)
|
42
|
+
rspec-expectations (3.10.1)
|
42
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-mocks (3.
|
44
|
+
rspec-support (~> 3.10.0)
|
45
|
+
rspec-mocks (3.10.2)
|
45
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
-
rspec-support (~> 3.
|
47
|
-
rspec-support (3.
|
48
|
-
rubocop (
|
47
|
+
rspec-support (~> 3.10.0)
|
48
|
+
rspec-support (3.10.2)
|
49
|
+
rubocop (1.11.0)
|
49
50
|
parallel (~> 1.10)
|
50
|
-
parser (>=
|
51
|
-
powerpack (~> 0.1)
|
51
|
+
parser (>= 3.0.0.0)
|
52
52
|
rainbow (>= 2.2.2, < 4.0)
|
53
|
+
regexp_parser (>= 1.8, < 3.0)
|
54
|
+
rexml
|
55
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
53
56
|
ruby-progressbar (~> 1.7)
|
54
|
-
unicode-display_width (
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
58
|
+
rubocop-ast (1.4.1)
|
59
|
+
parser (>= 2.7.1.5)
|
60
|
+
rubocop-bsm (0.5.4)
|
61
|
+
rubocop (~> 1.0)
|
62
|
+
rubocop-performance
|
63
|
+
rubocop-rails
|
64
|
+
rubocop-rake
|
65
|
+
rubocop-rspec
|
66
|
+
rubocop-performance (1.10.1)
|
67
|
+
rubocop (>= 0.90.0, < 2.0)
|
68
|
+
rubocop-ast (>= 0.4.0)
|
69
|
+
rubocop-rails (2.9.1)
|
70
|
+
activesupport (>= 4.2.0)
|
71
|
+
rack (>= 1.1)
|
72
|
+
rubocop (>= 0.90.0, < 2.0)
|
73
|
+
rubocop-rake (0.5.1)
|
74
|
+
rubocop
|
75
|
+
rubocop-rspec (2.2.0)
|
76
|
+
rubocop (~> 1.0)
|
77
|
+
rubocop-ast (>= 1.1.0)
|
78
|
+
ruby-progressbar (1.11.0)
|
79
|
+
sqlite3 (1.4.2)
|
80
|
+
tzinfo (2.0.4)
|
81
|
+
concurrent-ruby (~> 1.0)
|
82
|
+
unicode-display_width (2.0.0)
|
83
|
+
zeitwerk (2.4.2)
|
61
84
|
|
62
85
|
PLATFORMS
|
63
86
|
ruby
|
@@ -66,9 +89,9 @@ DEPENDENCIES
|
|
66
89
|
bundler
|
67
90
|
rake
|
68
91
|
rspec
|
69
|
-
rubocop
|
92
|
+
rubocop-bsm
|
70
93
|
sortable-by!
|
71
94
|
sqlite3
|
72
95
|
|
73
96
|
BUNDLED WITH
|
74
|
-
1.
|
97
|
+
2.1.4
|
data/README.md
CHANGED
@@ -20,23 +20,23 @@ class Post < ActiveRecord::Base
|
|
20
20
|
sortable_by :title, :id
|
21
21
|
end
|
22
22
|
|
23
|
-
Post.sorted_by('title') # => ORDER BY posts.title ASC
|
24
|
-
Post.sorted_by('-title') # => ORDER BY posts.title DESC
|
25
|
-
Post.sorted_by('bad,title') # => ORDER BY posts.title ASC
|
26
|
-
Post.sorted_by(nil) # => ORDER BY posts.title ASC
|
23
|
+
Post.sorted_by('title') # => ORDER BY LOWER(posts.title) ASC
|
24
|
+
Post.sorted_by('-title') # => ORDER BY LOWER(posts.title) DESC
|
25
|
+
Post.sorted_by('bad,title') # => ORDER BY LOWER(posts.title) ASC
|
26
|
+
Post.sorted_by(nil) # => ORDER BY LOWER(posts.title) ASC
|
27
27
|
```
|
28
28
|
|
29
|
-
Case-
|
29
|
+
Case-sensitive:
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
class Post < ActiveRecord::Base
|
33
33
|
sortable_by do |x|
|
34
|
-
x.field :title,
|
34
|
+
x.field :title, case_sensitive: true
|
35
35
|
x.field :id
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
Post.sorted_by('title') # => ORDER BY
|
39
|
+
Post.sorted_by('title') # => ORDER BY posts.title ASC
|
40
40
|
```
|
41
41
|
|
42
42
|
With custom default:
|
@@ -46,7 +46,7 @@ class Post < ActiveRecord::Base
|
|
46
46
|
sortable_by :id, :topic, :created_at, default: 'topic,-created_at'
|
47
47
|
end
|
48
48
|
|
49
|
-
Post.sorted_by(nil) # => ORDER BY posts.topic ASC, posts.created_at DESC
|
49
|
+
Post.sorted_by(nil) # => ORDER BY LOWER(posts.topic) ASC, posts.created_at DESC
|
50
50
|
```
|
51
51
|
|
52
52
|
Composition:
|
@@ -68,8 +68,8 @@ Associations (eager load):
|
|
68
68
|
class Product < ActiveRecord::Base
|
69
69
|
belongs_to :shop
|
70
70
|
sortable_by do |x|
|
71
|
-
x.field :name
|
72
|
-
x.field :shop, as: Shop.arel_table[:name]
|
71
|
+
x.field :name
|
72
|
+
x.field :shop, as: Shop.arel_table[:name], eager_load: :shop
|
73
73
|
x.default 'shop,name'
|
74
74
|
end
|
75
75
|
end
|
@@ -77,11 +77,11 @@ end
|
|
77
77
|
|
78
78
|
Associations (custom scope):
|
79
79
|
|
80
|
-
```
|
80
|
+
```ruby
|
81
81
|
class Product < ActiveRecord::Base
|
82
82
|
belongs_to :shop
|
83
83
|
sortable_by do |x|
|
84
|
-
x.field :shop, as: Shop.arel_table[:name]
|
84
|
+
x.field :shop, as: Shop.arel_table[:name], scope: -> { joins(:shop) }
|
85
85
|
end
|
86
86
|
end
|
87
87
|
```
|
data/lib/sortable_by.rb
CHANGED
@@ -17,9 +17,9 @@ module ActiveRecord # :nodoc:
|
|
17
17
|
duplicate
|
18
18
|
end
|
19
19
|
|
20
|
-
def field(name, opts
|
20
|
+
def field(name, **opts)
|
21
21
|
name = name.to_s
|
22
|
-
@_fields[name] = Field.new(name, opts)
|
22
|
+
@_fields[name] = Field.new(name, **opts)
|
23
23
|
@_default ||= name
|
24
24
|
end
|
25
25
|
|
@@ -36,7 +36,7 @@ module ActiveRecord # :nodoc:
|
|
36
36
|
|
37
37
|
protected
|
38
38
|
|
39
|
-
def order(relation, expr, fallback
|
39
|
+
def order(relation, expr, fallback: true)
|
40
40
|
matched = false
|
41
41
|
expr.to_s.split(',').each do |name|
|
42
42
|
name.strip!
|
@@ -44,31 +44,32 @@ module ActiveRecord # :nodoc:
|
|
44
44
|
rank = :asc
|
45
45
|
if name[0] == '-'
|
46
46
|
rank = :desc
|
47
|
-
name = name[1
|
47
|
+
name = name[1..]
|
48
48
|
end
|
49
49
|
|
50
50
|
field = _fields[name]
|
51
51
|
next unless field
|
52
52
|
|
53
|
-
matched
|
53
|
+
matched = true
|
54
54
|
relation = field.order(relation, rank)
|
55
55
|
end
|
56
56
|
|
57
|
-
relation = order(relation, _default, false) if fallback && !matched && _default
|
57
|
+
relation = order(relation, _default, fallback: false) if fallback && !matched && _default
|
58
58
|
relation
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
class Field # :nodoc:
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
STRING_TYPES = %i[string text].freeze # :nodoc:
|
64
|
+
|
65
|
+
def initialize(name, as: nil, scope: nil, eager_load: nil, case_sensitive: false)
|
66
|
+
@cols = Array.wrap(as)
|
67
|
+
@eager_load = Array.wrap(eager_load).presence
|
68
|
+
@case_sensitive = case_sensitive == true
|
66
69
|
|
67
70
|
# validate custom_scope
|
68
|
-
@custom_scope =
|
69
|
-
if @custom_scope && !@custom_scope.is_a?(Proc)
|
70
|
-
raise ArgumentError, "Invalid sortable-by field '#{name}': scope must be a Proc."
|
71
|
-
end
|
71
|
+
@custom_scope = scope
|
72
|
+
raise ArgumentError, "Invalid sortable-by field '#{name}': scope must be a Proc." if @custom_scope && !@custom_scope.is_a?(Proc)
|
72
73
|
|
73
74
|
# normalize cols
|
74
75
|
@cols.push name if @cols.empty?
|
@@ -77,9 +78,7 @@ module ActiveRecord # :nodoc:
|
|
77
78
|
when String, Symbol, Arel::Attributes::Attribute, Arel::Nodes::Node
|
78
79
|
next
|
79
80
|
when Proc
|
80
|
-
unless col.arity == 2
|
81
|
-
raise ArgumentError, "Invalid sortable-by field '#{name}': proc must accept 2 arguments."
|
82
|
-
end
|
81
|
+
raise ArgumentError, "Invalid sortable-by field '#{name}': proc must accept 2 arguments." unless col.arity == 2
|
83
82
|
else
|
84
83
|
raise ArgumentError, "Invalid sortable-by field '#{name}': invalid type #{col.class}."
|
85
84
|
end
|
@@ -90,7 +89,10 @@ module ActiveRecord # :nodoc:
|
|
90
89
|
@cols.each do |col|
|
91
90
|
case col
|
92
91
|
when String, Symbol
|
93
|
-
|
92
|
+
type = relation.columns_hash[col.to_s].type
|
93
|
+
col = relation.arel_table[col]
|
94
|
+
col = col.lower if STRING_TYPES.include?(type) && !@case_sensitive
|
95
|
+
relation = relation.order(col.send(rank))
|
94
96
|
when Arel::Nodes::Node, Arel::Attributes::Attribute
|
95
97
|
relation = relation.order(col.send(rank))
|
96
98
|
when Proc
|
@@ -121,10 +123,10 @@ module ActiveRecord # :nodoc:
|
|
121
123
|
# sortable_by :title, :id
|
122
124
|
# end
|
123
125
|
#
|
124
|
-
# # Case-
|
126
|
+
# # Case-sensitive
|
125
127
|
# class Post < ActiveRecord::Base
|
126
128
|
# sortable_by do |x|
|
127
|
-
# x.field :title,
|
129
|
+
# x.field :title, case_sensitive: true
|
128
130
|
# x.field :id
|
129
131
|
# end
|
130
132
|
# end
|
@@ -148,7 +150,7 @@ module ActiveRecord # :nodoc:
|
|
148
150
|
#
|
149
151
|
# sortable_by do |x|
|
150
152
|
# x.field :name
|
151
|
-
# x.field :shop, as: Shop.arel_table[:name]
|
153
|
+
# x.field :shop, as: Shop.arel_table[:name], eager_load: :shop
|
152
154
|
# x.default 'shop,name'
|
153
155
|
# end
|
154
156
|
# end
|
@@ -158,17 +160,16 @@ module ActiveRecord # :nodoc:
|
|
158
160
|
# belongs_to :shop
|
159
161
|
#
|
160
162
|
# sortable_by do |x|
|
161
|
-
# x.field :shop, as: Shop.arel_table[:name]
|
163
|
+
# x.field :shop, as: Shop.arel_table[:name], scope: -> { joins(:shop) }
|
162
164
|
# end
|
163
165
|
# end
|
164
166
|
#
|
165
|
-
def sortable_by(*attributes)
|
167
|
+
def sortable_by(*attributes, **opts)
|
166
168
|
config = _sortable_by_config
|
167
|
-
opts = attributes.extract_options!
|
168
169
|
default = opts.delete(:default)
|
169
170
|
|
170
171
|
attributes.each do |name|
|
171
|
-
config.field(name, opts)
|
172
|
+
config.field(name, **opts)
|
172
173
|
end
|
173
174
|
config.default(default) if default
|
174
175
|
yield config if block_given?
|
data/sortable-by.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
1
|
Gem::Specification.new do |s|
|
3
2
|
s.name = 'sortable-by'
|
4
|
-
s.version = '0.
|
3
|
+
s.version = '0.13.1'
|
5
4
|
s.authors = ['Dimitrij Denissenko']
|
6
5
|
s.email = ['dimitrij@blacksquaremedia.com']
|
7
6
|
s.summary = 'Generate white-listed sort scopes from URL parameter values'
|
@@ -9,10 +8,10 @@ Gem::Specification.new do |s|
|
|
9
8
|
s.homepage = 'https://github.com/bsm/sortable-by'
|
10
9
|
s.license = 'MIT'
|
11
10
|
|
12
|
-
s.files = `git ls-files -z`.split("\x0").reject {
|
11
|
+
s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^spec/}) }
|
13
12
|
s.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
14
13
|
s.require_paths = ['lib']
|
15
|
-
s.required_ruby_version = '>= 2.
|
14
|
+
s.required_ruby_version = '>= 2.6'
|
16
15
|
|
17
16
|
s.add_dependency 'activerecord'
|
18
17
|
s.add_dependency 'activesupport'
|
@@ -20,6 +19,6 @@ Gem::Specification.new do |s|
|
|
20
19
|
s.add_development_dependency 'bundler'
|
21
20
|
s.add_development_dependency 'rake'
|
22
21
|
s.add_development_dependency 'rspec'
|
23
|
-
s.add_development_dependency 'rubocop'
|
22
|
+
s.add_development_dependency 'rubocop-bsm'
|
24
23
|
s.add_development_dependency 'sqlite3'
|
25
24
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveRecord::SortableBy do
|
4
4
|
before do
|
@@ -8,7 +8,7 @@ describe ActiveRecord::SortableBy do
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
it '
|
11
|
+
it 'has config' do
|
12
12
|
expect(Post._sortable_by_config._fields.keys).to match_array(%w[title created])
|
13
13
|
expect(Post._sortable_by_config._default).to eq('-created')
|
14
14
|
expect(SubPost._sortable_by_config._fields.keys).to match_array(%w[title created])
|
@@ -24,7 +24,7 @@ describe ActiveRecord::SortableBy do
|
|
24
24
|
expect(Product._sortable_by_config._default).to eq('shop,name')
|
25
25
|
end
|
26
26
|
|
27
|
-
it '
|
27
|
+
it 'simplies order' do
|
28
28
|
Post.create! title: 'A', created_at: Time.at(1515151500)
|
29
29
|
Post.create! title: 'b', created_at: Time.at(1515151600)
|
30
30
|
Post.create! title: 'C', created_at: Time.at(1515151400)
|
@@ -41,7 +41,7 @@ describe ActiveRecord::SortableBy do
|
|
41
41
|
expect(Post.sorted_by(' title ').pluck(:title)).to eq(%w[A C b])
|
42
42
|
end
|
43
43
|
|
44
|
-
it '
|
44
|
+
it 'supports STI inheritance and overrides' do
|
45
45
|
SubPost.create! title: 'A', created_at: Time.at(1515151700)
|
46
46
|
SubPost.create! title: 'b', created_at: Time.at(1515151600)
|
47
47
|
Post.create! title: 'C', created_at: Time.at(1515151400)
|
@@ -56,7 +56,7 @@ describe ActiveRecord::SortableBy do
|
|
56
56
|
expect(SubPost.sorted_by('title').pluck(:title)).to eq(%w[A b D])
|
57
57
|
end
|
58
58
|
|
59
|
-
it '
|
59
|
+
it 'supports composition' do
|
60
60
|
App.create! name: 'E', major: 0, minor: 9, patch: 2
|
61
61
|
App.create! name: 'A', major: 1, minor: 0, patch: 1
|
62
62
|
App.create! name: 'D', major: 1, minor: 0, patch: 6
|
@@ -68,7 +68,7 @@ describe ActiveRecord::SortableBy do
|
|
68
68
|
expect(App.sorted_by('-version').pluck(:name)).to eq(%w[B C D A E])
|
69
69
|
end
|
70
70
|
|
71
|
-
it '
|
71
|
+
it 'supports associations' do
|
72
72
|
y = Shop.create! name: 'Y'
|
73
73
|
x = Shop.create! name: 'X'
|
74
74
|
|
data/spec/spec_helper.rb
CHANGED
@@ -2,9 +2,11 @@ ENV['RACK_ENV'] ||= 'test'
|
|
2
2
|
require 'sortable-by'
|
3
3
|
require 'rspec'
|
4
4
|
|
5
|
-
ActiveRecord::Base.configurations
|
6
|
-
'
|
7
|
-
|
5
|
+
ActiveRecord::Base.configurations = {
|
6
|
+
'test' => {
|
7
|
+
'adapter' => 'sqlite3',
|
8
|
+
'database' => ':memory:',
|
9
|
+
},
|
8
10
|
}
|
9
11
|
ActiveRecord::Base.establish_connection :test
|
10
12
|
|
@@ -15,14 +17,14 @@ ActiveRecord::Base.connection.create_table :posts do |t|
|
|
15
17
|
end
|
16
18
|
|
17
19
|
class Post < ActiveRecord::Base
|
18
|
-
sortable_by :title, default: '-created' do |s|
|
20
|
+
sortable_by :title, default: '-created', case_sensitive: true do |s|
|
19
21
|
s.field :created, as: arel_table[:created_at]
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
25
|
class SubPost < Post
|
24
26
|
sortable_by do |s|
|
25
|
-
s.field :title
|
27
|
+
s.field :title
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -63,8 +65,8 @@ class Product < ActiveRecord::Base
|
|
63
65
|
belongs_to :shop
|
64
66
|
|
65
67
|
sortable_by do |s|
|
66
|
-
s.field :name
|
67
|
-
s.field :shop, as: Shop.arel_table[:name]
|
68
|
+
s.field :name
|
69
|
+
s.field :shop, as: Shop.arel_table[:name], eager_load: :shop
|
68
70
|
s.default 'shop,name'
|
69
71
|
end
|
70
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sortable-by
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.1
|
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: 2021-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop
|
84
|
+
name: rubocop-bsm
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -115,9 +115,9 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
+
- ".github/workflows/ruby.yml"
|
118
119
|
- ".gitignore"
|
119
120
|
- ".rubocop.yml"
|
120
|
-
- ".travis.yml"
|
121
121
|
- Gemfile
|
122
122
|
- Gemfile.lock
|
123
123
|
- LICENSE
|
@@ -126,7 +126,7 @@ files:
|
|
126
126
|
- lib/sortable-by.rb
|
127
127
|
- lib/sortable_by.rb
|
128
128
|
- sortable-by.gemspec
|
129
|
-
- spec/sortable_by_spec.rb
|
129
|
+
- spec/active_record/sortable_by_spec.rb
|
130
130
|
- spec/spec_helper.rb
|
131
131
|
homepage: https://github.com/bsm/sortable-by
|
132
132
|
licenses:
|
@@ -140,18 +140,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
140
|
requirements:
|
141
141
|
- - ">="
|
142
142
|
- !ruby/object:Gem::Version
|
143
|
-
version: 2.
|
143
|
+
version: '2.6'
|
144
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
145
|
requirements:
|
146
146
|
- - ">="
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
|
-
|
151
|
-
rubygems_version: 2.7.3
|
150
|
+
rubygems_version: 3.1.4
|
152
151
|
signing_key:
|
153
152
|
specification_version: 4
|
154
153
|
summary: Generate white-listed sort scopes from URL parameter values
|
155
154
|
test_files:
|
156
|
-
- spec/sortable_by_spec.rb
|
155
|
+
- spec/active_record/sortable_by_spec.rb
|
157
156
|
- spec/spec_helper.rb
|