ranked-model 0.4.4 → 0.4.8

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.
@@ -1,3 +1,3 @@
1
1
  module RankedModel
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.8"
3
3
  end
data/lib/ranked-model.rb CHANGED
@@ -69,7 +69,7 @@ module RankedModel
69
69
  end
70
70
 
71
71
  def column_default ranker
72
- column_defaults[ranker.name.to_s] if ActiveRecord::Base.connected?
72
+ column_defaults[ranker.name.to_s] if ActiveRecord::Base.connected? && table_exists?
73
73
  end
74
74
 
75
75
  end
data/ranked-model.gemspec CHANGED
@@ -9,16 +9,16 @@ 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 3 & 4}
13
- s.description = %q{ranked-model is a modern row sorting library built for Rails 3 & 4. It uses ARel aggressively and is better optimized than most other libraries.}
12
+ s.summary = %q{An acts_as_sortable replacement built for Rails 4.2+}
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.add_dependency "activerecord", ">= 4.1.16"
16
+ s.add_dependency "activerecord", ">= 4.2"
17
17
  s.add_development_dependency "rspec", "~> 3"
18
18
  s.add_development_dependency "rspec-its"
19
19
  s.add_development_dependency "mocha"
20
20
  s.add_development_dependency "database_cleaner", "~> 1.7.0"
21
- s.add_development_dependency "rake", "~> 10.1.0"
21
+ s.add_development_dependency "rake", ">= 12.3.3"
22
22
  s.add_development_dependency "appraisal"
23
23
  s.add_development_dependency "pry"
24
24
 
@@ -22,7 +22,7 @@ describe 'ColumnDefaultDuck' do
22
22
  end
23
23
  }.not_to raise_error
24
24
  ensure
25
- ActiveRecord::Base.establish_connection(DB_CONFIG.to_sym)
25
+ ActiveRecord::Base.establish_connection(ENV['DB'].to_sym)
26
26
  end
27
27
  end
28
28
 
@@ -48,9 +48,9 @@ describe Duck do
48
48
  }
49
49
  @ducks.each { |name, duck|
50
50
  duck.reload
51
- duck.update_attribute :row_position, 0
52
- duck.update_attribute :size_position, 0
53
- duck.update_attribute :age_position, 0
51
+ duck.update :row_position => 0
52
+ duck.update :size_position => 0
53
+ duck.update :age_position => 0
54
54
  duck.save!
55
55
  }
56
56
  @ducks.each {|name, duck| duck.reload }
@@ -59,8 +59,8 @@ describe Duck do
59
59
  describe "sorting by size on in_shin_pond" do
60
60
 
61
61
  before {
62
- @ducks[:quacky].update_attribute :size_position, 0
63
- @ducks[:wingy].update_attribute :size_position, 2
62
+ @ducks[:quacky].update :size_position => 0
63
+ @ducks[:wingy].update :size_position => 2
64
64
  }
65
65
 
66
66
  subject { Duck.in_shin_pond.rank(:size).to_a }
@@ -76,8 +76,8 @@ describe Duck do
76
76
  describe "sorting by age on Shin pond" do
77
77
 
78
78
  before {
79
- @ducks[:feathers].update_attribute :age_position, 0
80
- @ducks[:wingy].update_attribute :age_position, 0
79
+ @ducks[:feathers].update :age_position => 0
80
+ @ducks[:wingy].update :age_position => 0
81
81
  }
82
82
 
83
83
  subject { Duck.where(:pond => 'Shin').rank(:age).to_a }
@@ -93,10 +93,10 @@ describe Duck do
93
93
  describe "sorting by row" do
94
94
 
95
95
  before {
96
- @ducks[:beaky].update_attribute :row_position, 0
97
- @ducks[:webby].update_attribute :row_position, 2
98
- @ducks[:waddly].update_attribute :row_position, 2
99
- @ducks[:wingy].update_attribute :row_position, 6
96
+ @ducks[:beaky].update :row_position => 0
97
+ @ducks[:webby].update :row_position => 2
98
+ @ducks[:waddly].update :row_position => 2
99
+ @ducks[:wingy].update :row_position => 6
100
100
  }
101
101
 
102
102
  subject { Duck.rank(:row).to_a }
@@ -112,13 +112,13 @@ describe Duck do
112
112
  describe "mixed sorting by" do
