ranked-model 0.4.8 → 0.4.11
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/FUNDING.yml +3 -0
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +107 -0
- data/.gitignore +1 -0
- data/Appraisals +14 -45
- data/CHANGELOG.md +9 -0
- data/Readme.mkd +54 -1
- data/gemfiles/rails_5_2.gemfile +3 -3
- data/gemfiles/rails_6_0.gemfile +2 -2
- data/gemfiles/rails_6_1.gemfile +2 -2
- data/gemfiles/rails_7_0.gemfile +22 -0
- data/lib/ranked-model/ranker.rb +367 -356
- data/lib/ranked-model/version.rb +1 -1
- data/ranked-model.gemspec +3 -1
- data/spec/duck-model/inferred_ducks_spec.rb +71 -0
- data/spec/notifications_spec.rb +89 -0
- data/spec/support/database.yml +2 -0
- metadata +15 -8
- data/gemfiles/rails_4_2.gemfile +0 -23
- data/gemfiles/rails_5_0.gemfile +0 -22
- data/gemfiles/rails_5_1.gemfile +0 -22
data/lib/ranked-model/version.rb
CHANGED
data/ranked-model.gemspec
CHANGED
@@ -13,7 +13,9 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{ranked-model is a modern row sorting library built for Rails 4.2+. It uses ARel aggressively and is better optimized than most other libraries.}
|
14
14
|
s.license = 'MIT'
|
15
15
|
|
16
|
-
s.
|
16
|
+
s.metadata["funding_uri"] = "https://github.com/sponsors/brendon"
|
17
|
+
|
18
|
+
s.add_dependency "activerecord", ">= 5.2"
|
17
19
|
s.add_development_dependency "rspec", "~> 3"
|
18
20
|
s.add_development_dependency "rspec-its"
|
19
21
|
s.add_development_dependency "mocha"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Duck do
|
4
|
+
before do
|
5
|
+
5.times do |i|
|
6
|
+
Duck.create(name: "Duck #{i + 1}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "updating a duck order with last" do
|
11
|
+
it "should maintain the order after creating a new duck" do
|
12
|
+
duck = Duck.first
|
13
|
+
duck.update(row_position: :last)
|
14
|
+
expect(duck.row_rank).to eq(4)
|
15
|
+
|
16
|
+
Duck.create(name: "Wacky")
|
17
|
+
|
18
|
+
expect(duck.row_rank).to eq(4)
|
19
|
+
|
20
|
+
duck.update(pond: 'Shin')
|
21
|
+
expect(duck.row_rank).to eq(4)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "updating a duck order with first" do
|
26
|
+
it "should maintain the order after creating a new duck" do
|
27
|
+
duck = Duck.last
|
28
|
+
duck.update(row_position: :first)
|
29
|
+
expect(duck.row_rank).to eq(0)
|
30
|
+
|
31
|
+
Duck.create(name: "Wacky")
|
32
|
+
|
33
|
+
expect(duck.row_rank).to eq(0)
|
34
|
+
|
35
|
+
duck.update(pond: 'Shin')
|
36
|
+
expect(duck.row_rank).to eq(0)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "updating a duck order with up" do
|
41
|
+
it "should maintain the order after creating a new duck" do
|
42
|
+
duck_id = Duck.ranker(:row).with(Duck.new).current_at_position(2).instance.id
|
43
|
+
duck = Duck.find(duck_id)
|
44
|
+
duck.update(row_position: :up)
|
45
|
+
expect(duck.row_rank).to eq(1)
|
46
|
+
|
47
|
+
Duck.create(name: "Wacky")
|
48
|
+
|
49
|
+
expect(duck.row_rank).to eq(1)
|
50
|
+
|
51
|
+
duck.update(pond: 'Shin')
|
52
|
+
expect(duck.row_rank).to eq(1)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "updating a duck order with down" do
|
57
|
+
it "should maintain the order after creating a new duck" do
|
58
|
+
duck_id = Duck.ranker(:row).with(Duck.new).current_at_position(2).instance.id
|
59
|
+
duck = Duck.find(duck_id)
|
60
|
+
duck.update(row_position: :down)
|
61
|
+
expect(duck.row_rank).to eq(3)
|
62
|
+
|
63
|
+
Duck.create(name: "Wacky")
|
64
|
+
|
65
|
+
expect(duck.row_rank).to eq(3)
|
66
|
+
|
67
|
+
duck.update(pond: 'Shin')
|
68
|
+
expect(duck.row_rank).to eq(3)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "notifications" do
|
4
|
+
before do
|
5
|
+
@notifications_count = 0
|
6
|
+
@notification_payloads = []
|
7
|
+
|
8
|
+
ActiveSupport::Notifications.subscribe("ranked_model.ranks_updated") do |name, start, finish, id, payload|
|
9
|
+
@notifications_count += 1
|
10
|
+
@notification_payloads << payload
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
ActiveSupport::Notifications.unsubscribe("ranked_model.ranks_updated")
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when rearranging" do
|
19
|
+
it "notifies subscribers with the instance" do
|
20
|
+
Number.create(order: RankedModel::MAX_RANK_VALUE)
|
21
|
+
second_number = Number.create(order: RankedModel::MAX_RANK_VALUE)
|
22
|
+
|
23
|
+
expect(@notifications_count).to eq(1)
|
24
|
+
expect(@notification_payloads.last[:instance]).to eq(second_number)
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with scope" do
|
28
|
+
it "notifies subscribers with the instance and scope" do
|
29
|
+
Duck.create(size: RankedModel::MAX_RANK_VALUE, pond: "Shin")
|
30
|
+
second_duck = Duck.create(size: RankedModel::MAX_RANK_VALUE, pond: "Shin")
|
31
|
+
|
32
|
+
expect(@notifications_count).to eq(1)
|
33
|
+
expect(@notification_payloads.last[:instance]).to eq(second_duck)
|
34
|
+
expect(@notification_payloads.last[:scope]).to eq(:in_shin_pond)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with with_same" do
|
39
|
+
it "notifies subscribers with the instance and with_same" do
|
40
|
+
Duck.create(age: RankedModel::MAX_RANK_VALUE, pond: "Shin")
|
41
|
+
second_duck = Duck.create(age: RankedModel::MAX_RANK_VALUE, pond: "Shin")
|
42
|
+
|
43
|
+
expect(@notifications_count).to eq(1)
|
44
|
+
expect(@notification_payloads.last[:instance]).to eq(second_duck)
|
45
|
+
expect(@notification_payloads.last[:with_same]).to eq(:pond)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when rebalancing" do
|
51
|
+
it "notifies subscribers with the instance" do
|
52
|
+
31.times { Number.create }
|
53
|
+
thirty_second_number = Number.create
|
54
|
+
|
55
|
+
expect(@notifications_count).to eq(1)
|
56
|
+
expect(@notification_payloads.last[:instance]).to eq(thirty_second_number)
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with scope" do
|
60
|
+
it "notifies subscribers with the instance and scope" do
|
61
|
+
31.times { Duck.create(pond: "Shin") }
|
62
|
+
thirty_second_duck = Duck.create(pond: "Shin")
|
63
|
+
|
64
|
+
expect(@notifications_count).to eq(4) # Duck has four ranks
|
65
|
+
expect(@notification_payloads.last[:instance]).to eq(thirty_second_duck)
|
66
|
+
expect(@notification_payloads.map { |p| p[:scope] }).to include(:in_shin_pond)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with with_same" do
|
71
|
+
it "notifies subscribers with the instance and with_same" do
|
72
|
+
31.times { Duck.create(pond: "Shin") }
|
73
|
+
thirty_second_duck = Duck.create(pond: "Shin")
|
74
|
+
|
75
|
+
expect(@notifications_count).to eq(4)
|
76
|
+
expect(@notification_payloads.last[:instance]).to eq(thirty_second_duck)
|
77
|
+
expect(@notification_payloads.map { |p| p[:with_same] }).to include(:pond)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when not rearranging or rebalancing" do
|
83
|
+
it "does not notify subscribers" do
|
84
|
+
Number.create
|
85
|
+
|
86
|
+
expect(@notifications_count).to eq(0)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/spec/support/database.yml
CHANGED
@@ -6,6 +6,7 @@ sqlite:
|
|
6
6
|
|
7
7
|
mysql:
|
8
8
|
adapter: mysql2
|
9
|
+
host: 127.0.0.1
|
9
10
|
database: ranked_model_test
|
10
11
|
pool: 5
|
11
12
|
timeout: 5000
|
@@ -14,6 +15,7 @@ mysql:
|
|
14
15
|
|
15
16
|
postgresql:
|
16
17
|
adapter: postgresql
|
18
|
+
host: 127.0.0.1
|
17
19
|
database: ranked_model_test
|
18
20
|
pool: 5
|
19
21
|
timeout: 5000
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ranked-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Beale
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,20 +130,22 @@ executables: []
|
|
130
130
|
extensions: []
|
131
131
|
extra_rdoc_files: []
|
132
132
|
files:
|
133
|
+
- ".github/FUNDING.yml"
|
134
|
+
- ".github/dependabot.yml"
|
135
|
+
- ".github/workflows/ci.yml"
|
133
136
|
- ".gitignore"
|
134
137
|
- ".rspec"
|
135
138
|
- ".travis.yml"
|
136
139
|
- Appraisals
|
140
|
+
- CHANGELOG.md
|
137
141
|
- Gemfile
|
138
142
|
- LICENSE
|
139
143
|
- Rakefile
|
140
144
|
- Readme.mkd
|
141
|
-
- gemfiles/rails_4_2.gemfile
|
142
|
-
- gemfiles/rails_5_0.gemfile
|
143
|
-
- gemfiles/rails_5_1.gemfile
|
144
145
|
- gemfiles/rails_5_2.gemfile
|
145
146
|
- gemfiles/rails_6_0.gemfile
|
146
147
|
- gemfiles/rails_6_1.gemfile
|
148
|
+
- gemfiles/rails_7_0.gemfile
|
147
149
|
- lib/ranked-model.rb
|
148
150
|
- lib/ranked-model/railtie.rb
|
149
151
|
- lib/ranked-model/ranker.rb
|
@@ -152,9 +154,11 @@ files:
|
|
152
154
|
- ranked-model.gemspec
|
153
155
|
- spec/duck-model/column_default_ducks_spec.rb
|
154
156
|
- spec/duck-model/duck_spec.rb
|
157
|
+
- spec/duck-model/inferred_ducks_spec.rb
|
155
158
|
- spec/duck-model/lots_of_ducks_spec.rb
|
156
159
|
- spec/duck-model/wrong_ducks_spec.rb
|
157
160
|
- spec/ego-model/ego_spec.rb
|
161
|
+
- spec/notifications_spec.rb
|
158
162
|
- spec/number-model/number_spec.rb
|
159
163
|
- spec/player-model/records_already_exist_spec.rb
|
160
164
|
- spec/ranked-model/ranker_spec.rb
|
@@ -168,7 +172,8 @@ files:
|
|
168
172
|
homepage: https://github.com/mixonic/ranked-model
|
169
173
|
licenses:
|
170
174
|
- MIT
|
171
|
-
metadata:
|
175
|
+
metadata:
|
176
|
+
funding_uri: https://github.com/sponsors/brendon
|
172
177
|
post_install_message:
|
173
178
|
rdoc_options: []
|
174
179
|
require_paths:
|
@@ -191,9 +196,11 @@ summary: An acts_as_sortable replacement built for Rails 4.2+
|
|
191
196
|
test_files:
|
192
197
|
- spec/duck-model/column_default_ducks_spec.rb
|
193
198
|
- spec/duck-model/duck_spec.rb
|
199
|
+
- spec/duck-model/inferred_ducks_spec.rb
|
194
200
|
- spec/duck-model/lots_of_ducks_spec.rb
|
195
201
|
- spec/duck-model/wrong_ducks_spec.rb
|
196
202
|
- spec/ego-model/ego_spec.rb
|
203
|
+
- spec/notifications_spec.rb
|
197
204
|
- spec/number-model/number_spec.rb
|
198
205
|
- spec/player-model/records_already_exist_spec.rb
|
199
206
|
- spec/ranked-model/ranker_spec.rb
|
data/gemfiles/rails_4_2.gemfile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "activerecord", "~> 4.2.0"
|
6
|
-
|
7
|
-
group :sqlite do
|
8
|
-
gem "sqlite3", "~> 1.3.13", platform: :ruby
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24", platform: :jruby
|
10
|
-
end
|
11
|
-
|
12
|
-
group :postgresql do
|
13
|
-
gem "pg", "~> 0.18.4", platform: :ruby
|
14
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.24", platform: :jruby
|
15
|
-
end
|
16
|
-
|
17
|
-
group :mysql do
|
18
|
-
gem "mysql2", "~> 0.4.0", platform: :ruby
|
19
|
-
gem "jdbc-mysql", "~> 5.1.47", platform: :jruby
|
20
|
-
gem "activerecord-jdbcmysql-adapter", "~> 1.3.24", platform: :jruby
|
21
|
-
end
|
22
|
-
|
23
|
-
gemspec path: "../"
|
data/gemfiles/rails_5_0.gemfile
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "activerecord", "~> 5.0.0"
|
6
|
-
|
7
|
-
group :sqlite do
|
8
|
-
gem "sqlite3", "~> 1.3.13", platform: :ruby
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 50.0", platform: :jruby
|
10
|
-
end
|
11
|
-
|
12
|
-
group :postgresql do
|
13
|
-
gem "pg", "~> 1.2.0", platform: :ruby
|
14
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 50.0", platform: :jruby
|
15
|
-
end
|
16
|
-
|
17
|
-
group :mysql do
|
18
|
-
gem "mysql2", "~> 0.5.0", platform: :ruby
|
19
|
-
gem "activerecord-jdbcmysql-adapter", "~> 50.0", platform: :jruby
|
20
|
-
end
|
21
|
-
|
22
|
-
gemspec path: "../"
|
data/gemfiles/rails_5_1.gemfile
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "activerecord", "~> 5.1.0"
|
6
|
-
|
7
|
-
group :sqlite do
|
8
|
-
gem "sqlite3", "~> 1.3.13", platform: :ruby
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 51.0", platform: :jruby
|
10
|
-
end
|
11
|
-
|
12
|
-
group :postgresql do
|
13
|
-
gem "pg", "~> 1.2.0", platform: :ruby
|
14
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 51.0", platform: :jruby
|
15
|
-
end
|
16
|
-
|
17
|
-
group :mysql do
|
18
|
-
gem "mysql2", "~> 0.5.0", platform: :ruby
|
19
|
-
gem "activerecord-jdbcmysql-adapter", "~> 51.0", platform: :jruby
|
20
|
-
end
|
21
|
-
|
22
|
-
gemspec path: "../"
|