ranked-model 0.4.11 → 0.5.0
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/ci.yml +8 -43
- data/Appraisals +6 -50
- data/CHANGELOG.md +59 -1
- data/Readme.mkd +2 -2
- data/gemfiles/{rails_5_2.gemfile → rails_7_2.gemfile} +1 -4
- data/gemfiles/rails_8_0.gemfile +19 -0
- data/gemfiles/rails_8_1.gemfile +19 -0
- data/lib/ranked-model/ranker.rb +6 -14
- data/lib/ranked-model/version.rb +1 -1
- data/ranked-model.gemspec +6 -4
- data/spec/duck-model/column_default_ducks_spec.rb +1 -0
- data/spec/number-model/connection_checkout_spec.rb +37 -0
- data/spec/ranked-model/ranker_spec.rb +30 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/active_record.rb +1 -1
- metadata +16 -18
- data/gemfiles/rails_6_0.gemfile +0 -22
- data/gemfiles/rails_6_1.gemfile +0 -22
- data/gemfiles/rails_7_0.gemfile +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1dcb2ee2687b9476e0253d3498178ff4dd42a8a8057c1ddeec94e905c63e2b8a
|
|
4
|
+
data.tar.gz: ab19cb890b758a0b3f2e22f1abae0ac5afd0fc20d431e6d7d65c4ce602a5a6bf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d7afc3a875a13911d12fda93d35e323e06c3af01a1e00b1e81539d5181138b4475cd217e9d33b238af09d1b0863351516d92f3cadbebe871674c360960a373bb
|
|
7
|
+
data.tar.gz: d6d723da9e3314dc2f4d3fa0dae19081774a88eb06fd17ce87d2711d43c0f720c23708d9764edda73ba5a340b7c5c4b01895c283773f5746f947e569fbfdcc35
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -10,55 +10,20 @@ jobs:
|
|
|
10
10
|
fail-fast: false
|
|
11
11
|
matrix:
|
|
12
12
|
ruby:
|
|
13
|
-
- 2.5
|
|
14
|
-
- 2.6
|
|
15
|
-
- 2.7
|
|
16
|
-
- '3.0'
|
|
17
|
-
- 3.1
|
|
18
|
-
- 3.2
|
|
19
13
|
- 3.3
|
|
14
|
+
- 3.4
|
|
15
|
+
- '4.0'
|
|
20
16
|
gemfile:
|
|
21
|
-
- gemfiles/
|
|
22
|
-
- gemfiles/
|
|
23
|
-
- gemfiles/
|
|
24
|
-
- gemfiles/rails_7_0.gemfile
|
|
17
|
+
- gemfiles/rails_7_2.gemfile
|
|
18
|
+
- gemfiles/rails_8_0.gemfile
|
|
19
|
+
- gemfiles/rails_8_1.gemfile
|
|
25
20
|
db:
|
|
26
21
|
- sqlite
|
|
27
22
|
- mysql
|
|
28
23
|
- postgresql
|
|
29
24
|
exclude:
|
|
30
|
-
- ruby:
|
|
31
|
-
gemfile: gemfiles/
|
|
32
|
-
- ruby: 2.6
|
|
33
|
-
gemfile: gemfiles/rails_7_0.gemfile
|
|
34
|
-
- ruby: '3.0'
|
|
35
|
-
gemfile: gemfiles/rails_5_2.gemfile
|
|
36
|
-
- ruby: 3.1
|
|
37
|
-
gemfile: gemfiles/rails_5_2.gemfile
|
|
38
|
-
- ruby: 3.2
|
|
39
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
|
40
|
-
- ruby: 3.2
|
|
41
|
-
gemfile: gemfiles/rails_5_0.gemfile
|
|
42
|
-
- ruby: 3.2
|
|
43
|
-
gemfile: gemfiles/rails_5_1.gemfile
|
|
44
|
-
- ruby: 3.2
|
|
45
|
-
gemfile: gemfiles/rails_5_2.gemfile
|
|
46
|
-
- ruby: 3.2
|
|
47
|
-
gemfile: gemfiles/rails_6_0.gemfile
|
|
48
|
-
- ruby: 3.2
|
|
49
|
-
gemfile: gemfiles/rails_6_1.gemfile
|
|
50
|
-
- ruby: 3.3
|
|
51
|
-
gemfile: gemfiles/rails_4_2.gemfile
|
|
52
|
-
- ruby: 3.3
|
|
53
|
-
gemfile: gemfiles/rails_5_0.gemfile
|
|
54
|
-
- ruby: 3.3
|
|
55
|
-
gemfile: gemfiles/rails_5_1.gemfile
|
|
56
|
-
- ruby: 3.3
|
|
57
|
-
gemfile: gemfiles/rails_5_2.gemfile
|
|
58
|
-
- ruby: 3.3
|
|
59
|
-
gemfile: gemfiles/rails_6_0.gemfile
|
|
60
|
-
- ruby: 3.3
|
|
61
|
-
gemfile: gemfiles/rails_6_1.gemfile
|
|
25
|
+
- ruby: '4.0'
|
|
26
|
+
gemfile: gemfiles/rails_7_2.gemfile
|
|
62
27
|
os:
|
|
63
28
|
- ubuntu-latest
|
|
64
29
|
services:
|
|
@@ -89,7 +54,7 @@ jobs:
|
|
|
89
54
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
|
90
55
|
DB: ${{ matrix.db }}
|
|
91
56
|
steps:
|
|
92
|
-
- uses: actions/checkout@
|
|
57
|
+
- uses: actions/checkout@v7
|
|
93
58
|
- name: Set up Ruby
|
|
94
59
|
uses: ruby/setup-ruby@v1
|
|
95
60
|
with:
|
data/Appraisals
CHANGED
|
@@ -1,55 +1,11 @@
|
|
|
1
|
-
appraise "rails-
|
|
2
|
-
|
|
3
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 52.0", platform: :jruby
|
|
4
|
-
end
|
|
5
|
-
group :mysql do
|
|
6
|
-
gem "activerecord-jdbcmysql-adapter", "~> 52.0", platform: :jruby
|
|
7
|
-
end
|
|
8
|
-
group :postgresql do
|
|
9
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 52.0", platform: :jruby
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
gem "activerecord", "~> 5.2.0"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
appraise "rails-6-0" do
|
|
16
|
-
group :sqlite do
|
|
17
|
-
gem "sqlite3", "~> 1.4", platform: :ruby
|
|
18
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 60.0", platform: :jruby
|
|
19
|
-
end
|
|
20
|
-
group :mysql do
|
|
21
|
-
gem "activerecord-jdbcmysql-adapter", "~> 60.0", platform: :jruby
|
|
22
|
-
end
|
|
23
|
-
group :postgresql do
|
|
24
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 60.0", platform: :jruby
|
|
25
|
-
end
|
|
26
|
-
gem "activerecord", "~> 6.0.0"
|
|
1
|
+
appraise "rails-7-2" do
|
|
2
|
+
gem "activerecord", "~> 7.2.0"
|
|
27
3
|
end
|
|
28
4
|
|
|
29
|
-
appraise "rails-
|
|
30
|
-
|
|
31
|
-
gem "sqlite3", "~> 1.4", platform: :ruby
|
|
32
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 61.0", platform: :jruby
|
|
33
|
-
end
|
|
34
|
-
group :mysql do
|
|
35
|
-
gem "activerecord-jdbcmysql-adapter", "~> 61.0", platform: :jruby
|
|
36
|
-
end
|
|
37
|
-
group :postgresql do
|
|
38
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0", platform: :jruby
|
|
39
|
-
end
|
|
40
|
-
gem "activerecord", "~> 6.1.0"
|
|
5
|
+
appraise "rails-8-0" do
|
|
6
|
+
gem "activerecord", "~> 8.0.0"
|
|
41
7
|
end
|
|
42
8
|
|
|
43
|
-
appraise "rails-
|
|
44
|
-
|
|
45
|
-
gem "sqlite3", "~> 1.4", platform: :ruby
|
|
46
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 61.0", platform: :jruby
|
|
47
|
-
end
|
|
48
|
-
group :mysql do
|
|
49
|
-
gem "activerecord-jdbcmysql-adapter", "~> 61.0", platform: :jruby
|
|
50
|
-
end
|
|
51
|
-
group :postgresql do
|
|
52
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0", platform: :jruby
|
|
53
|
-
end
|
|
54
|
-
gem "activerecord", "~> 7.0.0"
|
|
9
|
+
appraise "rails-8-1" do
|
|
10
|
+
gem "activerecord", "~> 8.1.0"
|
|
55
11
|
end
|
data/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,67 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
-
## [0.
|
|
3
|
+
## [0.5.0] - 2026-10-19
|
|
4
|
+
|
|
5
|
+
- Require Ruby 3.3+ and Rails 7.2+.
|
|
6
|
+
- Avoid permanently checking out a database connection when ranking. Thanks @joeljunstrom!
|
|
7
|
+
- Fix `rebalance_ranks` rounding that could push rank values past the maximum integer column value. Thanks @RNDcpp!
|
|
8
|
+
|
|
9
|
+
## [0.4.11] - 2024-11-20
|
|
4
10
|
|
|
5
11
|
- Add `funding_uri` to gemspec.
|
|
6
12
|
|
|
7
13
|
## [0.4.10] - 2024-08-09
|
|
8
14
|
|
|
9
15
|
- Publish ActiveSupport notifications on rebalancing. Thanks @tjvc!
|
|
16
|
+
|
|
17
|
+
## [0.4.9] - 2023-08-22
|
|
18
|
+
|
|
19
|
+
- Require Rails 5.2+.
|
|
20
|
+
- Update the `_position` attribute to its integer value after saving with an inferred position (e.g. `:last`), so saving again doesn't move the record. Thanks @CodingAnarchy!
|
|
21
|
+
- Document the possible N+1 when reading `_rank` across many records. Thanks @mrcasals!
|
|
22
|
+
|
|
23
|
+
## [0.4.8] - 2022-02-08
|
|
24
|
+
|
|
25
|
+
- Fix an unbounded query when setting a position of `:last`. Thanks @vincedevendra!
|
|
26
|
+
- Test against Rails 6.1. Thanks @aried3r!
|
|
27
|
+
|
|
28
|
+
## [0.4.7] - 2021-01-17
|
|
29
|
+
|
|
30
|
+
- Quote the column name in `_rank` queries, fixing SQL errors with reserved column names like `order`. Thanks @ursm!
|
|
31
|
+
- Test against Ruby 3.0. Thanks @aried3r!
|
|
32
|
+
- Document the `unless` option. Thanks @aried3r!
|
|
33
|
+
|
|
34
|
+
## [0.4.6] - 2020-03-17
|
|
35
|
+
|
|
36
|
+
- Support unique indexes on the ranked column when rebalancing. Thanks @janklimo!
|
|
37
|
+
|
|
38
|
+
## [0.4.5] - 2020-01-22
|
|
39
|
+
|
|
40
|
+
- Fix a `NoMethodError` when changing a `with_same` attribute and triggering a rebalance at the same time. Thanks @frysch!
|
|
41
|
+
- Don't fail when checking the column default before the table exists. Thanks @walf443!
|
|
42
|
+
- Use an `exists?` query when checking whether a rank is already taken.
|
|
43
|
+
- Test against Rails 6.0. Thanks @walf443!
|
|
44
|
+
|
|
45
|
+
## [0.4.4] - 2019-03-23
|
|
46
|
+
|
|
47
|
+
- Add a `<ranker>_rank` method (e.g. `row_order_rank`) that returns a record's position within the ordered list. Thanks @pragyadaga!
|
|
48
|
+
- Skip the column default check when there's no database connection.
|
|
49
|
+
|
|
50
|
+
## [0.4.3] - 2019-02-13
|
|
51
|
+
|
|
52
|
+
- Raise `RankedModel::NonNilColumnDefault` if the ranked column has a default value in the database.
|
|
53
|
+
- Use `reorder` rather than `order` so a `default_scope` ordering doesn't interfere with ranking.
|
|
54
|
+
- Only look for the record in the current order during rebalancing if it's persisted with a rank.
|
|
55
|
+
|
|
56
|
+
## [0.4.2] - 2018-12-10
|
|
57
|
+
|
|
58
|
+
- Require Rails 4.1+.
|
|
59
|
+
- Rails 5.x compatibility.
|
|
60
|
+
- Fix ranking when the final two ranks are consecutive and a record is moved to second to last.
|
|
61
|
+
- Quote the column name when rearranging ranks. Thanks @mkalygin!
|
|
62
|
+
|
|
63
|
+
## [0.4.1] - 2018-07-12
|
|
64
|
+
|
|
65
|
+
- Extend the rank range to the full signed 4-byte integer range. Thanks @bnauta!
|
|
66
|
+
- Fix memoization of `RankedModel::Ranker::Mapper#finder`.
|
|
67
|
+
- Name the missing attribute in the error raised when one of several `with_same` attributes doesn't exist. Thanks @vinbarnes!
|
data/Readme.mkd
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
**ranked-model** is a modern row sorting library built for Rails
|
|
1
|
+
**ranked-model** is a modern row sorting library built for Rails 7.2+. It uses ARel aggressively and is better optimized than most other libraries.
|
|
2
2
|
|
|
3
3
|
[](https://github.com/brendon/ranked-model/actions/workflows/ci.yml)
|
|
4
4
|
|
|
@@ -12,7 +12,7 @@ Positioning works similarly to Acts As List in that it maintains a sequential li
|
|
|
12
12
|
Installation
|
|
13
13
|
------------
|
|
14
14
|
|
|
15
|
-
ranked-model passes specs with Rails
|
|
15
|
+
ranked-model passes specs with Rails 7.2, 8.0 and 8.1 for MySQL, Postgres, and SQLite on Ruby 3.3, 3.4 and 4.0 (with exceptions, please check the CI setup for supported combinations).
|
|
16
16
|
|
|
17
17
|
To install ranked-model, just add it to your `Gemfile`:
|
|
18
18
|
|
|
@@ -2,21 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
-
gem "activerecord", "~>
|
|
5
|
+
gem "activerecord", "~> 7.2.0"
|
|
6
6
|
|
|
7
7
|
group :sqlite do
|
|
8
8
|
gem "sqlite3", platform: :ruby
|
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 52.0", platform: :jruby
|
|
10
9
|
end
|
|
11
10
|
|
|
12
11
|
group :postgresql do
|
|
13
12
|
gem "pg", platform: :ruby
|
|
14
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 52.0", platform: :jruby
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
group :mysql do
|
|
18
16
|
gem "mysql2", platform: :ruby
|
|
19
|
-
gem "activerecord-jdbcmysql-adapter", "~> 52.0", platform: :jruby
|
|
20
17
|
end
|
|
21
18
|
|
|
22
19
|
gemspec path: "../"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "activerecord", "~> 8.0.0"
|
|
6
|
+
|
|
7
|
+
group :sqlite do
|
|
8
|
+
gem "sqlite3", platform: :ruby
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
group :postgresql do
|
|
12
|
+
gem "pg", platform: :ruby
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
group :mysql do
|
|
16
|
+
gem "mysql2", platform: :ruby
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
gemspec path: "../"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# This file was generated by Appraisal
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
gem "activerecord", "~> 8.1.0"
|
|
6
|
+
|
|
7
|
+
group :sqlite do
|
|
8
|
+
gem "sqlite3", platform: :ruby
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
group :postgresql do
|
|
12
|
+
gem "pg", platform: :ruby
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
group :mysql do
|
|
16
|
+
gem "mysql2", platform: :ruby
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
gemspec path: "../"
|
data/lib/ranked-model/ranker.rb
CHANGED
|
@@ -78,9 +78,7 @@ module RankedModel
|
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def relative_rank
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
finder.where("#{escaped_column} < #{rank}").count(:all)
|
|
81
|
+
finder.where(ranker.column => ...rank).count(:all)
|
|
84
82
|
end
|
|
85
83
|
|
|
86
84
|
def rank
|
|
@@ -190,25 +188,19 @@ module RankedModel
|
|
|
190
188
|
|
|
191
189
|
def rearrange_ranks
|
|
192
190
|
_scope = finder
|
|
193
|
-
|
|
191
|
+
column = instance_class.arel_table[ranker.column]
|
|
194
192
|
# If there is room at the bottom of the list and we're added to the very top of the list...
|
|
195
193
|
if current_first.rank && current_first.rank > RankedModel::MIN_RANK_VALUE && rank == RankedModel::MAX_RANK_VALUE
|
|
196
194
|
# ...then move everyone else down 1 to make room for us at the end
|
|
197
|
-
_scope.
|
|
198
|
-
where( instance_class.arel_table[ranker.column].lteq(rank) ).
|
|
199
|
-
update_all( "#{escaped_column} = #{escaped_column} - 1" )
|
|
195
|
+
_scope.where(ranker.column => ..rank).update_all(ranker.column => column - 1)
|
|
200
196
|
# If there is room at the top of the list and we're added below the last value in the list...
|
|
201
197
|
elsif current_last.rank && current_last.rank < (RankedModel::MAX_RANK_VALUE - 1) && rank < current_last.rank
|
|
202
198
|
# ...then move everyone else at or above our desired rank up 1 to make room for us
|
|
203
|
-
_scope.
|
|
204
|
-
where( instance_class.arel_table[ranker.column].gteq(rank) ).
|
|
205
|
-
update_all( "#{escaped_column} = #{escaped_column} + 1" )
|
|
199
|
+
_scope.where(ranker.column => rank..).update_all(ranker.column => column + 1)
|
|
206
200
|
# If there is room at the bottom of the list and we're added above the lowest value in the list...
|
|
207
201
|
elsif current_first.rank && current_first.rank > RankedModel::MIN_RANK_VALUE && rank > current_first.rank
|
|
208
202
|
# ...then move everyone else below us down 1 and change our rank down 1 to avoid the collission
|
|
209
|
-
_scope.
|
|
210
|
-
where( instance_class.arel_table[ranker.column].lt(rank) ).
|
|
211
|
-
update_all( "#{escaped_column} = #{escaped_column} - 1" )
|
|
203
|
+
_scope.where(ranker.column => ...rank).update_all(ranker.column => column - 1)
|
|
212
204
|
rank_at( rank - 1 )
|
|
213
205
|
else
|
|
214
206
|
rebalance_ranks
|
|
@@ -229,7 +221,7 @@ module RankedModel
|
|
|
229
221
|
|
|
230
222
|
gaps = current_order.size + 1
|
|
231
223
|
range = (RankedModel::MAX_RANK_VALUE - RankedModel::MIN_RANK_VALUE).to_f
|
|
232
|
-
gap_size = (range / gaps).
|
|
224
|
+
gap_size = (range / gaps).floor
|
|
233
225
|
|
|
234
226
|
reset_ranks!
|
|
235
227
|
|
data/lib/ranked-model/version.rb
CHANGED
data/ranked-model.gemspec
CHANGED
|
@@ -9,17 +9,19 @@ Gem::Specification.new do |s|
|
|
|
9
9
|
s.authors = ["Matthew Beale"]
|
|
10
10
|
s.email = ["matt.beale@madhatted.com"]
|
|
11
11
|
s.homepage = "https://github.com/mixonic/ranked-model"
|
|
12
|
-
s.summary = %q{An acts_as_sortable replacement built for Rails
|
|
13
|
-
s.description = %q{ranked-model is a modern row sorting library built for Rails
|
|
12
|
+
s.summary = %q{An acts_as_sortable replacement built for Rails 7.2+}
|
|
13
|
+
s.description = %q{ranked-model is a modern row sorting library built for Rails 7.2+. It uses ARel aggressively and is better optimized than most other libraries.}
|
|
14
14
|
s.license = 'MIT'
|
|
15
15
|
|
|
16
16
|
s.metadata["funding_uri"] = "https://github.com/sponsors/brendon"
|
|
17
17
|
|
|
18
|
-
s.
|
|
18
|
+
s.required_ruby_version = ">= 3.3"
|
|
19
|
+
|
|
20
|
+
s.add_dependency "activerecord", ">= 7.2"
|
|
19
21
|
s.add_development_dependency "rspec", "~> 3"
|
|
20
22
|
s.add_development_dependency "rspec-its"
|
|
21
23
|
s.add_development_dependency "mocha"
|
|
22
|
-
s.add_development_dependency "database_cleaner", "~>
|
|
24
|
+
s.add_development_dependency "database_cleaner-active_record", "~> 2.2"
|
|
23
25
|
s.add_development_dependency "rake", ">= 12.3.3"
|
|
24
26
|
s.add_development_dependency "appraisal"
|
|
25
27
|
s.add_development_dependency "pry"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Number do
|
|
4
|
+
|
|
5
|
+
around { |example|
|
|
6
|
+
begin
|
|
7
|
+
checkout_was = ActiveRecord.permanent_connection_checkout
|
|
8
|
+
ActiveRecord.permanent_connection_checkout = :disallowed
|
|
9
|
+
example.run
|
|
10
|
+
ensure
|
|
11
|
+
ActiveRecord.permanent_connection_checkout = checkout_was
|
|
12
|
+
end
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
# A fresh thread holds no connection lease, unlike the example's own thread
|
|
16
|
+
# where DatabaseCleaner has checked one out for its transaction.
|
|
17
|
+
def without_leased_connection
|
|
18
|
+
Thread.new {
|
|
19
|
+
begin
|
|
20
|
+
yield
|
|
21
|
+
ensure
|
|
22
|
+
Number.delete_all
|
|
23
|
+
end
|
|
24
|
+
}.value
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "rearranges and reads ranks without permanently checking out a connection" do
|
|
28
|
+
ranks = without_leased_connection {
|
|
29
|
+
first = Number.create! :order => 100
|
|
30
|
+
second = Number.create! :order => 100
|
|
31
|
+
[first.reload.order_rank, second.reload.order_rank]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
expect(ranks).to eq([0, 1])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -80,3 +80,33 @@ describe RankedModel::Ranker, 'unless as lambda' do
|
|
|
80
80
|
}
|
|
81
81
|
end
|
|
82
82
|
end
|
|
83
|
+
|
|
84
|
+
# rebalance_ranks should keep all ranks within bounds
|
|
85
|
+
# see: https://github.com/brendon/ranked-model/issues/206
|
|
86
|
+
describe RankedModel::Ranker::Mapper, "rebalance_ranks" do
|
|
87
|
+
around do |example|
|
|
88
|
+
original_min = RankedModel::MIN_RANK_VALUE
|
|
89
|
+
original_max = RankedModel::MAX_RANK_VALUE
|
|
90
|
+
RankedModel.send(:remove_const, :MIN_RANK_VALUE)
|
|
91
|
+
RankedModel.send(:remove_const, :MAX_RANK_VALUE)
|
|
92
|
+
RankedModel.const_set(:MIN_RANK_VALUE, -256)
|
|
93
|
+
RankedModel.const_set(:MAX_RANK_VALUE, 255)
|
|
94
|
+
example.run
|
|
95
|
+
ensure
|
|
96
|
+
RankedModel.send(:remove_const, :MIN_RANK_VALUE)
|
|
97
|
+
RankedModel.send(:remove_const, :MAX_RANK_VALUE)
|
|
98
|
+
RankedModel.const_set(:MIN_RANK_VALUE, original_min)
|
|
99
|
+
RankedModel.const_set(:MAX_RANK_VALUE, original_max)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "keeps all ranks within bounds after rebalancing" do
|
|
103
|
+
27.times { |i| Duck.create(name: "Duck #{i}") }
|
|
104
|
+
duck = Duck.first
|
|
105
|
+
|
|
106
|
+
Duck.ranker(:row).with(duck).instance_eval { rebalance_ranks }
|
|
107
|
+
|
|
108
|
+
ranks = Duck.pluck(:row)
|
|
109
|
+
expect(ranks.max).to be <= RankedModel::MAX_RANK_VALUE
|
|
110
|
+
expect(ranks.min).to be >= RankedModel::MIN_RANK_VALUE
|
|
111
|
+
end
|
|
112
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -8,7 +8,7 @@ require 'pry'
|
|
|
8
8
|
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each {|f| require f}
|
|
9
9
|
|
|
10
10
|
# After the DB connection is setup
|
|
11
|
-
require 'database_cleaner'
|
|
11
|
+
require 'database_cleaner/active_record'
|
|
12
12
|
|
|
13
13
|
# Uncomment this to see Active Record logging for tests
|
|
14
14
|
# ActiveRecord::Base.logger = Logger.new(STDOUT)
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ranked-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthew Beale
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activerecord
|
|
@@ -16,14 +15,14 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
18
|
+
version: '7.2'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
25
|
+
version: '7.2'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: rspec
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -67,19 +66,19 @@ dependencies:
|
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
67
|
version: '0'
|
|
69
68
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: database_cleaner
|
|
69
|
+
name: database_cleaner-active_record
|
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements:
|
|
73
72
|
- - "~>"
|
|
74
73
|
- !ruby/object:Gem::Version
|
|
75
|
-
version:
|
|
74
|
+
version: '2.2'
|
|
76
75
|
type: :development
|
|
77
76
|
prerelease: false
|
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
78
|
requirements:
|
|
80
79
|
- - "~>"
|
|
81
80
|
- !ruby/object:Gem::Version
|
|
82
|
-
version:
|
|
81
|
+
version: '2.2'
|
|
83
82
|
- !ruby/object:Gem::Dependency
|
|
84
83
|
name: rake
|
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -122,7 +121,7 @@ dependencies:
|
|
|
122
121
|
- - ">="
|
|
123
122
|
- !ruby/object:Gem::Version
|
|
124
123
|
version: '0'
|
|
125
|
-
description: ranked-model is a modern row sorting library built for Rails
|
|
124
|
+
description: ranked-model is a modern row sorting library built for Rails 7.2+. It
|
|
126
125
|
uses ARel aggressively and is better optimized than most other libraries.
|
|
127
126
|
email:
|
|
128
127
|
- matt.beale@madhatted.com
|
|
@@ -142,10 +141,9 @@ files:
|
|
|
142
141
|
- LICENSE
|
|
143
142
|
- Rakefile
|
|
144
143
|
- Readme.mkd
|
|
145
|
-
- gemfiles/
|
|
146
|
-
- gemfiles/
|
|
147
|
-
- gemfiles/
|
|
148
|
-
- gemfiles/rails_7_0.gemfile
|
|
144
|
+
- gemfiles/rails_7_2.gemfile
|
|
145
|
+
- gemfiles/rails_8_0.gemfile
|
|
146
|
+
- gemfiles/rails_8_1.gemfile
|
|
149
147
|
- lib/ranked-model.rb
|
|
150
148
|
- lib/ranked-model/railtie.rb
|
|
151
149
|
- lib/ranked-model/ranker.rb
|
|
@@ -159,6 +157,7 @@ files:
|
|
|
159
157
|
- spec/duck-model/wrong_ducks_spec.rb
|
|
160
158
|
- spec/ego-model/ego_spec.rb
|
|
161
159
|
- spec/notifications_spec.rb
|
|
160
|
+
- spec/number-model/connection_checkout_spec.rb
|
|
162
161
|
- spec/number-model/number_spec.rb
|
|
163
162
|
- spec/player-model/records_already_exist_spec.rb
|
|
164
163
|
- spec/ranked-model/ranker_spec.rb
|
|
@@ -174,7 +173,6 @@ licenses:
|
|
|
174
173
|
- MIT
|
|
175
174
|
metadata:
|
|
176
175
|
funding_uri: https://github.com/sponsors/brendon
|
|
177
|
-
post_install_message:
|
|
178
176
|
rdoc_options: []
|
|
179
177
|
require_paths:
|
|
180
178
|
- lib
|
|
@@ -182,17 +180,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
182
180
|
requirements:
|
|
183
181
|
- - ">="
|
|
184
182
|
- !ruby/object:Gem::Version
|
|
185
|
-
version: '
|
|
183
|
+
version: '3.3'
|
|
186
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
185
|
requirements:
|
|
188
186
|
- - ">="
|
|
189
187
|
- !ruby/object:Gem::Version
|
|
190
188
|
version: '0'
|
|
191
189
|
requirements: []
|
|
192
|
-
rubygems_version:
|
|
193
|
-
signing_key:
|
|
190
|
+
rubygems_version: 4.0.20
|
|
194
191
|
specification_version: 4
|
|
195
|
-
summary: An acts_as_sortable replacement built for Rails
|
|
192
|
+
summary: An acts_as_sortable replacement built for Rails 7.2+
|
|
196
193
|
test_files:
|
|
197
194
|
- spec/duck-model/column_default_ducks_spec.rb
|
|
198
195
|
- spec/duck-model/duck_spec.rb
|
|
@@ -201,6 +198,7 @@ test_files:
|
|
|
201
198
|
- spec/duck-model/wrong_ducks_spec.rb
|
|
202
199
|
- spec/ego-model/ego_spec.rb
|
|
203
200
|
- spec/notifications_spec.rb
|
|
201
|
+
- spec/number-model/connection_checkout_spec.rb
|
|
204
202
|
- spec/number-model/number_spec.rb
|
|
205
203
|
- spec/player-model/records_already_exist_spec.rb
|
|
206
204
|
- spec/ranked-model/ranker_spec.rb
|
data/gemfiles/rails_6_0.gemfile
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "https://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "activerecord", "~> 6.0.0"
|
|
6
|
-
|
|
7
|
-
group :sqlite do
|
|
8
|
-
gem "sqlite3", "~> 1.4", platform: :ruby
|
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 60.0", platform: :jruby
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
group :postgresql do
|
|
13
|
-
gem "pg", platform: :ruby
|
|
14
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 60.0", platform: :jruby
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
group :mysql do
|
|
18
|
-
gem "mysql2", platform: :ruby
|
|
19
|
-
gem "activerecord-jdbcmysql-adapter", "~> 60.0", platform: :jruby
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
gemspec path: "../"
|
data/gemfiles/rails_6_1.gemfile
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "https://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "activerecord", "~> 6.1.0"
|
|
6
|
-
|
|
7
|
-
group :sqlite do
|
|
8
|
-
gem "sqlite3", "~> 1.4", platform: :ruby
|
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 61.0", platform: :jruby
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
group :postgresql do
|
|
13
|
-
gem "pg", platform: :ruby
|
|
14
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0", platform: :jruby
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
group :mysql do
|
|
18
|
-
gem "mysql2", platform: :ruby
|
|
19
|
-
gem "activerecord-jdbcmysql-adapter", "~> 61.0", platform: :jruby
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
gemspec path: "../"
|
data/gemfiles/rails_7_0.gemfile
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# This file was generated by Appraisal
|
|
2
|
-
|
|
3
|
-
source "https://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "activerecord", "~> 7.0.0"
|
|
6
|
-
|
|
7
|
-
group :sqlite do
|
|
8
|
-
gem "sqlite3", "~> 1.4", platform: :ruby
|
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 61.0", platform: :jruby
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
group :postgresql do
|
|
13
|
-
gem "pg", platform: :ruby
|
|
14
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0", platform: :jruby
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
group :mysql do
|
|
18
|
-
gem "mysql2", platform: :ruby
|
|
19
|
-
gem "activerecord-jdbcmysql-adapter", "~> 61.0", platform: :jruby
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
gemspec path: "../"
|