113
113
 
114
114
  before {
115
- @ducks[:quacky].update_attribute :size_position, 0
116
- @ducks[:beaky].update_attribute :row_position, 0
117
- @ducks[:webby].update_attribute :row_position, 2
118
- @ducks[:wingy].update_attribute :size_position, 1
119
- @ducks[:waddly].update_attribute :row_position, 2
120
- @ducks[:wingy].update_attribute :row_position, 6
121
- @ducks[:webby].update_attribute :row_position, 6
115
+ @ducks[:quacky].update :size_position => 0
116
+ @ducks[:beaky].update :row_position => 0
117
+ @ducks[:webby].update :row_position => 2
118
+ @ducks[:wingy].update :size_position => 1
119
+ @ducks[:waddly].update :row_position => 2
120
+ @ducks[:wingy].update :row_position => 6
121
+ @ducks[:webby].update :row_position => 6
122
122
  }
123
123
 
124
124
  describe "row" do
@@ -153,7 +153,7 @@ describe Duck do
153
153
  # puts Duck.rank(:age).collect {|duck| "#{duck.name} #{duck.age}" }
154
154
  duck = Duck.rank(:age)[2]
155
155
  expect(->{
156
- duck.update_attribute :name, 'New Name'
156
+ duck.update :name => 'New Name'
157
157
  }).to_not change(duck.reload, :age)
158
158
  # puts Duck.rank(:age).collect {|duck| "#{duck.name} #{duck.age}" }
159
159
  end
@@ -187,7 +187,7 @@ describe Duck do
187
187
 
188
188
  before {
189
189
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:wingy].id).collect {|duck| duck.id }
190
- @ducks[:wingy].update_attribute :row_position, 2
190
+ @ducks[:wingy].update :row_position => 2
191
191
  }
192
192
 
193
193
  context {
@@ -214,7 +214,7 @@ describe Duck do
214
214
 
215
215
  before {
216
216
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:wingy].id).collect {|duck| duck.id }
217
- @ducks[:wingy].update_attribute :row_position, 0
217
+ @ducks[:wingy].update :row_position => 0
218
218
  }
219
219
 
220
220
  context {
@@ -254,7 +254,7 @@ describe Duck do
254
254
 
255
255
  context {
256
256
 
257
- before { @ducks[:wingy].update_attribute :row_position, (@ducks.size - 2) }
257
+ before { @ducks[:wingy].update :row_position => (@ducks.size - 2) }
258
258
 
259
259
  subject { Duck.ranker(:row).with(Duck.new).current_at_position(@ducks.size - 2).instance }
260
260
 
@@ -264,7 +264,7 @@ describe Duck do
264
264
 
265
265
  context {
266
266
 
267
- before { @ducks[:wingy].update_attribute :row_position, :down }
267
+ before { @ducks[:wingy].update :row_position => :down }
268
268
 
269
269
  subject { Duck.ranker(:row).with(Duck.new).current_at_position(@ducks.size - 2).instance }
270
270
 
@@ -278,7 +278,7 @@ describe Duck do
278
278
 
279
279
  before {
280
280
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:wingy].id).collect {|duck| duck.id }
281
- @ducks[:wingy].update_attribute :row_position, (@ducks.size - 1)
281
+ @ducks[:wingy].update :row_position => (@ducks.size - 1)
282
282
  }
283
283
 
284
284
  context {
@@ -319,7 +319,7 @@ describe Duck do
319
319
 
320
320
  before {
321
321
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:wingy].id).collect {|duck| duck.id }
322
- @ducks[:wingy].update_attribute :row_position, :last
322
+ @ducks[:wingy].update :row_position => :last
323
323
  }
324
324
 
325
325
  context {
@@ -360,7 +360,7 @@ describe Duck do
360
360
 
361
361
  before {
362
362
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:wingy].id).collect {|duck| duck.id }
363
- @ducks[:wingy].update_attribute :row_position, 'last'
363
+ @ducks[:wingy].update :row_position => 'last'
364
364
  }
365
365
 
366
366
  context {
@@ -403,7 +403,7 @@ describe Duck do
403
403
 
404
404
  before {
405
405
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:wingy].id).collect { |duck| duck.id }
406
- @ducks[:wingy].update_attribute :row_position, :down
406
+ @ducks[:wingy].update :row_position => :down
407
407
  }
