acts_as_list 0.9.19 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,9 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rack", "~> 1", platforms: [:ruby_19, :ruby_20, :ruby_21]
6
5
  gem "rake"
7
6
  gem "appraisal"
8
- gem "activerecord", "~> 5.2.1"
7
+ gem "activerecord", "~> 5.2.0"
9
8
 
10
9
  group :development do
11
10
  gem "github_changelog_generator", "1.9.0"
@@ -13,21 +12,20 @@ end
13
12
 
14
13
  group :test do
15
14
  gem "minitest", "~> 5.0"
16
- gem "test_after_commit", "~> 0.4.2"
17
15
  gem "timecop"
18
16
  gem "mocha"
19
17
  end
20
18
 
21
19
  group :sqlite do
22
- gem "sqlite3", "~> 1.3.13", platforms: [:ruby]
20
+ gem "sqlite3", "~> 1.3.13"
23
21
  end
24
22
 
25
23
  group :postgresql do
26
- gem "pg", "~> 0.18.0", platforms: [:ruby]
24
+ gem "pg", "~> 1.1.4"
27
25
  end
28
26
 
29
27
  group :mysql do
30
- gem "mysql2", "~> 0.4.10", platforms: [:ruby]
28
+ gem "mysql2", "~> 0.5.0"
31
29
  end
32
30
 
33
31
  gemspec path: "../"
@@ -0,0 +1,31 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rake"
6
+ gem "appraisal"
7
+ gem "activerecord", "~> 6.0.0"
8
+
9
+ group :development do
10
+ gem "github_changelog_generator", "1.9.0"
11
+ end
12
+
13
+ group :test do
14
+ gem "minitest", "~> 5.0"
15
+ gem "timecop"
16
+ gem "mocha"
17
+ end
18
+
19
+ group :sqlite do
20
+ gem "sqlite3", "~> 1.4"
21
+ end
22
+
23
+ group :postgresql do
24
+ gem "pg", "~> 1.1.4"
25
+ end
26
+
27
+ group :mysql do
28
+ gem "mysql2", "~> 0.5.0"
29
+ end
30
+
31
+ gemspec path: "../"
@@ -65,6 +65,12 @@ module ActiveRecord
65
65
  end
66
66
 
67
67
  module InstanceMethods
68
+ # Get the current position of the item in the list
69
+ def current_position
70
+ position = send(position_column)
71
+ position ? position.to_i : nil
72
+ end
73
+
68
74
  # Insert the item at the given position (defaults to the top position of 1).
69
75
  def insert_at(position = acts_as_list_top)
70
76
  insert_at_position(position)
@@ -79,8 +85,8 @@ module ActiveRecord
79
85
  return unless lower_item
80
86
 
81
87
  acts_as_list_class.transaction do
82
- if lower_item.send(position_column) != self.send(position_column)
83
- swap_positions(lower_item, self)
88
+ if lower_item.current_position != current_position
89
+ swap_positions_with(lower_item)
84
90
  else
85
91
  lower_item.decrement_position
86
92
  increment_position
@@ -93,8 +99,8 @@ module ActiveRecord
93
99
  return unless higher_item
94
100
 
95
101
  acts_as_list_class.transaction do
96
- if higher_item.send(position_column) != self.send(position_column)
97
- swap_positions(higher_item, self)
102
+ if higher_item.current_position != current_position
103
+ swap_positions_with(higher_item)
98
104
  else
99
105
  higher_item.increment_position
100
106
  decrement_position
@@ -134,13 +140,13 @@ module ActiveRecord
134
140
  # Increase the position of this item without adjusting the rest of the list.
135
141
  def increment_position
136
142
  return unless in_list?
137
- set_list_position(self.send(position_column).to_i + 1)
143
+ set_list_position(current_position + 1)
138
144
  end
139
145
 
140
146
  # Decrease the position of this item without adjusting the rest of the list.
141
147
  def decrement_position
142
148
  return unless in_list?
143
- set_list_position(self.send(position_column).to_i - 1)
149
+ set_list_position(current_position - 1)
144
150
  end
145
151
 
146
152
  def first?
@@ -163,9 +169,8 @@ module ActiveRecord
163
169
  # selects all higher items by default
164
170
  def higher_items(limit=nil)
165
171
  limit ||= acts_as_list_list.count
166
- position_value = send(position_column)
167
172
  acts_as_list_list.
