ranked-model 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +30 -74
- data/Appraisals +71 -0
- data/Gemfile +2 -27
- data/Readme.mkd +58 -4
- data/gemfiles/rails_3_2.gemfile +24 -0
- data/gemfiles/rails_4_1.gemfile +24 -0
- data/gemfiles/rails_4_2.gemfile +24 -0
- data/lib/ranked-model.rb +3 -3
- data/lib/ranked-model/ranker.rb +4 -3
- data/lib/ranked-model/version.rb +1 -1
- data/ranked-model.gemspec +1 -0
- data/spec/duck-model/duck_spec.rb +29 -0
- data/spec/duck-model/lots_of_ducks_spec.rb +2 -2
- data/spec/duck-model/wrong_ducks_spec.rb +11 -0
- data/spec/support/active_record.rb +7 -2
- data/spec/support/database.yml +9 -17
- metadata +40 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bc1cd219c463a32552a7f583dbb9f52c95a356b
|
4
|
+
data.tar.gz: '0362078c1c550eb8da5e22fa2aa9c69864597f44'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e347568a8c34e9ce8ced2ba819fc8e9f3b297c4dadefff56c8eb0c43cafa12e872e508f4140ded18aea30b7aaed704979b7d2c42030c56f244ce930a150d1125
|
7
|
+
data.tar.gz: 3ebd264cd22bea1038055c36cf460c3e352b3cc4383bfdb3112134808341ee8b9d180782f21b48341003f15b3dbe199d704dfa0fea3cc5bacb396caf377cf8b1
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,82 +1,38 @@
|
|
1
|
+
sudo: false # use newer travis infrastructure
|
1
2
|
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
before_install:
|
5
|
+
- gem install bundler -v 1.16.1
|
2
6
|
before_script:
|
3
7
|
- mysql -e 'create database ranked_model_test;'
|
4
8
|
- psql -c 'create database ranked_model_test;' -U postgres
|
5
9
|
rvm:
|
6
|
-
-
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
-
|
10
|
+
- 1.9.3
|
11
|
+
- 2.1.10
|
12
|
+
- 2.2.10
|
13
|
+
- 2.3.7
|
14
|
+
- 2.4.4
|
15
|
+
- 2.5.1
|
16
|
+
- jruby-9.1.17.0
|
17
|
+
- rbx-3.100
|
12
18
|
env:
|
13
|
-
-
|
14
|
-
-
|
15
|
-
-
|
16
|
-
|
17
|
-
-
|
18
|
-
-
|
19
|
-
-
|
20
|
-
- "ACTIVERECORD_VERSION=3.2.16 DB=mysql_travis"
|
21
|
-
- "ACTIVERECORD_VERSION=3.2.16 DB=postgresql_travis"
|
22
|
-
- "ACTIVERECORD_VERSION=3.1.12"
|
23
|
-
- "ACTIVERECORD_VERSION=3.1.12 DB=mysql_travis"
|
24
|
-
- "ACTIVERECORD_VERSION=3.1.12 DB=postgresql_travis"
|
25
|
-
- "ACTIVERECORD_VERSION=master"
|
26
|
-
- "ACTIVERECORD_VERSION=master DB=mysql_travis"
|
27
|
-
- "ACTIVERECORD_VERSION=master DB=postgresql_travis"
|
19
|
+
- DB=sqlite
|
20
|
+
- DB=mysql
|
21
|
+
- DB=postgresql
|
22
|
+
gemfile:
|
23
|
+
- gemfiles/rails_3_2.gemfile
|
24
|
+
- gemfiles/rails_4_1.gemfile
|
25
|
+
- gemfiles/rails_4_2.gemfile
|
28
26
|
matrix:
|
29
27
|
exclude:
|
30
|
-
-
|
31
|
-
|
32
|
-
-
|
33
|
-
|
34
|
-
-
|
35
|
-
|
36
|
-
-
|
37
|
-
|
38
|
-
- env:
|
39
|
-
|
40
|
-
|
41
|
-
rvm: "1.9.3"
|
42
|
-
- env: "ACTIVERECORD_VERSION=4.1.0.beta1"
|
43
|
-
rvm: "jruby-19mode"
|
44
|
-
- env: "ACTIVERECORD_VERSION=4.1.0.beta1 DB=mysql_travis"
|
45
|
-
rvm: "jruby-19mode"
|
46
|
-
- env: "ACTIVERECORD_VERSION=4.1.0.beta1 DB=postgresql_travis"
|
47
|
-
rvm: "jruby-19mode"
|
48
|
-
- env: "ACTIVERECORD_VERSION=master"
|
49
|
-
rvm: "jruby-19mode"
|
50
|
-
- env: "ACTIVERECORD_VERSION=master DB=mysql_travis"
|
51
|
-
rvm: "jruby-19mode"
|
52
|
-
- env: "ACTIVERECORD_VERSION=master DB=postgresql_travis"
|
53
|
-
rvm: "jruby-19mode"
|
54
|
-
- env: "ACTIVERECORD_VERSION=4.0.2"
|
55
|
-
rvm: "1.9.2"
|
56
|
-
- env: "ACTIVERECORD_VERSION=4.0.2 DB=mysql_travis"
|
57
|
-
rvm: "1.9.2"
|
58
|
-
- env: "ACTIVERECORD_VERSION=4.0.2 DB=postgresql_travis"
|
59
|
-
rvm: "1.9.2"
|
60
|
-
- env: "ACTIVERECORD_VERSION=master"
|
61
|
-
rvm: "1.9.2"
|
62
|
-
- env: "ACTIVERECORD_VERSION=master DB=mysql_travis"
|
63
|
-
rvm: "1.9.2"
|
64
|
-
- env: "ACTIVERECORD_VERSION=master DB=postgresql_travis"
|
65
|
-
rvm: "1.9.2"
|
66
|
-
- env: "ACTIVERECORD_VERSION=master"
|
67
|
-
rvm: "1.9.3"
|
68
|
-
- env: "ACTIVERECORD_VERSION=master DB=mysql_travis"
|
69
|
-
rvm: "1.9.3"
|
70
|
-
- env: "ACTIVERECORD_VERSION=master DB=postgresql_travis"
|
71
|
-
rvm: "1.9.3"
|
72
|
-
allow_failures:
|
73
|
-
# Master may or may not pass
|
74
|
-
- env: "ACTIVERECORD_VERSION=master"
|
75
|
-
- env: "ACTIVERECORD_VERSION=master DB=mysql_travis"
|
76
|
-
- env: "ACTIVERECORD_VERSION=master DB=postgresql_travis"
|
77
|
-
# Rails 3.1 is incompatible with database cleaner 1.2
|
78
|
-
- env: "ACTIVERECORD_VERSION=3.1.12 DB=mysql_travis"
|
79
|
-
- env: "ACTIVERECORD_VERSION=3.1.12 DB=postgresql_travis"
|
80
|
-
# Postgres is not supported before Rails 4.0.
|
81
|
-
- env: "ACTIVERECORD_VERSION=3.1.12 DB=postgresql_travis"
|
82
|
-
- env: "ACTIVERECORD_VERSION=3.2.16 DB=postgresql_travis"
|
28
|
+
- rvm: 2.4.4
|
29
|
+
gemfile: gemfiles/rails_3_2.gemfile
|
30
|
+
- rvm: 2.4.4
|
31
|
+
gemfile: gemfiles/rails_4_1.gemfile
|
32
|
+
- rvm: 2.5.1
|
33
|
+
gemfile: gemfiles/rails_3_2.gemfile
|
34
|
+
- rvm: 2.5.1
|
35
|
+
gemfile: gemfiles/rails_4_1.gemfile
|
36
|
+
- env: DB=postgresql
|
37
|
+
gemfile: gemfiles/rails_3_2.gemfile
|
38
|
+
|
data/Appraisals
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
appraise "rails-3-2" do
|
2
|
+
group :sqlite do
|
3
|
+
gem "sqlite3", platform: :ruby
|
4
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24", platform: :jruby
|
5
|
+
end
|
6
|
+
group :mysql do
|
7
|
+
gem "mysql2", "~> 0.3.21", platform: :ruby
|
8
|
+
gem "activerecord-jdbcmysql-adapter", "~> 1.3.24", platform: :jruby
|
9
|
+
end
|
10
|
+
group :postgresql do
|
11
|
+
gem "pg", "~> 0.18.0", platform: :ruby
|
12
|
+
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.24", platform: :jruby
|
13
|
+
end
|
14
|
+
|
15
|
+
gem "activerecord", "~> 3.2.22.2"
|
16
|
+
end
|
17
|
+
|
18
|
+
appraise "rails-4-1" do
|
19
|
+
group :sqlite do
|
20
|
+
gem "sqlite3", platform: :ruby
|
21
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24", platform: :jruby
|
22
|
+
end
|
23
|
+
group :mysql do
|
24
|
+
gem "mysql2", "~> 0.3.21", platform: :ruby
|
25
|
+
gem "activerecord-jdbcmysql-adapter", "~> 1.3.24", platform: :jruby
|
26
|
+
end
|
27
|
+
group :postgresql do
|
28
|
+
gem "pg", "~> 0.18.0", platform: :ruby
|
29
|
+
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.24", platform: :jruby
|
30
|
+
end
|
31
|
+
|
32
|
+
gem "activerecord", "~> 4.1.16"
|
33
|
+
end
|
34
|
+
|
35
|
+
appraise "rails-4-2" do
|
36
|
+
group :sqlite do
|
37
|
+
gem "sqlite3", platform: :ruby
|
38
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24", platform: :jruby
|
39
|
+
end
|
40
|
+
group :mysql do
|
41
|
+
gem "mysql2", "~> 0.4.10", platform: :ruby
|
42
|
+
gem "activerecord-jdbcmysql-adapter", "~> 1.3.24", platform: :jruby
|
43
|
+
end
|
44
|
+
group :postgresql do
|
45
|
+
gem "pg", "~> 0.18.0", platform: :ruby
|
46
|
+
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.24", platform: :jruby
|
47
|
+
end
|
48
|
+
|
49
|
+
gem "activerecord", "~> 4.2.10"
|
50
|
+
end
|
51
|
+
|
52
|
+
# appraise "rails-5-0" do
|
53
|
+
# group :mysql do
|
54
|
+
# gem "mysql2", "~> 0.4.10", platform: :ruby
|
55
|
+
# end
|
56
|
+
# gem "activerecord", "~> 5.0.6"
|
57
|
+
# end
|
58
|
+
|
59
|
+
# appraise "rails-5-1" do
|
60
|
+
# group :mysql do
|
61
|
+
# gem "mysql2", "~> 0.4.10", platform: :ruby
|
62
|
+
# end
|
63
|
+
# gem "activerecord", "~> 5.1.4"
|
64
|
+
# end
|
65
|
+
|
66
|
+
# appraise "rails-5-2" do
|
67
|
+
# group :mysql do
|
68
|
+
# gem "mysql2", "~> 0.4.10", platform: :ruby
|
69
|
+
# end
|
70
|
+
# gem "activerecord", "~> 5.2.0.rc1"
|
71
|
+
# end
|
data/Gemfile
CHANGED
@@ -3,30 +3,5 @@ source "https://rubygems.org"
|
|
3
3
|
# Specify your gem's dependencies in ranked-model.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
ar_gem_version = case ar_version
|
9
|
-
when "master"
|
10
|
-
gem "activerecord", {github: "rails/rails"}
|
11
|
-
when "default"
|
12
|
-
# Allow the gemspec to specify
|
13
|
-
else
|
14
|
-
gem "activerecord", "~> #{ar_version}"
|
15
|
-
end
|
16
|
-
|
17
|
-
platforms :rbx do
|
18
|
-
gem 'rubysl', '~> 2.0'
|
19
|
-
gem 'rubinius-developer_tools'
|
20
|
-
end
|
21
|
-
|
22
|
-
# SQLite
|
23
|
-
gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0", platforms: :jruby
|
24
|
-
gem "sqlite3", platforms: :ruby
|
25
|
-
|
26
|
-
# Postgres
|
27
|
-
gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
|
28
|
-
gem "pg", platforms: :ruby
|
29
|
-
|
30
|
-
# MySQL
|
31
|
-
gem "activerecord-jdbcmysql-adapter", platforms: :jruby
|
32
|
-
gem "mysql", platforms: :ruby
|
6
|
+
gem 'rubysl', '~> 2.0', platform: :rbx
|
7
|
+
gem 'rubinius-developer_tools', platform: :rbx
|
data/Readme.mkd
CHANGED
@@ -73,7 +73,7 @@ $.ajax({
|
|
73
73
|
Complex Use
|
74
74
|
-----------
|
75
75
|
|
76
|
-
The `ranks` method takes
|
76
|
+
The `ranks` method takes several arguments:
|
77
77
|
|
78
78
|
``` ruby
|
79
79
|
class Duck < ActiveRecord::Base
|
@@ -104,12 +104,66 @@ Pond.first.ducks.rank(:swimming_order)
|
|
104
104
|
Duck.walking.rank(:walking)
|
105
105
|
```
|
106
106
|
|
107
|
+
Single Table Inheritance (STI)
|
108
|
+
------------------------------
|
109
|
+
|
110
|
+
ranked-model scopes your records' positions based on the class name of the object. If you have
|
111
|
+
a STI `type` column set in your model, ranked-model will reference that class for positioning.
|
112
|
+
|
113
|
+
Consider this example:
|
114
|
+
|
115
|
+
``` ruby
|
116
|
+
class Vehicle < ActiveRecord::Base
|
117
|
+
ranks :row_order
|
118
|
+
end
|
119
|
+
|
120
|
+
class Car < Vehicle
|
121
|
+
end
|
122
|
+
|
123
|
+
class Truck < Vehicle
|
124
|
+
end
|
125
|
+
|
126
|
+
car = Car.create!
|
127
|
+
truck = Truck.create!
|
128
|
+
|
129
|
+
car.row_order
|
130
|
+
=> 0
|
131
|
+
truck.row_order
|
132
|
+
=> 0
|
133
|
+
```
|
134
|
+
|
135
|
+
In this example, the `row_order` for both `car` and `truck` will be set to `0` because they have
|
136
|
+
different class names (`Car` and `Truck`, respectively).
|
137
|
+
|
138
|
+
If you would like for both `car` and `truck` to be ranked together based on the base `Vehicle`
|
139
|
+
class instead, use the `class_name` option:
|
140
|
+
|
141
|
+
``` ruby
|
142
|
+
class Vehicle < ActiveRecord::Base
|
143
|
+
ranks :row_order, class_name: 'Vehicle'
|
144
|
+
end
|
145
|
+
|
146
|
+
class Car < Vehicle
|
147
|
+
end
|
148
|
+
|
149
|
+
class Truck < Vehicle
|
150
|
+
end
|
151
|
+
|
152
|
+
car = Car.create!
|
153
|
+
truck = Truck.create!
|
154
|
+
|
155
|
+
car.row_order
|
156
|
+
=> 0
|
157
|
+
truck.row_order
|
158
|
+
=> 4194304
|
159
|
+
```
|
160
|
+
|
107
161
|
Internals
|
108
162
|
---------
|
109
163
|
|
110
|
-
This
|
164
|
+
This library is written using ARel from the ground-up. This leaves the code much cleaner
|
111
165
|
than many implementations. ranked-model is also optimized to write to the database as little
|
112
|
-
as possible: ranks are stored as a number between -
|
166
|
+
as possible: ranks are stored as a number between -2147483648 and 2147483647 (the INT range in MySQL).
|
113
167
|
When an item is given a new position, it assigns itself a rank number between two neighbors.
|
114
168
|
This allows several movements of items before no digits are available between two neighbors. When
|
115
169
|
this occurs, ranked-model will try to shift other records out of the way. If items can't be easily
|
@@ -124,7 +178,7 @@ Fork, clone, write a test, write some code, commit, push, send a pull request.
|
|
124
178
|
The specs can be run with sqlite, postgres, and mysql:
|
125
179
|
|
126
180
|
```
|
127
|
-
DB=
|
181
|
+
DB=postgresql bundle exec rake
|
128
182
|
```
|
129
183
|
|
130
184
|
Is no DB is specified, the tests run against sqlite.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rubysl", "~> 2.0", platform: :rbx
|
6
|
+
gem "rubinius-developer_tools", platform: :rbx
|
7
|
+
gem "activerecord", "~> 3.2.22.2"
|
8
|
+
|
9
|
+
group :sqlite do
|
10
|
+
gem "sqlite3", platform: :ruby
|
11
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24", platform: :jruby
|
12
|
+
end
|
13
|
+
|
14
|
+
group :mysql do
|
15
|
+
gem "mysql2", "~> 0.3.21", platform: :ruby
|
16
|
+
gem "activerecord-jdbcmysql-adapter", "~> 1.3.24", platform: :jruby
|
17
|
+
end
|
18
|
+
|
19
|
+
group :postgresql do
|
20
|
+
gem "pg", "~> 0.18.0", platform: :ruby
|
21
|
+
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.24", platform: :jruby
|
22
|
+
end
|
23
|
+
|
24
|
+
gemspec path: "../"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rubysl", "~> 2.0", platform: :rbx
|
6
|
+
gem "rubinius-developer_tools", platform: :rbx
|
7
|
+
gem "activerecord", "~> 4.1.16"
|
8
|
+
|
9
|
+
group :sqlite do
|
10
|
+
gem "sqlite3", platform: :ruby
|
11
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24", platform: :jruby
|
12
|
+
end
|
13
|
+
|
14
|
+
group :mysql do
|
15
|
+
gem "mysql2", "~> 0.3.21", platform: :ruby
|
16
|
+
gem "activerecord-jdbcmysql-adapter", "~> 1.3.24", platform: :jruby
|
17
|
+
end
|
18
|
+
|
19
|
+
group :postgresql do
|
20
|
+
gem "pg", "~> 0.18.0", platform: :ruby
|
21
|
+
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.24", platform: :jruby
|
22
|
+
end
|
23
|
+
|
24
|
+
gemspec path: "../"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rubysl", "~> 2.0", platform: :rbx
|
6
|
+
gem "rubinius-developer_tools", platform: :rbx
|
7
|
+
gem "activerecord", "~> 4.2.10"
|
8
|
+
|
9
|
+
group :sqlite do
|
10
|
+
gem "sqlite3", platform: :ruby
|
11
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24", platform: :jruby
|
12
|
+
end
|
13
|
+
|
14
|
+
group :mysql do
|
15
|
+
gem "mysql2", "~> 0.4.10", platform: :ruby
|
16
|
+
gem "activerecord-jdbcmysql-adapter", "~> 1.3.24", platform: :jruby
|
17
|
+
end
|
18
|
+
|
19
|
+
group :postgresql do
|
20
|
+
gem "pg", "~> 0.18.0", platform: :ruby
|
21
|
+
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.24", platform: :jruby
|
22
|
+
end
|
23
|
+
|
24
|
+
gemspec path: "../"
|
data/lib/ranked-model.rb
CHANGED
@@ -3,10 +3,10 @@ require File.dirname(__FILE__)+'/ranked-model/railtie' if defined?(Rails::Railti
|
|
3
3
|
|
4
4
|
module RankedModel
|
5
5
|
|
6
|
-
# Signed
|
6
|
+
# Signed INT in MySQL
|
7
7
|
#
|
8
|
-
MAX_RANK_VALUE =
|
9
|
-
MIN_RANK_VALUE = -
|
8
|
+
MAX_RANK_VALUE = 2147483647
|
9
|
+
MIN_RANK_VALUE = -2147483648
|
10
10
|
|
11
11
|
def self.included base
|
12
12
|
|
data/lib/ranked-model/ranker.rb
CHANGED
@@ -40,11 +40,11 @@ module RankedModel
|
|
40
40
|
when Symbol
|
41
41
|
!instance.respond_to?(ranker.with_same)
|
42
42
|
when Array
|
43
|
-
ranker.with_same.detect {|attr| !instance.respond_to?(attr) }
|
43
|
+
array_element = ranker.with_same.detect {|attr| !instance.respond_to?(attr) }
|
44
44
|
else
|
45
45
|
false
|
46
46
|
end)
|
47
|
-
raise RankedModel::InvalidField, %Q{No field called "#{ranker.with_same}" found in model}
|
47
|
+
raise RankedModel::InvalidField, %Q{No field called "#{array_element || ranker.with_same}" found in model}
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -215,7 +215,8 @@ module RankedModel
|
|
215
215
|
end
|
216
216
|
|
217
217
|
def finder(order = :asc)
|
218
|
-
@finder ||=
|
218
|
+
@finder ||= {}
|
219
|
+
@finder[order] ||= begin
|
219
220
|
_finder = instance_class
|
220
221
|
columns = [instance_class.arel_table[instance_class.primary_key], instance_class.arel_table[ranker.column]]
|
221
222
|
if ranker.scope
|
data/lib/ranked-model/version.rb
CHANGED
data/ranked-model.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_development_dependency "mocha", "~> 0.14.0"
|
21
21
|
s.add_development_dependency "database_cleaner", "~> 1.2.0"
|
22
22
|
s.add_development_dependency "rake", "~> 10.1.0"
|
23
|
+
s.add_development_dependency "appraisal"
|
23
24
|
|
24
25
|
s.files = `git ls-files`.split("\n")
|
25
26
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -603,6 +603,35 @@ describe Duck do
|
|
603
603
|
|
604
604
|
end
|
605
605
|
|
606
|
+
context "from position without gaps with rebalance" do
|
607
|
+
|
608
|
+
before {
|
609
|
+
[:quacky, :feathers, :wingy, :webby, :waddly, :beaky].each_with_index do |name, i|
|
610
|
+
Duck.where(id: @ducks[name].id).update_all(row: i)
|
611
|
+
@ducks[name].reload
|
612
|
+
end
|
613
|
+
@ducks[:wingy].update_attribute :row_position, :up
|
614
|
+
}
|
615
|
+
|
616
|
+
context {
|
617
|
+
|
618
|
+
subject { Duck.ranker(:row).with(Duck.new).current_at_position(1).instance }
|
619
|
+
|
620
|
+
its(:id) { should == @ducks[:wingy].id }
|
621
|
+
|
622
|
+
}
|
623
|
+
|
624
|
+
context {
|
625
|
+
|
626
|
+
subject { Duck.ranker(:row).with(Duck.new).current_at_position(2).instance }
|
627
|
+
|
628
|
+
its(:id) { should == @ducks[:feathers].id }
|
629
|
+
|
630
|
+
}
|
631
|
+
|
632
|
+
end
|
633
|
+
|
634
|
+
|
606
635
|
end
|
607
636
|
|
608
637
|
describe "up with string" do
|
@@ -93,8 +93,8 @@ describe Duck do
|
|
93
93
|
Duck.first(50).each_with_index do |d, index|
|
94
94
|
d.update_attributes :age => index % 10, :pond => "Pond #{index / 10}"
|
95
95
|
end
|
96
|
-
@duck_11 = Duck.
|
97
|
-
@duck_12 = Duck.
|
96
|
+
@duck_11 = Duck.where(:pond => 'Pond 1').rank(:age).first
|
97
|
+
@duck_12 = Duck.where(:pond => 'Pond 1').rank(:age).second
|
98
98
|
@ordered = Duck.where(:pond => 'Pond 1').rank(:age).where(Duck.arel_table[:id].not_in([@duck_11.id, @duck_12.id])).collect {|d| d.id }
|
99
99
|
@duck_11.update_attribute :age, RankedModel::MAX_RANK_VALUE
|
100
100
|
@duck_12.update_attribute :age, RankedModel::MAX_RANK_VALUE
|
@@ -23,3 +23,14 @@ describe WrongFieldDuck do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
26
|
+
|
27
|
+
describe ReallyWrongFieldDuck do
|
28
|
+
|
29
|
+
it "should raise an error because of a specific unknown field" do
|
30
|
+
|
31
|
+
expect {
|
32
|
+
ReallyWrongFieldDuck.create(:name => 'Quicky', :pond => 'Shin')
|
33
|
+
}.to raise_error(RankedModel::InvalidField, 'No field called "non_existant_field" found in model')
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -3,11 +3,11 @@ require 'logger'
|
|
3
3
|
|
4
4
|
ROOT = File.join(File.dirname(__FILE__), '..')
|
5
5
|
|
6
|
-
DB_CONFIG =
|
6
|
+
DB_CONFIG = ENV["DB"] || "sqlite"
|
7
7
|
|
8
8
|
ActiveRecord::Base.logger = Logger.new('tmp/ar_debug.log')
|
9
9
|
ActiveRecord::Base.configurations = YAML::load(IO.read('spec/support/database.yml'))
|
10
|
-
ActiveRecord::Base.establish_connection(DB_CONFIG)
|
10
|
+
ActiveRecord::Base.establish_connection(DB_CONFIG.to_sym)
|
11
11
|
|
12
12
|
ActiveRecord::Schema.define :version => 0 do
|
13
13
|
create_table :ducks, :force => true do |t|
|
@@ -85,7 +85,12 @@ class WrongFieldDuck < ActiveRecord::Base
|
|
85
85
|
|
86
86
|
include RankedModel
|
87
87
|
ranks :age, :with_same => :non_existant_field
|
88
|
+
end
|
88
89
|
|
90
|
+
class ReallyWrongFieldDuck < ActiveRecord::Base
|
91
|
+
self.table_name = :wrong_field_ducks
|
92
|
+
include RankedModel
|
93
|
+
ranks :age, :with_same => [:name, :non_existant_field]
|
89
94
|
end
|
90
95
|
|
91
96
|
# Example for STI, ranking within each child class
|
data/spec/support/database.yml
CHANGED
@@ -1,30 +1,22 @@
|
|
1
|
-
|
1
|
+
sqlite:
|
2
2
|
adapter: sqlite3
|
3
3
|
database: tmp/data.sqlite3
|
4
4
|
pool: 5
|
5
5
|
timeout: 5000
|
6
6
|
|
7
|
-
|
8
|
-
adapter:
|
7
|
+
mysql:
|
8
|
+
adapter: mysql2
|
9
9
|
database: ranked_model_test
|
10
10
|
pool: 5
|
11
11
|
timeout: 5000
|
12
|
+
username: root
|
13
|
+
password:
|
12
14
|
|
13
|
-
|
14
|
-
adapter: postgresql
|
15
|
-
database: ranked_model_test
|
16
|
-
pool: 5
|
17
|
-
timeout: 5000
|
18
|
-
|
19
|
-
test_mysql_travis:
|
20
|
-
adapter: mysql
|
21
|
-
database: ranked_model_test
|
22
|
-
pool: 5
|
23
|
-
timeout: 5000
|
24
|
-
username: travis
|
25
|
-
|
26
|
-
test_postgresql_travis:
|
15
|
+
postgresql:
|
27
16
|
adapter: postgresql
|
28
17
|
database: ranked_model_test
|
29
18
|
pool: 5
|
30
19
|
timeout: 5000
|
20
|
+
username: postgres
|
21
|
+
password:
|
22
|
+
min_messages: ERROR
|
metadata
CHANGED
@@ -1,113 +1,127 @@
|
|
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.1
|
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: 2018-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.1.12
|
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
26
|
version: 3.1.12
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 2.13.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.13.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sqlite3
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 1.3.7
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.3.7
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: genspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.2.8
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.2.8
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mocha
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.14.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.14.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: database_cleaner
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 1.2.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 1.2.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 10.1.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - ~>
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 10.1.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: appraisal
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: ranked-model is a modern row sorting library built for Rails 3 & 4. It
|
112
126
|
uses ARel aggressively and is better optimized than most other libraries.
|
113
127
|
email:
|
@@ -116,13 +130,17 @@ executables: []
|
|
116
130
|
extensions: []
|
117
131
|
extra_rdoc_files: []
|
118
132
|
files:
|
119
|
-
- .gitignore
|
120
|
-
- .rspec
|
121
|
-
- .travis.yml
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Appraisals
|
122
137
|
- Gemfile
|
123
138
|
- LICENSE
|
124
139
|
- Rakefile
|
125
140
|
- Readme.mkd
|
141
|
+
- gemfiles/rails_3_2.gemfile
|
142
|
+
- gemfiles/rails_4_1.gemfile
|
143
|
+
- gemfiles/rails_4_2.gemfile
|
126
144
|
- lib/ranked-model.rb
|
127
145
|
- lib/ranked-model/railtie.rb
|
128
146
|
- lib/ranked-model/ranker.rb
|
@@ -152,17 +170,17 @@ require_paths:
|
|
152
170
|
- lib
|
153
171
|
required_ruby_version: !ruby/object:Gem::Requirement
|
154
172
|
requirements:
|
155
|
-
- -
|
173
|
+
- - ">="
|
156
174
|
- !ruby/object:Gem::Version
|
157
175
|
version: '0'
|
158
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
177
|
requirements:
|
160
|
-
- -
|
178
|
+
- - ">="
|
161
179
|
- !ruby/object:Gem::Version
|
162
180
|
version: '0'
|
163
181
|
requirements: []
|
164
182
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.6.14
|
166
184
|
signing_key:
|
167
185
|
specification_version: 4
|
168
186
|
summary: An acts_as_sortable replacement built for Rails 3 & 4
|