408
408
 
409
409
  context {
@@ -430,7 +430,7 @@ describe Duck do
430
430
 
431
431
  before {
432
432
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:quacky].id).collect { |duck| duck.id }
433
- @ducks[:quacky].update_attribute :row_position, :down
433
+ @ducks[:quacky].update :row_position => :down
434
434
  }
435
435
 
436
436
  context {
@@ -455,7 +455,7 @@ describe Duck do
455
455
 
456
456
  before {
457
457
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:feathers].id).collect { |duck| duck.id }
458
- @ducks[:feathers].update_attribute :row_position, :down
458
+ @ducks[:feathers].update :row_position => :down
459
459
  }
460
460
 
461
461
  context {
@@ -484,7 +484,7 @@ describe Duck do
484
484
 
485
485
  before {
486
486
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:wingy].id).collect { |duck| duck.id }
487
- @ducks[:wingy].update_attribute :row_position, 'down'
487
+ @ducks[:wingy].update :row_position => 'down'
488
488
  }
489
489
 
490
490
  context {
@@ -511,7 +511,7 @@ describe Duck do
511
511
 
512
512
  before {
513
513
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:quacky].id).collect { |duck| duck.id }
514
- @ducks[:quacky].update_attribute :row_position, 'down'
514
+ @ducks[:quacky].update :row_position => 'down'
515
515
  }
516
516
 
517
517
  context {
@@ -536,7 +536,7 @@ describe Duck do
536
536
 
537
537
  before {
538
538
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:feathers].id).collect { |duck| duck.id }
539
- @ducks[:feathers].update_attribute :row_position, 'down'
539
+ @ducks[:feathers].update :row_position => 'down'
540
540
  }
541
541
 
542
542
  context {
@@ -565,7 +565,7 @@ describe Duck do
565
565
 
566
566
  before {
567
567
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:wingy].id).collect { |duck| duck.id }
568
- @ducks[:wingy].update_attribute :row_position, :up
568
+ @ducks[:wingy].update :row_position => :up
569
569
  }
570
570
 
571
571
  context {
@@ -592,7 +592,7 @@ describe Duck do
592
592
 
593
593
  before {
594
594
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:beaky].id).collect { |duck| duck.id }
595
- @ducks[:beaky].update_attribute :row_position, :up
595
+ @ducks[:beaky].update :row_position => :up
596
596
  }
597
597
 
598
598
  context {
@@ -617,7 +617,7 @@ describe Duck do
617
617
 
618
618
  before {
619
619
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:waddly].id).collect { |duck| duck.id }
620
- @ducks[:waddly].update_attribute :row_position, :up
620
+ @ducks[:waddly].update :row_position => :up
621
621
  }
622
622
 
623
623
  context {
@@ -645,7 +645,7 @@ describe Duck do
645
645
  Duck.where(id: @ducks[name].id).update_all(row: i)
646
646
  @ducks[name].reload
647
647
  end
648
- @ducks[:wingy].update_attribute :row_position, :up
648
+ @ducks[:wingy].update :row_position => :up
649
649
  }
650
650
 
651
651
  context {
@@ -675,7 +675,7 @@ describe Duck do
675
675
 
676
676
  before {
677
677
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:wingy].id).collect { |duck| duck.id }
678
- @ducks[:wingy].update_attribute :row_position, 'up'
678
+ @ducks[:wingy].update :row_position => 'up'
679
679
  }
680
680
 
681
681
  context {
@@ -702,7 +702,7 @@ describe Duck do
702
702
 
703
703
  before {
704
704
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:beaky].id).collect { |duck| duck.id }
705
- @ducks[:beaky].update_attribute :row_position, 'up'
705
+ @ducks[:beaky].update :row_position => 'up'
706
706
  }
707
707
 
708
708
  context {
@@ -727,7 +727,7 @@ describe Duck do
727
727
 
728
728
  before {
729
729
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_eq @ducks[:waddly].id).collect { |duck| duck.id }
730
- @ducks[:waddly].update_attribute :row_position, 'up'
730
+ @ducks[:waddly].update :row_position => 'up'
731
731
  }
732
732
 
733
733
  context {
@@ -779,6 +779,44 @@ describe Duck do
779
779
  }
