ranked-model 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +1 -0
- data/Gemfile +1 -1
- data/lib/ranked-model/ranker.rb +5 -5
- data/lib/ranked-model/version.rb +1 -1
- data/ranked-model.gemspec +1 -1
- data/spec/duck-model/duck_spec.rb +13 -0
- data/spec/ego-model/ego_spec.rb +36 -0
- data/spec/support/active_record.rb +12 -1
- metadata +23 -41
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fa03565f2d58125cad4f32d6e9e9eb71287a7c33
|
4
|
+
data.tar.gz: 7dc3963857902ef6872a26d90a0156869622a1be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21d43557aa038bd4a588dcb5b2742f67661398557a51367f2cd759b37727b2f96bf00cfcc3952d4985a61409a4f1d6ab39b634d35c4dd1bd927bf7f506529018
|
7
|
+
data.tar.gz: 0e6d81072a17f1c6c6abe519a38f2750181685dc174f320c6cb96e3866a78403316b68ecc363258a2e01ada3a2064b366ed38652743cc17249bd62ceaa6c932f
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/lib/ranked-model/ranker.rb
CHANGED
@@ -29,7 +29,7 @@ module RankedModel
|
|
29
29
|
|
30
30
|
validate_ranker_for_instance!
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def validate_ranker_for_instance!
|
34
34
|
if ranker.scope && !instance_class.respond_to?(ranker.scope)
|
35
35
|
raise RankedModel::InvalidScope, %Q{No scope called "#{ranker.scope}" found in model}
|
@@ -64,7 +64,7 @@ module RankedModel
|
|
64
64
|
def update_rank! value
|
65
65
|
# Bypass callbacks
|
66
66
|
#
|
67
|
-
instance_class.where(
|
67
|
+
instance_class.where(instance_class.primary_key => instance.id).update_all ["#{ranker.column} = ?", value]
|
68
68
|
end
|
69
69
|
|
70
70
|
def position
|
@@ -152,7 +152,7 @@ module RankedModel
|
|
152
152
|
_scope = finder
|
153
153
|
unless instance.id.nil?
|
154
154
|
# Never update ourself, shift others around us.
|
155
|
-
_scope = _scope.where( instance_class.arel_table[
|
155
|
+
_scope = _scope.where( instance_class.arel_table[instance_class.primary_key].not_eq(instance.id) )
|
156
156
|
end
|
157
157
|
if current_first.rank && current_first.rank > RankedModel::MIN_RANK_VALUE && rank == RankedModel::MAX_RANK_VALUE
|
158
158
|
_scope.
|
@@ -221,9 +221,9 @@ module RankedModel
|
|
221
221
|
end
|
222
222
|
if !new_record?
|
223
223
|
_finder = _finder.where \
|
224
|
-
instance_class.arel_table[
|
224
|
+
instance_class.arel_table[instance_class.primary_key].not_eq(instance.id)
|
225
225
|
end
|
226
|
-
_finder.order(instance_class.arel_table[ranker.column].asc).select([instance_class.arel_table[
|
226
|
+
_finder.order(instance_class.arel_table[ranker.column].asc).select([instance_class.arel_table[instance_class.primary_key], instance_class.arel_table[ranker.column]])
|
227
227
|
end
|
228
228
|
end
|
229
229
|
|
data/lib/ranked-model/version.rb
CHANGED
data/ranked-model.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.add_dependency "activerecord", ">= 3.0.3"
|
16
16
|
s.add_development_dependency "rspec"
|
17
|
-
s.add_development_dependency "rspec-rails"
|
17
|
+
s.add_development_dependency "rspec-rails", "~> 2.12.0"
|
18
18
|
s.add_development_dependency "sqlite3"
|
19
19
|
s.add_development_dependency "genspec"
|
20
20
|
s.add_development_dependency "mocha"
|
@@ -143,6 +143,19 @@ describe Duck do
|
|
143
143
|
|
144
144
|
end
|
145
145
|
|
146
|
+
describe "changing an unrelated attribute" do
|
147
|
+
|
148
|
+
it "doesn't change ranking" do
|
149
|
+
# puts Duck.rank(:age).collect {|duck| "#{duck.name} #{duck.age}" }
|
150
|
+
duck = Duck.rank(:age)[2]
|
151
|
+
->{
|
152
|
+
duck.update_attribute :name, 'New Name'
|
153
|
+
}.should_not change(duck.reload, :age)
|
154
|
+
# puts Duck.rank(:age).collect {|duck| "#{duck.name} #{duck.age}" }
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
146
159
|
describe "setting and fetching by positioning" do
|
147
160
|
|
148
161
|
describe "in the middle" do
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ego do
|
4
|
+
|
5
|
+
before {
|
6
|
+
@egos = {
|
7
|
+
:bob => Ego.create(:name => 'Bob'),
|
8
|
+
:nick => Ego.create(:name => 'Nick'),
|
9
|
+
:sally => Ego.create(:name => 'Sally')
|
10
|
+
}
|
11
|
+
@egos.each { |name, ego|
|
12
|
+
ego.reload
|
13
|
+
ego.update_attribute :size_position, 0
|
14
|
+
ego.save!
|
15
|
+
}
|
16
|
+
@egos.each {|name, ego| ego.reload }
|
17
|
+
}
|
18
|
+
|
19
|
+
describe "sorting on size alternative primary key" do
|
20
|
+
|
21
|
+
before {
|
22
|
+
@egos[:nick].update_attribute :size_position, 0
|
23
|
+
@egos[:sally].update_attribute :size_position, 2
|
24
|
+
}
|
25
|
+
|
26
|
+
subject { Ego.rank(:size).all }
|
27
|
+
|
28
|
+
its(:size) { should == 3 }
|
29
|
+
|
30
|
+
its(:first) { should == @egos[:nick] }
|
31
|
+
|
32
|
+
its(:last) { should == @egos[:sally] }
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -46,6 +46,11 @@ ActiveRecord::Schema.define :version => 0 do
|
|
46
46
|
t.string :type
|
47
47
|
t.integer :parking_order
|
48
48
|
end
|
49
|
+
|
50
|
+
create_table :egos, :primary_key => :alternative_to_id, :force => true do |t|
|
51
|
+
t.string :name
|
52
|
+
t.integer :size
|
53
|
+
end
|
49
54
|
end
|
50
55
|
|
51
56
|
class Duck < ActiveRecord::Base
|
@@ -119,4 +124,10 @@ class MotorBike < Vehicle
|
|
119
124
|
include RankedModel
|
120
125
|
ranks :parking_order, :class_name => 'Vehicle', :with_same => :color
|
121
126
|
|
122
|
-
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class Ego < ActiveRecord::Base
|
130
|
+
primary_key = :alternative_to_id
|
131
|
+
include RankedModel
|
132
|
+
ranks :size
|
133
|
+
end
|
metadata
CHANGED
@@ -1,110 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ranked-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Matthew Beale
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 3.0.3
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 3.0.3
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec-rails
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
47
|
+
version: 2.12.0
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
54
|
+
version: 2.12.0
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: sqlite3
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: genspec
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: mocha
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
description: ranked-model is a modern row sorting library built for Rails 3. It uses
|
@@ -131,6 +118,7 @@ files:
|
|
131
118
|
- spec/duck-model/duck_spec.rb
|
132
119
|
- spec/duck-model/lots_of_ducks_spec.rb
|
133
120
|
- spec/duck-model/wrong_ducks_spec.rb
|
121
|
+
- spec/ego-model/ego_spec.rb
|
134
122
|
- spec/ranked-model/ranker_spec.rb
|
135
123
|
- spec/ranked-model/version_spec.rb
|
136
124
|
- spec/spec_helper.rb
|
@@ -141,38 +129,32 @@ files:
|
|
141
129
|
- tmp/.gitignore
|
142
130
|
homepage: https://github.com/harvesthq/ranked-model
|
143
131
|
licenses: []
|
132
|
+
metadata: {}
|
144
133
|
post_install_message:
|
145
134
|
rdoc_options: []
|
146
135
|
require_paths:
|
147
136
|
- lib
|
148
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
-
none: false
|
150
138
|
requirements:
|
151
|
-
- -
|
139
|
+
- - '>='
|
152
140
|
- !ruby/object:Gem::Version
|
153
141
|
version: '0'
|
154
|
-
segments:
|
155
|
-
- 0
|
156
|
-
hash: -3607802699364138868
|
157
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
-
none: false
|
159
143
|
requirements:
|
160
|
-
- -
|
144
|
+
- - '>='
|
161
145
|
- !ruby/object:Gem::Version
|
162
146
|
version: '0'
|
163
|
-
segments:
|
164
|
-
- 0
|
165
|
-
hash: -3607802699364138868
|
166
147
|
requirements: []
|
167
148
|
rubyforge_project:
|
168
|
-
rubygems_version:
|
149
|
+
rubygems_version: 2.0.0
|
169
150
|
signing_key:
|
170
|
-
specification_version:
|
151
|
+
specification_version: 4
|
171
152
|
summary: An acts_as_sortable replacement built for Rails 3
|
172
153
|
test_files:
|
173
154
|
- spec/duck-model/duck_spec.rb
|
174
155
|
- spec/duck-model/lots_of_ducks_spec.rb
|
175
156
|
- spec/duck-model/wrong_ducks_spec.rb
|
157
|
+
- spec/ego-model/ego_spec.rb
|
176
158
|
- spec/ranked-model/ranker_spec.rb
|
177
159
|
- spec/ranked-model/version_spec.rb
|
178
160
|
- spec/spec_helper.rb
|