sortable-by 0.13.3 → 0.14.0

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: 739ba7b6c67825b04f539ac5f288617865cf98e0286b5504d561580e0b4a4da7
4
- data.tar.gz: 9790f0fb3506dbe02f83a5a1fb312d568e0f3b4bcdb7265da896604f7ff398b9
3
+ metadata.gz: 8ecdfdde420426271df2fbc5ed0c8360f2d3397ef8def31a94847f5dd78916a9
4
+ data.tar.gz: 4abb2f7fae1f56d461ac2c834db694182aa3c8e61c24a9af05618536243abb52
5
5
  SHA512:
6
- metadata.gz: 265748bb3409aed86fa24dd6b46102967408b50bb663b682d2a834ca36cc0c5694ad2dcf266f6d7e2751c4667ab975c539831df2d829a8fab9c88c6483a1edf9
7
- data.tar.gz: a67635307cbafedaaf385d0a340e7745031a3e4439d5cd1f112400a6649f8762bf88e54f6655006550bf448b35a8ea60a47bee837f58e6a7168f0518c12c4bfd
6
+ metadata.gz: 8da947750cfc43e55b56b9040cd251368d93ac48efdeeee853da1294d2f5e69103f13271fe0da998cd1f4cb4e32e04e5a1643d406d8e057b19637cca152c7e94
7
+ data.tar.gz: e2a0a08467f48a5357e12e33cf98069e8b1026e950fca8512ae0a278484dab3ff3022f9ea0ff1bdfbd650996831aa8190705dbb91e320332236da1d3f8339286
@@ -16,7 +16,7 @@ jobs:
16
16
  env:
17
17
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
18
18
  steps:
19
- - uses: actions/checkout@v2
19
+ - uses: actions/checkout@v3
20
20
  - uses: ruby/setup-ruby@v1
21
21
  with:
22
22
  ruby-version: ${{ matrix.ruby-version }}
data/.rubocop.yml CHANGED
@@ -13,3 +13,5 @@ Naming/MemoizedInstanceVariableName:
13
13
  Enabled: false
14
14
  Naming/FileName:
15
15
  Exclude: [lib/sortable-by.rb]
16
+ Metrics/ParameterLists:
17
+ Max: 10
data/Gemfile.lock CHANGED
@@ -1,35 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sortable-by (0.13.3)
4
+ sortable-by (0.14.0)
5
5
  activerecord
6
6
  activesupport
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- activemodel (7.0.2.3)
12
- activesupport (= 7.0.2.3)
13
- activerecord (7.0.2.3)
14
- activemodel (= 7.0.2.3)
15
- activesupport (= 7.0.2.3)
16
- activesupport (7.0.2.3)
11
+ activemodel (7.0.3)
12
+ activesupport (= 7.0.3)
13
+ activerecord (7.0.3)
14
+ activemodel (= 7.0.3)
15
+ activesupport (= 7.0.3)
16
+ activesupport (7.0.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.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
- minitest (5.15.0)
27
- parallel (1.21.0)
28
- parser (3.1.1.0)
26
+ minitest (5.16.1)
27
+ parallel (1.22.1)
28
+ parser (3.1.2.0)
29
29
  ast (~> 2.4.1)
30
30
  rainbow (3.1.1)
31
31
  rake (13.0.6)
32
- regexp_parser (2.2.1)
32
+ regexp_parser (2.5.0)
33
33
  rexml (3.2.5)
34
34
  rspec (3.11.0)
35
35
  rspec-core (~> 3.11.0)
@@ -40,38 +40,38 @@ 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.30.1)
48
48
  parallel (~> 1.10)
49
49
  parser (>= 3.1.0.0)
50
50
  rainbow (>= 2.2.2, < 4.0)
51
51
  regexp_parser (>= 1.8, < 3.0)
52
- rexml
53
- rubocop-ast (>= 1.16.0, < 2.0)
52
+ rexml (>= 3.2.5, < 4.0)
53
+ rubocop-ast (>= 1.18.0, < 2.0)
54
54
  ruby-progressbar (~> 1.7)
55
55
  unicode-display_width (>= 1.4.0, < 3.0)
56
- rubocop-ast (1.16.0)
56
+ rubocop-ast (1.18.0)
57
57
  parser (>= 3.1.1.0)
58
58
  rubocop-bsm (0.6.0)
59
59
  rubocop (~> 1.0)
60
60
  rubocop-performance
61
61
  rubocop-rake
62
62
  rubocop-rspec
63
- rubocop-performance (1.13.3)
63
+ rubocop-performance (1.14.2)
64
64
  rubocop (>= 1.7.0, < 2.0)
65
65
  rubocop-ast (>= 0.4.0)
66
66
  rubocop-rake (0.6.0)
67
67
  rubocop (~> 1.0)