780
780
  end
781
781
 
782
+ describe "when moving between ponds should work when rebalancing" do
783
+ before do
784
+ [:feathers, :wingy, :webby, :waddly, :beaky].each_with_index do |name, i|
785
+ Duck.where(id: @ducks[name].id)
786
+ .update_all(age: RankedModel::MIN_RANK_VALUE + i, pond: "Boyden")
787
+ end
788
+
789
+ @ducks[:quacky].update!(age_position: 2, pond: "Boyden")
790
+ end
791
+
792
+ it 'rebalances ranks correctly' do
793
+ expect(@ducks[:feathers].reload.age_rank).to eq 0
794
+ expect(@ducks[:quacky].reload.age_rank).to eq 2
795
+ expect(@ducks[:beaky].reload.age_rank).to eq 5
796
+ end
797
+
798
+ context 'when attempting to update position to a non-unique value' do
799
+ before do
800
+ @duck_one = Duck.create(landing_order: RankedModel::MIN_RANK_VALUE,
801
+ lake_id: 42, flock_id: 42)
802
+ # Duck one's landing order will be rebalanced to -715_827_883.
803
+ # Given a unique index on [:landing_order, :lake_id, :flock_id] we
804
+ # verify that the operation succeeds despite the value already being
805
+ # occupied by duck two.
806
+ @duck_two = Duck.create(landing_order: -715_827_883,
807
+ lake_id: 42, flock_id: 42)
808
+ end
809
+
810
+ it 'rebalances ranks correctly' do
811
+ @ducks[:quacky].update!(landing_order_position: :first,
812
+ lake_id: 42, flock_id: 42)
813
+ expect(@ducks[:quacky].reload.landing_order_rank).to eq 0
814
+ expect(@duck_one.reload.landing_order_rank).to eq 1
815
+ expect(@duck_two.reload.landing_order_rank).to eq 2
816
+ end
817
+ end
818
+ end
819
+
782
820
  end
783
821
 
784
822
  describe Duck do
@@ -812,7 +850,7 @@ describe Duck do
812
850
  }
813
851
  @ducks.each { |name, duck|
814
852
  duck.reload
815
- duck.update_attribute :landing_order_position, 0
853
+ duck.update :landing_order_position => 0
816
854
  duck.save!
817
855
  }
818
856
  @ducks.each {|name, duck| duck.reload }
@@ -821,8 +859,8 @@ describe Duck do
821
859
  describe "sorting by landing_order" do
822
860
 
823
861
  before {
824
- @ducks[:quacky].update_attribute :landing_order_position, 0
825
- @ducks[:wingy].update_attribute :landing_order_position, 1
862
+ @ducks[:quacky].update :landing_order_position => 0
863
+ @ducks[:wingy].update :landing_order_position => 1
826
864
  }
827
865
 
828
866
  subject { Duck.in_lake_and_flock(0,0).rank(:landing_order).to_a }
@@ -846,10 +884,10 @@ describe Duck do
846
884
 
847
885
  @previous_ranks = @untouchable_ranks.call
848
886
 
849
- @ducks[:quacky].update_attribute :landing_order_position, 0
850
- @ducks[:wingy].update_attribute :landing_order_position, 1
851
- @ducks[:feathers].update_attribute :landing_order_position, 0
852
- @ducks[:wingy].update_attribute :landing_order_position, 1
887
+ @ducks[:quacky].update :landing_order_position => 0
888
+ @ducks[:wingy].update :landing_order_position => 1
889
+ @ducks[:feathers].update :landing_order_position => 0
890
+ @ducks[:wingy].update :landing_order_position => 1
853
891
  }
854
892
 
855
893
  subject { @untouchable_ranks.call }
@@ -5,7 +5,7 @@ describe Duck do
5
5
  before {
6
6
  200.times do |i|
7
7
  Duck.create \
8
- :name => "Duck #{i}"
8
+ :name => "Duck #{i + 1}"
9
9
  end
10
10
  }
11
11
 
@@ -29,7 +29,7 @@ describe Duck do
29
29
 
30
30
  before {
31
31
  @last = Duck.last
32
- @last.update_attribute :row_position, 137
32
+ @last.update :row_position => 137
33
33
  }
34
34
 
35
35
  subject { Duck.ranker(:row).with(Duck.new).current_at_position(137).instance }