168
- where("#{quoted_position_column_with_table_name} <= ?", position_value).
173
+ where("#{quoted_position_column_with_table_name} <= ?", current_position).
169
174
  where("#{quoted_table_name}.#{self.class.primary_key} != ?", self.send(self.class.primary_key)).
170
175
  reorder(acts_as_list_order_argument(:desc)).
171
176
  limit(limit)
@@ -181,9 +186,8 @@ module ActiveRecord
181
186
  # selects all lower items by default
182
187
  def lower_items(limit=nil)
183
188
  limit ||= acts_as_list_list.count
184
- position_value = send(position_column)
185
189
  acts_as_list_list.
186
- where("#{quoted_position_column_with_table_name} >= ?", position_value).
190
+ where("#{quoted_position_column_with_table_name} >= ?", current_position).
187
191
  where("#{quoted_table_name}.#{self.class.primary_key} != ?", self.send(self.class.primary_key)).
188
192
  reorder(acts_as_list_order_argument(:asc)).
189
193
  limit(limit)
@@ -195,40 +199,34 @@ module ActiveRecord
195
199
  end
196
200
 
197
201
  def not_in_list?
198
- send(position_column).nil?
202
+ current_position.nil?
199
203
  end
200
204
 
201
205
  def default_position
202
- acts_as_list_class.columns_hash[position_column.to_s].default
206
+ acts_as_list_class.column_defaults[position_column.to_s]
203
207
  end
204
208
 
205
209
  def default_position?
206
- default_position && default_position.to_i == send(position_column)
210
+ default_position && default_position == current_position
207
211
  end
208
212
 
209
213
  # Sets the new position and saves it
210
214
  def set_list_position(new_position, raise_exception_if_save_fails=false)
211
- write_attribute position_column, new_position
215
+ self[position_column] = new_position
212
216
  raise_exception_if_save_fails ? save! : save
213
217
  end
214
218
 
215
219
  private
216
220
 
217
- def swap_positions(item1, item2)
218
- item1_position = item1.send(position_column)
221
+ def swap_positions_with(item)
222
+ item_position = item.current_position
219
223
 
220
- item1.set_list_position(item2.send(position_column))
221
- item2.set_list_position(item1_position)
224
+ item.set_list_position(current_position)
225
+ set_list_position(item_position)
222
226
  end
223
227
 
224
228
  def acts_as_list_list
225
- if ActiveRecord::VERSION::MAJOR < 4
226
- acts_as_list_class.unscoped do
227
- acts_as_list_class.where(scope_condition)
228
- end
229
- else
230
- acts_as_list_class.unscope(:select, :where).where(scope_condition)
231
- end
229
+ acts_as_list_class.unscope(:select, :where).where(scope_condition)
232
230
  end
233
231
 
234
232
  # Poorly named methods. They will insert the item at the desired position if the position
@@ -276,7 +274,7 @@ module ActiveRecord
276
274
  # bottom_position_in_list # => 2
277
275
  def bottom_position_in_list(except = nil)
278
276
  item = bottom_item(except)
279
- item ? item.send(position_column) : acts_as_list_top - 1
277
+ item ? item.current_position : acts_as_list_top - 1
280
278
  end
281
279
 
282
280
  # Returns the bottom item
@@ -303,7 +301,7 @@ module ActiveRecord
303
301
  # This has the effect of moving all the higher items down one.
304
302
  def increment_positions_on_higher_items
305
303
  return unless in_list?
306
- acts_as_list_list.where("#{quoted_position_column_with_table_name} < ?", send(position_column).to_i).increment_all
304
+ acts_as_list_list.where("#{quoted_position_column_with_table_name} < ?", current_position).increment_all
307
305
  end
308
306
 
309
307
  # This has the effect of moving all the lower items down one.
@@ -323,9 +321,8 @@ module ActiveRecord
323
321
  end
324
322
 
325
323
  # This has the effect of moving all the lower items up one.
326
- def decrement_positions_on_lower_items(position=nil)
324
+ def decrement_positions_on_lower_items(position=current_position)
327
325
  return unless in_list?
328
- position ||= send(position_column).to_i
329
326
 
330
327
  if sequential_updates?
331
328
  acts_as_list_list.where("#{quoted_position_column_with_table_name} > ?", position).reorder(acts_as_list_order_argument(:asc)).decrement_sequentially
@@ -392,7 +389,7 @@ module ActiveRecord
392
389
  return set_list_position(position, raise_exception_if_save_fails) if new_record?
393
390
  with_lock do
394
391
  if in_list?