68
- rubocop-rspec (2.9.0)
68
+ rubocop-rspec (2.11.1)
69
69
  rubocop (~> 1.19)
70
70
  ruby-progressbar (1.11.0)
71
- sqlite3 (1.4.2)
71
+ sqlite3 (1.4.4)
72
72
  tzinfo (2.0.4)
73
73
  concurrent-ruby (~> 1.0)
74
- unicode-display_width (2.1.0)
74
+ unicode-display_width (2.2.0)
75
75
 
76
76
  PLATFORMS
77
77
  ruby
data/Gemfile.rails6.lock CHANGED
@@ -1,36 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sortable-by (0.13.3)
4
+ sortable-by (0.14.0)
5
5
  activerecord
6
6
  activesupport
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (6.1.4.7)
12
- activesupport (= 6.1.4.7)
13
- activerecord (6.1.4.7)
14
- activemodel (= 6.1.4.7)
15
- activesupport (= 6.1.4.7)
16
- activesupport (6.1.4.7)
11
+ activemodel (6.1.6)
12
+ activesupport (= 6.1.6)
13
+ activerecord (6.1.6)
14
+ activemodel (= 6.1.6)
15
+ activesupport (= 6.1.6)
16
+ activesupport (6.1.6)
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.1.9)
23
+ concurrent-ruby (1.1.10)
24
24
  diff-lcs (1.5.0)
25
25
  i18n (1.10.0)
26
26
  concurrent-ruby (~> 1.0)
27
- minitest (5.15.0)
28
- parallel (1.21.0)
29
- parser (3.1.1.0)
27
+ minitest (5.16.1)
28
+ parallel (1.22.1)
29
+ parser (3.1.2.0)
30
30
  ast (~> 2.4.1)
31
31
  rainbow (3.1.1)
32
32
  rake (13.0.6)
33
- regexp_parser (2.2.1)
33
+ regexp_parser (2.5.0)
34
34
  rexml (3.2.5)
35
35
  rspec (3.11.0)
36
36
  rspec-core (~> 3.11.0)
@@ -41,39 +41,39 @@ GEM
41
41
  rspec-expectations (3.11.0)
42
42
  diff-lcs (>= 1.2.0, < 2.0)
43
43
  rspec-support (~> 3.11.0)
44
- rspec-mocks (3.11.0)
44
+ rspec-mocks (3.11.1)
45
45
  diff-lcs (>= 1.2.0, < 2.0)
46
46
  rspec-support (~> 3.11.0)
47
47
  rspec-support (3.11.0)
48
- rubocop (1.26.0)
48
+ rubocop (1.30.1)
49
49
  parallel (~> 1.10)
50
50
  parser (>= 3.1.0.0)
51
51
  rainbow (>= 2.2.2, < 4.0)
52
52
  regexp_parser (>= 1.8, < 3.0)
53
- rexml
54
- rubocop-ast (>= 1.16.0, < 2.0)
53
+ rexml (>= 3.2.5, < 4.0)
54
+ rubocop-ast (>= 1.18.0, < 2.0)
55
55
  ruby-progressbar (~> 1.7)
56
56
  unicode-display_width (>= 1.4.0, < 3.0)
57
- rubocop-ast (1.16.0)
57
+ rubocop-ast (1.18.0)
58
58
  parser (>= 3.1.1.0)
59
59
  rubocop-bsm (0.6.0)
60
60
  rubocop (~> 1.0)
61
61
  rubocop-performance
62
62
  rubocop-rake
63
63
  rubocop-rspec
64
- rubocop-performance (1.13.3)
64
+ rubocop-performance (1.14.2)
65
65
  rubocop (>= 1.7.0, < 2.0)
66
66
  rubocop-ast (>= 0.4.0)
67
67
  rubocop-rake (0.6.0)
68
68
  rubocop (~> 1.0)
69
- rubocop-rspec (2.9.0)
69
+ rubocop-rspec (2.11.1)
70
70
  rubocop (~> 1.19)
71
71
  ruby-progressbar (1.11.0)
72
- sqlite3 (1.4.2)
72
+ sqlite3 (1.4.4)
73
73
  tzinfo (2.0.4)
74
74
  concurrent-ruby (~> 1.0)
75
- unicode-display_width (2.1.0)
76
- zeitwerk (2.5.4)
75
+ unicode-display_width (2.2.0)
76
+ zeitwerk (2.6.0)
77
77
 
78
78
  PLATFORMS
79
79
  x86_64-linux
data/lib/sortable_by.rb CHANGED
@@ -65,6 +65,10 @@ module ActiveRecord # :nodoc:
65
65
  def initialize(name, as: nil, scope: nil, eager_load: nil, case_sensitive: false)
66
66
  @cols = Array.wrap(as)