@@ -42,7 +42,7 @@ describe Duck do
42
42
 
43
43
  before {
44
44
  @last = Duck.last
45
- @last.update_attribute :row_position, 2
45
+ @last.update :row_position => 2
46
46
  }
47
47
 
48
48
  subject { Duck.ranker(:row).with(Duck.new).current_at_position(2).instance }
@@ -55,7 +55,7 @@ describe Duck do
55
55
 
56
56
  before {
57
57
  @last = Duck.last
58
- @last.update_attribute :row_position, :last
58
+ @last.update :row_position => :last
59
59
  }
60
60
 
61
61
  subject { Duck.rank(:row).last }
@@ -68,7 +68,7 @@ describe Duck do
68
68
 
69
69
  before {
70
70
  @last = Duck.last
71
- @last.update_attribute :row_position, :first
71
+ @last.update :row_position => :first
72
72
  }
73
73
 
74
74
  subject { Duck.rank(:row).first }
@@ -87,8 +87,8 @@ describe Duck do
87
87
  @first = Duck.first
88
88
  @second = Duck.offset(1).first
89
89
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_in([@first.id, @second.id])).collect {|d| d.id }
90
- @first.update_attribute :row, RankedModel::MAX_RANK_VALUE
91
- @second.update_attribute :row, RankedModel::MAX_RANK_VALUE
90
+ @first.update :row => RankedModel::MAX_RANK_VALUE
91
+ @second.update :row => RankedModel::MAX_RANK_VALUE
92
92
  }
93
93
 
94
94
  context {
@@ -105,13 +105,13 @@ describe Duck do
105
105
 
106
106
  before {
107
107
  Duck.first(50).each_with_index do |d, index|
108
- d.update_attributes :age => index % 10, :pond => "Pond #{index / 10}"
108
+ d.update :age => index % 10, :pond => "Pond #{index / 10}"
109
109
  end
110
110
  @duck_11 = Duck.where(:pond => 'Pond 1').rank(:age).first
111
111
  @duck_12 = Duck.where(:pond => 'Pond 1').rank(:age).second
112
112
  @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 }
113
- @duck_11.update_attribute :age, RankedModel::MAX_RANK_VALUE
114
- @duck_12.update_attribute :age, RankedModel::MAX_RANK_VALUE
113
+ @duck_11.update :age => RankedModel::MAX_RANK_VALUE
114
+ @duck_12.update :age => RankedModel::MAX_RANK_VALUE
115
115
  }
116
116
 
117
117
  context {
@@ -133,8 +133,8 @@ describe Duck do
133
133
  @first = Duck.first
134
134
  @second = Duck.offset(1).first
135
135
  @ordered = Duck.rank(:row).where(Duck.arel_table[:id].not_in([@first.id, @second.id])).collect {|d| d.id }
136
- @first.update_attribute :row, RankedModel::MIN_RANK_VALUE
137
- @second.update_attribute :row, RankedModel::MIN_RANK_VALUE
136
+ @first.update :row => RankedModel::MIN_RANK_VALUE
137
+ @second.update :row => RankedModel::MIN_RANK_VALUE
138
138
  }
139
139
 