395
- old_position = send(position_column).to_i
392
+ old_position = current_position
396
393
  return if position == old_position
397
394
  # temporary move after bottom with gap, avoiding duplicate values
398
395
  # gap is required to leave room for position increments
@@ -411,31 +408,27 @@ module ActiveRecord
411
408
  return unless position_before_save_changed?
412
409
 
413
410
  old_position = position_before_save || bottom_position_in_list + 1
414
- new_position = send(position_column).to_i
415
411
 
416
- return unless acts_as_list_list.where(
417
- "#{quoted_position_column_with_table_name} = #{new_position}"
412
+ return unless current_position && acts_as_list_list.where(
413
+ "#{quoted_position_column_with_table_name} = #{current_position}"
418
414
  ).count > 1
419
- shuffle_positions_on_intermediate_items old_position, new_position, id
415
+
416
+ shuffle_positions_on_intermediate_items old_position, current_position, id
420
417
  end
421
418
 
422
419
  def position_before_save_changed?
423
- if ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR >= 1 ||
424
- ActiveRecord::VERSION::MAJOR > 5
425
-
420
+ if active_record_version_is?('>= 5.1')
426
421
  saved_change_to_attribute? position_column
427
422
  else
428
- send "#{position_column}_changed?"
423
+ attribute_changed? position_column
429
424
  end
430
425
  end
431
426
 
432
427
  def position_before_save
433
- if ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR >= 1 ||
434
- ActiveRecord::VERSION::MAJOR > 5
435
-
428
+ if active_record_version_is?('>= 5.1')
436
429
  attribute_before_last_save position_column
437
430
  else
438
- send "#{position_column}_was"
431
+ attribute_was position_column
439
432
  end
440
433
  end
441
434
 
@@ -464,7 +457,7 @@ module ActiveRecord
464
457
  # This check is skipped if the position is currently the default position from the table
465
458
  # as modifying the default position on creation is handled elsewhere
466
459
  def check_top_position
467
- if send(position_column) && !default_position? && send(position_column) < acts_as_list_top
460
+ if current_position && !default_position? && current_position < acts_as_list_top
468
461
  self[position_column] = acts_as_list_top
469
462
  end
470
463
  end
@@ -484,11 +477,13 @@ module ActiveRecord
484
477
  end
485
478
 
486
479
  def acts_as_list_order_argument(direction = :asc)
487
- if ActiveRecord::VERSION::MAJOR >= 4
488
- { position_column => direction }
489
- else
490
- "#{quoted_position_column_with_table_name} #{direction.to_s.upcase}"
491
- end
480
+ { position_column => direction }
481
+ end
482
+
483
+ def active_record_version_is?(version_requirement)
484
+ requirement = Gem::Requirement.new(version_requirement)
485
+ version = Gem.loaded_specs['activerecord'].version
486
+ requirement.satisfied_by?(version)
492
487
  end
493
488
  end
494
489
 
@@ -64,7 +64,7 @@ module ActiveRecord::Acts::List::PositionColumnMethodDefiner #:nodoc:
64
64
  end
65
65
 
66
66
  define_method :"#{position_column}=" do |position|
67
- write_attribute(position_column, position)
67
+ self[position_column] = position
68
68
  @position_changed = true
69
69
  end
70
70
 
@@ -21,7 +21,6 @@ module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
21
21
  end
22
22
 
23
23
  define_method :destroyed_via_scope? do
24
- return false if ActiveRecord::VERSION::MAJOR < 4
25
24
  scope == (destroyed_by_association && destroyed_by_association.foreign_key.to_sym)
26
25
  end
27
26
  elsif scope.is_a?(Array)
@@ -45,7 +44,6 @@ module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
45
44
  end
46
45
 
47
46
  define_method :destroyed_via_scope? do
48
- return false if ActiveRecord::VERSION::MAJOR < 4
49
47
  scope_condition.keys.include? (destroyed_by_association && destroyed_by_association.foreign_key.to_sym)
50
48
  end
51
49
  else
@@ -7,7 +7,7 @@ module ActiveRecord::Acts::List::SequentialUpdatesMethodDefiner #:nodoc:
7
7
  if !defined?(@sequential_updates)
8
8
  if sequential_updates_option.nil?
9
9
  table_exists =
10
- if ActiveRecord::VERSION::MAJOR >= 5
10
+ if active_record_version_is?('>= 5')
11
11
  caller_class.connection.data_source_exists?(caller_class.table_name)
12
12
  else
13
13
  caller_class.connection.table_exists?(caller_class.table_name)
@@ -3,7 +3,7 @@
3
3
  module ActiveRecord
4
4
  module Acts
5
5
  module List
6
- VERSION = '0.9.19'
6
+ VERSION = '1.0.0'
7
7
  end
8
8
  end
9
9
  end
@@ -13,7 +13,7 @@ rescue Bundler::BundlerError => e
13
13
  end
14
14
  require "active_record"
15
15
  require "minitest/autorun"
16
- require "mocha/mini_test"
16
+ require "mocha/minitest"
17
17
  require "#{File.dirname(__FILE__)}/../init"
18
18
 
19
19
  if defined?(ActiveRecord::VERSION) &&
@@ -27,15 +27,6 @@ db_config = YAML.load_file(File.expand_path("../database.yml", __FILE__)).fetch(
27
27
  ActiveRecord::Base.establish_connection(db_config)
28
28
  ActiveRecord::Schema.verbose = false
29
29
 
30
- # Returns true if ActiveRecord is rails 3, 4 version
31
- def rails_3
32
- defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::MAJOR >= 3
33
- end
34
-
35
- def rails_4
36
- defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::MAJOR >= 4
37
- end
38
-
39
30
  def teardown_db
40
31
  if ActiveRecord::VERSION::MAJOR >= 5
41
32
  tables = ActiveRecord::Base.connection.data_sources
@@ -10,6 +10,13 @@ module Shared
10
10
  end
11
11
  end
12
12
 
13
+ def test_current_position
14
+ first_item = ListMixin.where(parent_id: 5).first
15
+ assert_equal 1, first_item.current_position
16
+ first_item.remove_from_list
17
+ assert_nil first_item.current_position
18
+ end
19
+
13
20
  def test_reordering
14
21
  assert_equal [1, 2, 3, 4], ListMixin.where(parent_id: 5).order('pos').map(&:id)
15
22
 
@@ -230,12 +237,9 @@ module Shared
230
237
  # We need to trigger all the before_destroy callbacks without actually
231
238
  # destroying the record so we can see the affect the callbacks have on
232
239
  # the record.
233
- # NOTE: Hotfix for rails3 ActiveRecord
234
240
  list = ListMixin.where(id: 2).first
235
241
  if list.respond_to?(:run_callbacks)
236
- # Refactored to work according to Rails3 ActiveRSupport Callbacks <http://api.rubyonrails.org/classes/ActiveSupport/Callbacks.html>
237
- list.run_callbacks(:destroy) if rails_3
238
- list.run_callbacks(:before_destroy) if !rails_3
242
+ list.run_callbacks(:destroy)
239
243
  else
240
244
  list.send(:callback, :before_destroy)
241
245
  end
@@ -47,7 +47,7 @@ module Shared
47
47
 
48
48
  def test_next_prev_not_regular_sequence
49
49
  ListMixin.all.each do |item|
50
- item.update_attributes(pos: item.pos * 5)
50
+ item.update pos: item.pos * 5
51
51
  end
52
52
 
53
53
  assert_equal [1, 2, 3, 4], ListMixin.where(parent_id: 5000).order('pos').map(&:id)
@@ -49,11 +49,9 @@ def setup_db(position_options = {})
49
49
  ActiveRecord::Base.connection.add_index 'altid-table', :pos, unique: true
50
50
 
51
51
  mixins = [ Mixin, ListMixin, ListMixinSub1, ListMixinSub2, ListWithStringScopeMixin,
52
- ArrayScopeListMixin, ZeroBasedMixin, DefaultScopedMixin,
52
+ ArrayScopeListMixin, ZeroBasedMixin, DefaultScopedMixin, EnumArrayScopeListMixin,
53
53
  DefaultScopedWhereMixin, TopAdditionMixin, NoAdditionMixin, QuotedList, TouchDisabledMixin ]
54
54
 
55
- mixins << EnumArrayScopeListMixin if rails_4
56
-
57
55
  ActiveRecord::Base.connection.schema_cache.clear!
58
56
  mixins.each do |klass|
59
57
  klass.reset_column_information
@@ -80,19 +78,11 @@ class ListMixinSub1 < ListMixin
80
78
  end
81
79
 
82
80
  class ListMixinSub2 < ListMixin
83
- if rails_3
84
- validates :pos, presence: true
85
- else
86
- validates_presence_of :pos
87
- end
81
+ validates :pos, presence: true
88
82
  end
89
83
 
90
84
  class ListMixinError < ListMixin
91
- if rails_3
92
- validates :state, presence: true
93
- else
94
- validates_presence_of :state
95
- end
85
+ validates :state, presence: true
96
86
  end
97
87
 
98
88
  class ListWithStringScopeMixin < Mixin
@@ -107,13 +97,11 @@ class ArrayScopeListWithHashMixin < Mixin
107
97
  acts_as_list column: "pos", scope: [:parent_id, state: nil]
108
98
  end
109
99
 
110
- if rails_4
111
- class EnumArrayScopeListMixin < Mixin
112
- STATE_VALUES = %w(active archived)
113
- enum state: STATE_VALUES
100
+ class EnumArrayScopeListMixin < Mixin
101
+ STATE_VALUES = %w(active archived)
102
+ enum state: STATE_VALUES
114
103
 
115
- acts_as_list column: "pos", scope: [:parent_id, :state]
116
- end
104
+ acts_as_list column: "pos", scope: [:parent_id, :state]
117
105
  end
118
106
 
119
107
  class ZeroBasedMixin < Mixin
@@ -130,13 +118,7 @@ class DefaultScopedWhereMixin < Mixin
130
118
  default_scope { order('pos ASC').where(active: true) }
131
119
 
132
120
  def self.for_active_false_tests
133
- if ActiveRecord::VERSION::MAJOR < 4
134
- unscoped do
135
- order('pos ASC').where(active: false)
136
- end
137
- else
138
- unscope(:where).where(active: false)
139
- end
121
+ unscope(:where).where(active: false)
140
122
  end
141
123
  end
142
124
 
@@ -170,7 +152,7 @@ end
170
152
  ##
171
153
  # The way we track changes to
172
154
  # scope and position can get tripped up
173
- # by someone using update_attributes within
155
+ # by someone using update within
174
156
  # a callback because it causes multiple passes
175
157
  # through the callback chain
176
158
  module CallbackMixin
@@ -185,7 +167,7 @@ module CallbackMixin
185
167
  # doesn't matter what column changes, just
186
168
  # need to change something
187
169
 
188
- self.update_attributes(active: !self.active)
170
+ self.update active: !self.active
189
171
  end
190
172
  end
191
173
  end
@@ -649,7 +631,7 @@ class MultipleListsTest < ActsAsListTestCase
649
631
  def test_check_scope_order
650
632
  assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 1).order('pos').map(&:id)
651
633
  assert_equal [5, 6, 7, 8], ListMixin.where(:parent_id => 2).order('pos').map(&:id)
652
- ListMixin.find(4).update_attributes(:parent_id => 2, :pos => 2)
634
+ ListMixin.find(4).update :parent_id => 2, :pos => 2
653
635
  assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order('pos').map(&:id)
654
636
  assert_equal [5, 4, 6, 7, 8], ListMixin.where(:parent_id => 2).order('pos').map(&:id)
655
637
  end
@@ -657,34 +639,32 @@ class MultipleListsTest < ActsAsListTestCase
657
639
  def test_check_scope_position
658
640
  assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 1).map(&:pos)
