acts_as_list 0.9.18 → 1.0.3

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.
@@ -89,20 +89,30 @@ module ActiveRecord
89
89
 
90
90
  class << self
91
91
  def apply_to(klasses)
92
- extracted_klasses.push(*klasses)
92
+ klasses.map {|klass| add_klass(klass)}
93
93
  yield
94
94
  ensure
95
- extracted_klasses.clear
95
+ klasses.map {|klass| remove_klass(klass)}
96
96
  end
97
97
 
98
98
  def applied_to?(klass)
99
- !(klass.ancestors & extracted_klasses).empty?
99
+ !(klass.ancestors & extracted_klasses.keys).empty?
100
100
  end
101
101
 
102
102
  private
103
103
 
104
104
  def extracted_klasses
105
- Thread.current[:act_as_list_no_update] ||= []
105
+ Thread.current[:act_as_list_no_update] ||= {}
106
+ end
107
+
108
+ def add_klass(klass)
109
+ extracted_klasses[klass] = 0 unless extracted_klasses.key?(klass)
110
+ extracted_klasses[klass] += 1
111
+ end
112
+
113
+ def remove_klass(klass)
114
+ extracted_klasses[klass] -= 1
115
+ extracted_klasses.delete(klass) if extracted_klasses[klass] <= 0
106
116
  end
107
117
  end
108
118
 
@@ -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
 
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
+ require "active_support/inflector"
2
3
 
3
4
  module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
4
5
  extend ActiveSupport::Inflector
5
6
 
6
7
  def self.call(caller_class, scope)
7
- scope = idify(scope) if scope.is_a?(Symbol)
8
+ scope = idify(caller_class, scope) if scope.is_a?(Symbol)
8
9
 
9
10
  caller_class.class_eval do
10
11
  define_method :scope_name do
@@ -21,7 +22,6 @@ module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
21
22
  end
22
23
 
23
24
  define_method :destroyed_via_scope? do
24
- return false if ActiveRecord::VERSION::MAJOR < 4
25
25
  scope == (destroyed_by_association && destroyed_by_association.foreign_key.to_sym)
26
26
  end
27
27
  elsif scope.is_a?(Array)
@@ -45,7 +45,6 @@ module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
45
45
  end
46
46
 
47
47
  define_method :destroyed_via_scope? do
48
- return false if ActiveRecord::VERSION::MAJOR < 4
49
48
  scope_condition.keys.include? (destroyed_by_association && destroyed_by_association.foreign_key.to_sym)
50
49
  end
51
50
  else
@@ -66,9 +65,13 @@ module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
66
65
  end
67
66
  end
68
67
 
69
- def self.idify(name)
68
+ def self.idify(caller_class, name)
70
69
  return name if name.to_s =~ /_id$/
71
70
 
72
- foreign_key(name).to_sym
71
+ if caller_class.reflections.key?(name.to_s)
72
+ caller_class.reflections[name.to_s].foreign_key.to_sym
73
+ else
74
+ foreign_key(name).to_sym
75
+ end
73
76
  end
74
77
  end
@@ -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.18'
6
+ VERSION = '1.0.3'
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
@@ -60,3 +51,19 @@ def assert_equal_or_nil(a, b)
60
51
  assert_equal a, b
61
52
  end
62
53
  end
54
+
55
+ def assert_no_deprecation_warning_raised_by(failure_message = 'ActiveRecord deprecation warning raised when we didn\'t expect it', pass_message = 'No ActiveRecord deprecation raised')
56
+ original_behavior = ActiveSupport::Deprecation.behavior
57
+ ActiveSupport::Deprecation.behavior = :raise
58
+ begin
59
+ yield
60
+ rescue ActiveSupport::DeprecationException => e
61
+ flunk "#{failure_message}: #{e}"
62
+ rescue
63
+ raise
64
+ else
65
+ pass pass_message
66
+ end
67
+ ensure
68
+ ActiveSupport::Deprecation.behavior = original_behavior
69
+ end
@@ -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
@@ -310,5 +314,11 @@ module Shared
310
314
  new.insert_at!(1)
311
315
  end
312
316
  end
317
+
318
+ def test_find_or_create_doesnt_raise_deprecation_warning
319
+ assert_no_deprecation_warning_raised_by('ActiveRecord deprecation warning raised when using `find_or_create_by` when we didn\'t expect it') do
320
+ ListMixin.where(parent_id: 5).find_or_create_by(pos: 5)
321
+ end
322
+ end
313
323
  end
314
324
  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
@@ -437,6 +419,12 @@ class DefaultScopedTest < ActsAsListTestCase
437
419
  assert_equal_or_nil $default_position, new_noup.pos
438
420
  end
439
421
 
422
+ def test_find_or_create_doesnt_raise_deprecation_warning
423
+ assert_no_deprecation_warning_raised_by('ActiveRecord deprecation warning raised when using `find_or_create_by` when we didn\'t expect it') do
424
+ DefaultScopedMixin.find_or_create_by(pos: 5)
425
+ end
426
+ end
427
+
440
428
  def test_update_position