140
140
  context {
@@ -149,34 +149,30 @@ describe Duck do
149
149
 
150
150
  describe "with no more gaps" do
151
151
 
152
- before {
152
+ before do
153
153
  @first = Duck.rank(:row).first
154
154
  @second = Duck.rank(:row).offset(1).first
155
155
  @third = Duck.rank(:row).offset(2).first
156
- @fourth = Duck.rank(:row).offset(4).first
157
- @fifth = Duck.rank(:row).offset(5).first
156
+ @fourth = Duck.rank(:row).offset(3).first
158
157
  @lower = Duck.rank(:row).
159
- where(Duck.arel_table[:id].not_in([@first.id, @second.id, @third.id, @fourth.id, @fifth.id])).
158
+ where(Duck.arel_table[:id].not_in([@first.id, @second.id, @third.id, @fourth.id])).
160
159
  where(Duck.arel_table[:row].lt(RankedModel::MAX_RANK_VALUE / 2)).
161
- collect {|d| d.id }
160
+ pluck(:id)
162
161
  @upper = Duck.rank(:row).
163
- where(Duck.arel_table[:id].not_in([@first.id, @second.id, @third.id, @fourth.id, @fifth.id])).
162
+ where(Duck.arel_table[:id].not_in([@first.id, @second.id, @third.id, @fourth.id])).
164
163
  where(Duck.arel_table[:row].gteq(RankedModel::MAX_RANK_VALUE / 2)).
165
- collect {|d| d.id }
166
- @first.update_attribute :row, RankedModel::MIN_RANK_VALUE
167
- @second.update_attribute :row, RankedModel::MAX_RANK_VALUE
168
- @third.update_attribute :row, (RankedModel::MAX_RANK_VALUE / 2)
169
- Duck.where(id: @fifth.id).update_all row: @third.row
170
- @fourth.update_attribute :row, @third.row
171
- }
172
-
173
- context {
174
-
175
- subject { Duck.rank(:row).collect {|d| d.id } }
176
-
177
- it { is_expected.to eq([@first.id] + @lower + [@fourth.id, @third.id, @fifth.id] + @upper + [@second.id]) }
178
-
179
- }
164
+ pluck(:id)
165
+ @first.update(row: RankedModel::MIN_RANK_VALUE)
166
+ @second.update(row: RankedModel::MAX_RANK_VALUE)
167
+ @third.update(row: (RankedModel::MAX_RANK_VALUE / 2))
168
+ @fourth.update(row: @third.row)
169
+ end
170
+
171
+ it 'works correctly' do
172
+ result = Duck.rank(:row).pluck(:id)
173
+ expected = [@first.id, *@lower, @fourth.id, @third.id, *@upper, @second.id]
174
+ expect(result).to eq(expected)
175
+ end
180
176
 
181
177
  end
182
178
 
@@ -10,7 +10,7 @@ describe Ego do
10
10
  }
11
11
  @egos.each { |name, ego|
12
12
  ego.reload
13
- ego.update_attribute :size_position, 0
13
+ ego.update :size_position => 0
14
14
  ego.save!
15
15
  }
16
16
  @egos.each {|name, ego| ego.reload }
@@ -19,8 +19,8 @@ describe Ego do
19
19
  describe "sorting on size alternative primary key" do
20
20
 
21
21
  before {
22
- @egos[:nick].update_attribute :size_position, 0
23
- @egos[:sally].update_attribute :size_position, 2
22
+ @egos[:nick].update :size_position => 0
23
+ @egos[:sally].update :size_position => 2
24
24
  }
25
25
 
26
26
  subject { Ego.rank(:size).to_a }
@@ -14,8 +14,8 @@ describe Number do
14
14
  @first = Number.first
15
15
  @second = Number.offset(1).first
16
16
  @ordered = Number.rank(:order).where(Number.arel_table[:id].not_in([@first.id, @second.id])).collect {|d| d.id }
17
- @first.update_attribute :order, RankedModel::MAX_RANK_VALUE
18
- @second.update_attribute :order, RankedModel::MAX_RANK_VALUE
17
+ @first.update :order => RankedModel::MAX_RANK_VALUE
18
+ @second.update :order => RankedModel::MAX_RANK_VALUE
19
19
  }
20
20
 
21
21
  context {
@@ -28,4 +28,12 @@ describe Number do
28
28
 
29
29
  end
30
30
 
31
+ describe "getting a position with keyword column name" do
32
+
33
+ subject { Number.first }
34
+
35
+ its(:order_rank) { should == 0 }
36
+
37
+ end
38
+
31
39
  end
@@ -16,7 +16,7 @@ describe Player do
16
16
 
17
17
  describe "setting the position of a record that already exists" do
18
18
  it "sets the rank without error" do
19
- expect{@players[:bob].update_attributes! :score_position => 1}.to_not raise_error
19
+ expect{@players[:bob].update! :score_position => 1}.to_not raise_error
20
20
  end
21
21
  end
22
22
  end
@@ -62,3 +62,21 @@ describe RankedModel::Ranker, 'unless as Proc' do
62
62
  }
63
63
  end
64
64
  end