659
641
  assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 2).map(&:pos)
660
- ListMixin.find(4).update_attributes(:parent_id => 2, :pos => 2)
642
+ ListMixin.find(4).update :parent_id => 2, :pos => 2
661
643
  assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order('pos').map(&:pos)
662
644
  assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 2).order('pos').map(&:pos)
663
645
  end
664
646
  end
665
647
 
666
- if rails_4
667
- class EnumArrayScopeListMixinTest < ActsAsListTestCase
668
- def setup
669
- setup_db
670
- EnumArrayScopeListMixin.create! :parent_id => 1, :state => EnumArrayScopeListMixin.states['active']
671
- EnumArrayScopeListMixin.create! :parent_id => 1, :state => EnumArrayScopeListMixin.states['archived']
672
- EnumArrayScopeListMixin.create! :parent_id => 2, :state => EnumArrayScopeListMixin.states["active"]
673
- EnumArrayScopeListMixin.create! :parent_id => 2, :state => EnumArrayScopeListMixin.states["archived"]
674
- end
648
+ class EnumArrayScopeListMixinTest < ActsAsListTestCase
649
+ def setup
650
+ setup_db
651
+ EnumArrayScopeListMixin.create! :parent_id => 1, :state => EnumArrayScopeListMixin.states['active']
652
+ EnumArrayScopeListMixin.create! :parent_id => 1, :state => EnumArrayScopeListMixin.states['archived']
653
+ EnumArrayScopeListMixin.create! :parent_id => 2, :state => EnumArrayScopeListMixin.states["active"]
654
+ EnumArrayScopeListMixin.create! :parent_id => 2, :state => EnumArrayScopeListMixin.states["archived"]
655
+ end
675
656
 