67
67
  @eager_load = Array.wrap(eager_load).presence
68
+ if @eager_load
69
+ inner = @eager_load.inspect
70
+ ActiveSupport::Deprecation.warn("using :eager_load in sortable_by blocks is deprecated. Please pass scope: -> { includes(#{inner}) } instead.")
71
+ end
68
72
  @case_sensitive = case_sensitive == true
69
73
 
70
74
  # validate custom_scope
@@ -101,7 +105,7 @@ module ActiveRecord # :nodoc:
101
105
  end
102
106
 
103
107
  relation = relation.eager_load(*@eager_load) if @eager_load
104
- relation = relation.instance_eval(&@custom_scope) if @custom_scope
108
+ relation = relation.instance_exec(&@custom_scope) if @custom_scope
105
109
  relation
106
110
  end
107
111
  end
data/sortable-by.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'sortable-by'
3
- s.version = '0.13.3'
3
+ s.version = '0.14.0'
4
4
  s.authors = ['Dimitrij Denissenko']
5
5
  s.email = ['dimitrij@blacksquaremedia.com']
6
6
  s.summary = 'Generate white-listed sort scopes from URL parameter values'
@@ -9,7 +9,6 @@ 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
 
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.13.3
4
+ version: 0.14.0
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-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -128,8 +128,6 @@ files:
128
128
  - lib/sortable-by.rb
129
129
  - lib/sortable_by.rb
130
130
  - sortable-by.gemspec
131
- - spec/active_record/sortable_by_spec.rb
132
- - spec/spec_helper.rb
133
131
  homepage: https://github.com/bsm/sortable-by
134
132
  licenses:
135
133
  - MIT
@@ -154,6 +152,4 @@ rubygems_version: 3.3.3
154
152
  signing_key:
155
153
  specification_version: 4
156
154
  summary: Generate white-listed sort scopes from URL parameter values