65
+
66
+ describe RankedModel::Ranker, 'unless as lambda' do
67
+ context 'returns true' do
68
+ subject { RankedModel::Ranker.new(:overview, unless: ->(_) { true }).with(Class.new) }
69
+ its(:handle_ranking) { should == nil }
70
+ end
71
+
72
+ context 'returns false' do
73
+ subject { RankedModel::Ranker.new(:overview, unless: ->(_) { false }).with(Class.new) }
74
+
75
+ it {
76
+ subject.expects(:update_index_from_position).once
77
+ subject.expects(:assure_unique_position).once
78
+
79
+ subject.handle_ranking
80
+ }
81
+ end
82
+ end
@@ -12,7 +12,7 @@ describe Element do
12
12
  }
13
13
  @elements.each { |name, element|
14
14
  element.reload
15
- element.update_attribute :combination_order_position, 0
15
+ element.update :combination_order_position => 0
16
16
  }
17
17
  @elements.each {|name, element| element.reload }
18
18
  }
@@ -20,9 +20,9 @@ describe Element do
20
20
  describe "rebalancing on an STI class should not affect the other class" do
21
21
 
22
22
  before {
23
- @elements[:helium].update_attribute :combination_order_position, :first
24
- @elements[:xenon].update_attribute :combination_order_position, :first
25
- @elements[:argon].update_attribute :combination_order_position, :last
23
+ @elements[:helium].update :combination_order_position => :first
24
+ @elements[:xenon].update :combination_order_position => :first
25
+ @elements[:argon].update :combination_order_position => :last
26
26
 
27
27
  TransitionMetal.ranker(:combination_order).with(@elements[:chromium]).instance_eval { rebalance_ranks }
28
28
  }
@@ -40,16 +40,16 @@ describe Element do
40
40
  describe "setting positions on STI classes" do
41
41
 
42
42
  before {
43
- @elements[:helium].update_attribute :combination_order_position, :first
44
- @elements[:xenon].update_attribute :combination_order_position, :first
45
- @elements[:argon].update_attribute :combination_order_position, :first
46
-
47
- @elements[:chromium].update_attribute :combination_order_position, 1
48
- @elements[:manganese].update_attribute :combination_order_position, 1
49
- @elements[:manganese].update_attribute :combination_order_position, 0
50
- @elements[:chromium].update_attribute :combination_order_position, 0
51
- @elements[:manganese].update_attribute :combination_order_position, 0
52
- @elements[:chromium].update_attribute :combination_order_position, 0
43
+ @elements[:helium].update :combination_order_position => :first
44
+ @elements[:xenon].update :combination_order_position => :first
45
+ @elements[:argon].update :combination_order_position => :first
46
+
47
+ @elements[:chromium].update :combination_order_position => 1
48
+ @elements[:manganese].update :combination_order_position => 1
49
+ @elements[:manganese].update :combination_order_position => 0
50
+ @elements[:chromium].update :combination_order_position => 0
51
+ @elements[:manganese].update :combination_order_position => 0
52
+ @elements[:chromium].update :combination_order_position => 0
53
53
  }
54
54
 
55
55
  describe "NobleGas" do
@@ -81,16 +81,16 @@ describe Element do
81
81
  describe "setting positions on STI classes" do
82
82
 
83
83
  before {
84
- @elements[:helium].update_attribute :combination_order_position, :first
85
- @elements[:xenon].update_attribute :combination_order_position, :first
86
- @elements[:argon].update_attribute :combination_order_position, :first
87
-
88
- @elements[:chromium].update_attribute :combination_order_position, 1
89
- @elements[:manganese].update_attribute :combination_order_position, 1
90
- @elements[:manganese].update_attribute :combination_order_position, 0
91
- @elements[:chromium].update_attribute :combination_order_position, 0
92
- @elements[:manganese].update_attribute :combination_order_position, 0
93
- @elements[:chromium].update_attribute :combination_order_position, 0
84
+ @elements[:helium].update :combination_order_position => :first
85
+ @elements[:xenon].update :combination_order_position => :first
86
+ @elements[:argon].update :combination_order_position => :first
87
+
88
+ @elements[:chromium].update :combination_order_position => 1
89
+ @elements[:manganese].update :combination_order_position => 1
90
+ @elements[:manganese].update :combination_order_position => 0
91
+ @elements[:chromium].update :combination_order_position => 0
92
+ @elements[:manganese].update :combination_order_position => 0
93
+ @elements[:chromium].update :combination_order_position => 0
94
94
  }
95
95
 
96
96
  describe "NobleGas" do