441
429
  assert_equal [1, 2, 3, 4], DefaultScopedMixin.all.map(&:id)
442
430
  DefaultScopedMixin.where(id: 2).first.set_list_position(4)
@@ -541,6 +529,12 @@ class DefaultScopedWhereTest < ActsAsListTestCase
541
529
  assert_equal_or_nil $default_position, new_noup.pos
542
530
  end
543
531
 
532
+ def test_find_or_create_doesnt_raise_deprecation_warning
533
+ assert_no_deprecation_warning_raised_by('ActiveRecord deprecation warning raised when using `find_or_create_by` when we didn\'t expect it') do
534
+ DefaultScopedWhereMixin.find_or_create_by(pos: 5)
535
+ end
536
+ end
537
+
544
538
  def test_update_position
545
539
  assert_equal [1, 2, 3, 4], DefaultScopedWhereMixin.for_active_false_tests.map(&:id)
546
540
  DefaultScopedWhereMixin.for_active_false_tests.where(id: 2).first.set_list_position(4)
@@ -649,7 +643,7 @@ class MultipleListsTest < ActsAsListTestCase
649
643
  def test_check_scope_order
650
644
  assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 1).order('pos').map(&:id)
651
645
  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)
646
+ ListMixin.find(4).update :parent_id => 2, :pos => 2
653
647
  assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order('pos').map(&:id)
654
648
  assert_equal [5, 4, 6, 7, 8], ListMixin.where(:parent_id => 2).order('pos').map(&:id)
655
649
  end
@@ -657,34 +651,38 @@ class MultipleListsTest < ActsAsListTestCase
657
651
  def test_check_scope_position
658
652
  assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 1).map(&:pos)
659
653
  assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 2).map(&:pos)
660
- ListMixin.find(4).update_attributes(:parent_id => 2, :pos => 2)
654
+ ListMixin.find(4).update :parent_id => 2, :pos => 2
661
655
  assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order('pos').map(&:pos)
662
656
  assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 2).order('pos').map(&:pos)
663
657
  end
664
- end
665
658
 
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"]
659
+ def test_find_or_create_doesnt_raise_deprecation_warning
660
+ assert_no_deprecation_warning_raised_by('ActiveRecord deprecation warning raised when using `find_or_create_by` when we didn\'t expect it') do
661
+ ListMixin.where(:parent_id => 1).find_or_create_by(pos: 5)
674
662
  end
663
+ end
664
+ end
675
665
 
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
666
+ class EnumArrayScopeListMixinTest < ActsAsListTestCase
667
+ def setup
668
+ setup_db
669
+ EnumArrayScopeListMixin.create! :parent_id => 1, :state => EnumArrayScopeListMixin.states['active']
670
+ EnumArrayScopeListMixin.create! :parent_id => 1, :state => EnumArrayScopeListMixin.states['archived']
671
+ EnumArrayScopeListMixin.create! :parent_id => 2, :state => EnumArrayScopeListMixin.states["active"]
672
+ EnumArrayScopeListMixin.create! :parent_id => 2, :state => EnumArrayScopeListMixin.states["archived"]
673
+ end
682
674
 
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
675
+ def test_positions
676
+ assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 1, :state => EnumArrayScopeListMixin.states['active']).map(&:pos)
677
+ assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 1, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos)
678
+ assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['active']).map(&:pos)
679
+ assert_equal [1], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos)
680
+ end
681
+
682
+ def test_update_state
683
+ active_item = EnumArrayScopeListMixin.find_by(:parent_id => 2, :state => EnumArrayScopeListMixin.states['active'])
684
+ active_item.update(state: EnumArrayScopeListMixin.states['archived'])
685
+ assert_equal [1, 2], EnumArrayScopeListMixin.where(:parent_id => 2, :state => EnumArrayScopeListMixin.states['archived']).map(&:pos).sort
688
686
  end
689
687
  end
690
688
 
@@ -699,7 +697,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
699
697
  def test_order_after_all_scope_properties_are_changed
700
698
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
701
699
  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')
700
+ ArrayScopeListMixin.find(2).update :parent_id => 2, :pos => 2,:parent_type => 'something'
703
701
  assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
704
702
  assert_equal [5, 2, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2,:parent_type => 'something').order('pos').map(&:id)
705
703
  end
@@ -707,7 +705,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
707
705
  def test_position_after_all_scope_properties_are_changed
708
706
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
709
707
  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')
708
+ ArrayScopeListMixin.find(4).update :parent_id => 2, :pos => 2, :parent_type => 'something'
711
709
  assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
712
710
  assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order('pos').map(&:pos)
713
711
  end
@@ -715,7 +713,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
715
713
  def test_order_after_one_scope_property_is_changed
716
714
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
717
715
  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)