157
- test_files:
158
- - spec/active_record/sortable_by_spec.rb
159
- - spec/spec_helper.rb
155
+ test_files: []
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveRecord::SortableBy do
4
- before do
5
- c = ActiveRecord::Base.connection
6
- c.tables.each do |t|
7
- c.update "DELETE FROM #{t}"
8
- end
9
- end
10
-
11
- it 'has config' do
12
- expect(Post._sortable_by_config._fields.keys).to match_array(%w[title created])
13
- expect(Post._sortable_by_config._default).to eq('-created')
14
- expect(SubPost._sortable_by_config._fields.keys).to match_array(%w[title created])
15
- expect(SubPost._sortable_by_config._default).to eq('-created')
16
-
17
- expect(App._sortable_by_config._fields.keys).to match_array(%w[name version])
18
- expect(App._sortable_by_config._default).to eq('name')
19
-
20
- expect(Shop._sortable_by_config._fields.keys).to be_empty
21
- expect(Shop._sortable_by_config._default).to be_nil
22
-
23
- expect(Product._sortable_by_config._fields.keys).to match_array(%w[name shop])
24
- expect(Product._sortable_by_config._default).to eq('shop,name')
25
- end
26
-
27
- it 'supports simple ordering' do
28
- Post.create! title: 'A', created_at: Time.at(1515151500)
29
- Post.create! title: 'b', created_at: Time.at(1515151600)
30
- Post.create! title: 'C', created_at: Time.at(1515151400)
31
-
32
- expect(Post.sorted_by(nil).pluck(:title)).to eq(%w[b A C])
33
- expect(Post.sorted_by('').pluck(:title)).to eq(%w[b A C])
34
- expect(Post.sorted_by('invalid').pluck(:title)).to eq(%w[b A C])
35
-
36
- expect(Post.sorted_by('-created').pluck(:title)).to eq(%w[b A C])
37
- expect(Post.sorted_by('created').pluck(:title)).to eq(%w[C A b])
38
-
39
- expect(Post.sorted_by('title').pluck(:title)).to eq(%w[A C b])
40
- expect(Post.sorted_by('-title').pluck(:title)).to eq(%w[b C A])
41
- expect(Post.sorted_by(' title ').pluck(:title)).to eq(%w[A C b])
42
- end
43
-
44
- it 'supports array params' do
45
- Post.create! title: 'A', created_at: Time.at(1515151500)
46
- Post.create! title: 'C', created_at: Time.at(1515151400)
47
- Post.create! title: 'B', created_at: Time.at(1515151400)
48
-
49
- expect(Post.sorted_by(['created', '-title']).pluck(:title)).to eq(%w[C B A])
50
- expect(Post.sorted_by(['created , -title']).pluck(:title)).to eq(%w[C B A])
51
- end
52
-
53
- it 'supports STI inheritance and overrides' do
54
- SubPost.create! title: 'A', created_at: Time.at(1515151700)
55
- SubPost.create! title: 'b', created_at: Time.at(1515151600)
56
- Post.create! title: 'C', created_at: Time.at(1515151400)
57
- SubPost.create! title: 'D', created_at: Time.at(1515151500)
58
-
59
- expect(Post.sorted_by(nil).pluck(:title)).to eq(%w[A b D C])
60
- expect(SubPost.sorted_by(nil).pluck(:title)).to eq(%w[A b D])
61
- expect(SubPost.sorted_by('-created').pluck(:title)).to eq(%w[A b D])
62
- expect(SubPost.sorted_by('created').pluck(:title)).to eq(%w[D b A])
63
-
64
- expect(Post.sorted_by('title').pluck(:title)).to eq(%w[A C D b])
65
- expect(SubPost.sorted_by('title').pluck(:title)).to eq(%w[A b D])
66
- end
67
-
68
- it 'supports composition' do
69
- App.create! name: 'E', major: 0, minor: 9, patch: 2
70
- App.create! name: 'A', major: 1, minor: 0, patch: 1
71
- App.create! name: 'D', major: 1, minor: 0, patch: 6
72
- App.create! name: 'C', major: 1, minor: 1, patch: 0
73
- App.create! name: 'B', major: 2, minor: 2, patch: 0
74
-
75
- expect(App.sorted_by(nil).pluck(:name)).to eq(%w[A B C D E])
76
- expect(App.sorted_by('version').pluck(:name)).to eq(%w[E A D C B])
77
- expect(App.sorted_by('-version').pluck(:name)).to eq(%w[B C D A E])
78
- end
79
-
80
- it 'supports associations' do
81
- y = Shop.create! name: 'Y'
82
- x = Shop.create! name: 'X'
83
-
84
- Product.create! name: 'a', shop_id: y.id
85
- Product.create! name: 'B', shop_id: y.id, active: false
86
- Product.create! name: 'c', shop_id: x.id
87
- Product.create! name: 'D', shop_id: y.id
88
- Product.create! name: 'e', shop_id: x.id
89
- Product.create! name: 'f', shop_id: x.id, active: false
90
-
91
- expect(Product.sorted_by(nil).pluck(:name)).to eq(%w[c e f a B D])
92
- expect(Product.where(active: true).sorted_by(nil).pluck(:name)).to eq(%w[c e a D])
93
- expect(Product.sorted_by('name').pluck(:name)).to eq(%w[a B c D e f])
94
- end
95
- end
data/spec/spec_helper.rb DELETED
@@ -1,72 +0,0 @@
1
- ENV['RACK_ENV'] ||= 'test'
2
- require 'sortable-by'
3
- require 'rspec'
4
-
5
- ActiveRecord::Base.configurations = {
6
- 'test' => {
7
- 'adapter' => 'sqlite3',
8
- 'database' => ':memory:',
9
- },
10
- }
11
- ActiveRecord::Base.establish_connection :test
12
-
13
- ActiveRecord::Base.connection.create_table :posts do |t|
14
- t.string :type
15
- t.string :title, null: false
16
- t.timestamp :created_at, null: false
17
- end
18
-
19
- class Post < ActiveRecord::Base
20
- sortable_by :title, default: '-created', case_sensitive: true do |s|
21
- s.field :created, as: arel_table[:created_at]
22
- end
23
- end
24
-
25
- class SubPost < Post
26
- sortable_by do |s|
27
- s.field :title
28
- end
29
- end
30
-
31
- # ---------------------------------------------------------------------
32
-
33
- ActiveRecord::Base.connection.create_table :apps do |t|
34
- t.string :name, null: false
35
- t.integer :major, null: false
36
- t.integer :minor, null: false
37
- t.integer :patch, null: false
38
- end
39
-
40
- class App < ActiveRecord::Base
41
- sortable_by :name do |s|
42
- s.field :version, as: %i[major minor patch]
43
- end
44
- end
45
-
46
- # ---------------------------------------------------------------------
47
-
48
- ActiveRecord::Base.connection.create_table :shops do |t|
49
- t.string :name, null: false
50
- end
51
-
52
- class Shop < ActiveRecord::Base
53
- end
54
-
55
- # ---------------------------------------------------------------------
56
-
57
- ActiveRecord::Base.connection.create_table :products do |t|
58
- t.string :name, null: false
59
- t.integer :shop_id, null: false
60
- t.boolean :active, null: false, default: true
61
- t.foreign_key :shops
62
- end
63
-
64
- class Product < ActiveRecord::Base
65
- belongs_to :shop
66
-
67
- sortable_by do |s|
68
- s.field :name
69
- s.field :shop, as: Shop.arel_table[:name], eager_load: :shop
70
- s.default 'shop,name'
71
- end
72
- end