676
- def test_positions
677
- assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 1, :state => EnumArrayScopeListMixin.states['active']).map(&:pos)
678
- assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 1, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos)
679
- assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['active']).map(&:pos)
680
- assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos)
681
- end
657
+ def test_positions
658
+ assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 1, :state => EnumArrayScopeListMixin.states['active']).map(&:pos)
659
+ assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 1, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos)
660
+ assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['active']).map(&:pos)
661
+ assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos)
662
+ end
682
663
 
683
- def test_update_state
684
- active_item = EnumArrayScopeListMixin.find_by(:parent_id => 2, :state => EnumArrayScopeListMixin.states['active'])
685
- active_item.update(state: EnumArrayScopeListMixin.states['archived'])
686
- assert_equal [1, 2], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos).sort
687
- end
664
+ def test_update_state
665
+ active_item = EnumArrayScopeListMixin.find_by(:parent_id => 2, :state => EnumArrayScopeListMixin.states['active'])
666
+ active_item.update(state: EnumArrayScopeListMixin.states['archived'])
667
+ assert_equal [1, 2], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos).sort
688
668
  end
689
669
  end
690
670
 
@@ -699,7 +679,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
699
679
  def test_order_after_all_scope_properties_are_changed
700
680
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
701
681
  assert_equal [5, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order('pos').map(&:id)
702
- ArrayScopeListMixin.find(2).update_attributes(:parent_id => 2, :pos => 2,:parent_type => 'something')
682
+ ArrayScopeListMixin.find(2).update :parent_id => 2, :pos => 2,:parent_type => 'something'
703
683
  assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
704
684
  assert_equal [5, 2, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2,:parent_type => 'something').order('pos').map(&:id)
705
685
  end
@@ -707,7 +687,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
707
687
  def test_position_after_all_scope_properties_are_changed
708
688
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
709
689
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').map(&:pos)
710
- ArrayScopeListMixin.find(4).update_attributes(:parent_id => 2, :pos => 2, :parent_type => 'something')
690
+ ArrayScopeListMixin.find(4).update :parent_id => 2, :pos => 2, :parent_type => 'something'
711
691
  assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
712
692
  assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order('pos').map(&:pos)
713
693
  end
@@ -715,7 +695,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
715
695
  def test_order_after_one_scope_property_is_changed
716
696
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
717
697
  assert_equal [9, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order('pos').map(&:id)
718
- ArrayScopeListMixin.find(2).update_attributes(:parent_id => 3, :pos => 2)
698
+ ArrayScopeListMixin.find(2).update :parent_id => 3, :pos => 2
719
699
  assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
720
700
  assert_equal [9, 2, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3,:parent_type => 'anything').order('pos').map(&:id)
721
701
  end
@@ -723,7 +703,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
723
703
  def test_position_after_one_scope_property_is_changed
724
704
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
725
705
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').map(&:pos)
726
- ArrayScopeListMixin.find(4).update_attributes(:parent_id => 3, :pos => 2)
706
+ ArrayScopeListMixin.find(4).update :parent_id => 3, :pos => 2
727
707
  assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
728
708
  assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order('pos').map(&:pos)
729
709
  end
@@ -731,7 +711,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
731
711
  def test_order_after_moving_to_empty_list
732
712
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
733
713
  assert_equal [], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order('pos').map(&:id)
734
- ArrayScopeListMixin.find(2).update_attributes(:parent_id => 4, :pos => 1)
714
+ ArrayScopeListMixin.find(2).update :parent_id => 4, :pos => 1
735
715
  assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
736
716
  assert_equal [2], ArrayScopeListMixin.where(:parent_id => 4,:parent_type => 'anything').order('pos').map(&:id)
737
717
  end
@@ -739,7 +719,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
739
719
  def test_position_after_moving_to_empty_list
740
720
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
741
721
  assert_equal [], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').map(&:pos)
742
- ArrayScopeListMixin.find(2).update_attributes(:parent_id => 4, :pos => 1)
722
+ ArrayScopeListMixin.find(2).update :parent_id => 4, :pos => 1
743
723
  assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
744
724
  assert_equal [1], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order('pos').map(&:pos)
745
725
  end