716
+ ArrayScopeListMixin.find(2).update :parent_id => 3, :pos => 2
719
717
  assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
720
718
  assert_equal [9, 2, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3,:parent_type => 'anything').order('pos').map(&:id)
721
719
  end
@@ -723,7 +721,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
723
721
  def test_position_after_one_scope_property_is_changed
724
722
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
725
723
  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)
724
+ ArrayScopeListMixin.find(4).update :parent_id => 3, :pos => 2
727
725
  assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
728
726
  assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order('pos').map(&:pos)
729
727
  end
@@ -731,7 +729,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
731
729
  def test_order_after_moving_to_empty_list
732
730
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
733
731
  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)
732
+ ArrayScopeListMixin.find(2).update :parent_id => 4, :pos => 1
735
733
  assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
736
734
  assert_equal [2], ArrayScopeListMixin.where(:parent_id => 4,:parent_type => 'anything').order('pos').map(&:id)
737
735
  end
@@ -739,7 +737,7 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
739
737
  def test_position_after_moving_to_empty_list
740
738
  assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
741
739
  assert_equal [], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').map(&:pos)
742
- ArrayScopeListMixin.find(2).update_attributes(:parent_id => 4, :pos => 1)
740
+ ArrayScopeListMixin.find(2).update :parent_id => 4, :pos => 1
743
741
  assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
744
742
  assert_equal [1], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order('pos').map(&:pos)
745
743
  end
@@ -1015,6 +1013,11 @@ class SequentialUpdatesMixinNotNullUniquePositiveConstraintsTest < ActsAsListTes
1015
1013
  assert_equal 3, new.pos
1016
1014
  end
1017
1015
 
1016
+ def test_create_at_top
1017
+ new = SequentialUpdatesAltId.create!(pos: 1)
1018
+ assert_equal 1, new.pos
1019
+ end
1020
+
1018
1021
  def test_move_to_bottom
1019
1022
  item = SequentialUpdatesAltId.order(:pos).first
1020
1023
  item.move_to_bottom
@@ -52,16 +52,17 @@ class NoUpdateForCollectionClassesTest < NoUpdateForCollectionClassesTestCase
52
52
 
53
53
  @item_1, @item_2 = (1..2).map { |counter| TodoItem.create!(position: counter, todo_list_id: @list_1.id) }
54
54
  @attachment_1, @attachment_2 = (1..2).map { |counter| TodoItemAttachment.create!(position: counter, todo_item_id: @item_1.id) }
55
+ @attachment_3, @attachment_4 = (1..2).map {|counter| TodoItemAttachment.create!(position: counter, todo_item_id: @item_2.id)}
55
56
  end
56
57
 
57
58
  def test_update
58
- @item_1.update_attributes(position: 2)
59
+ @item_1.update position: 2
59
60
  assert_equal 2, @item_1.reload.position
60
61
  assert_equal 1, @item_2.reload.position
61
62
  end
62
63
 
63
64
  def test_no_update_for_single_class_instances
64
- TodoItem.acts_as_list_no_update { @item_1.update_attributes(position: 2) }
65
+ TodoItem.acts_as_list_no_update { @item_1.update position: 2 }
65
66
 
66
67
  assert_equal 2, @item_1.reload.position
67
68
  assert_equal 2, @item_2.reload.position
@@ -80,6 +81,30 @@ class NoUpdateForCollectionClassesTest < NoUpdateForCollectionClassesTestCase
80
81
  assert_equal 1, @list_2.reload.position
81
82
  end
82
83
 
84
+ def test_no_update_for_nested_blocks
85
+ new_list = @list_1.dup
86
+ new_list.save!
87
+
88
+ TodoItem.acts_as_list_no_update do
89
+ @list_1.todo_items.reverse.each do |item|
90
+ new_item = item.dup
91
+ new_list.todo_items << new_item
92
+ new_item.save!
93
+
94
+ assert_equal new_item.position, item.reload.position
95
+
96
+ TodoItemAttachment.acts_as_list_no_update do
97
+ item.todo_item_attachments.reverse.each do |attach|
98
+ new_attach = attach.dup
99
+ new_item.todo_item_attachments << new_attach
100
+ new_attach.save!
101
+ assert_equal new_attach.position, attach.reload.position
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+
83
108
  def test_raising_array_type_error
84
109
  exception = assert_raises ActiveRecord::Acts::List::NoUpdate::ArrayTypeError do
85
110
  TodoList.acts_as_list_no_update(nil)
@@ -99,8 +124,8 @@ class NoUpdateForCollectionClassesTest < NoUpdateForCollectionClassesTestCase
99
124
  private
100
125
 
101
126
  def update_records!
102
- @item_1.update_attributes(position: 2)
103
- @attachment_1.update_attributes(position: 2)
104
- @list_1.update_attributes(position: 2)
127
+ @item_1.update position: 2
128
+ @attachment_1.update position: 2
129
+ @list_1.update position: 2
105
130
  end
106
131
  end