acts_as_list 0.9.19 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +3 -0
- data/.travis.yml +33 -36
- data/Appraisals +23 -33
- data/CHANGELOG.md +395 -352
- data/Gemfile +6 -5
- data/README.md +104 -7
- data/Rakefile +1 -1
- data/acts_as_list.gemspec +12 -13
- data/gemfiles/rails_4_2.gemfile +6 -7
- data/gemfiles/rails_5_0.gemfile +4 -6
- data/gemfiles/rails_5_1.gemfile +4 -6
- data/gemfiles/rails_5_2.gemfile +4 -6
- data/gemfiles/rails_6_0.gemfile +31 -0
- data/gemfiles/rails_6_1.gemfile +31 -0
- data/lib/acts_as_list/active_record/acts/list.rb +48 -49
- data/lib/acts_as_list/active_record/acts/position_column_method_definer.rb +1 -1
- data/lib/acts_as_list/active_record/acts/scope_method_definer.rb +8 -5
- data/lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb +1 -1
- data/lib/acts_as_list/version.rb +1 -1
- data/test/helper.rb +17 -10
- data/test/shared_list.rb +14 -4
- data/test/shared_list_sub.rb +1 -1
- data/test/test_list.rb +60 -57
- data/test/test_no_update_for_extra_classes.rb +5 -5
- data/test/test_no_update_for_scope_destruction.rb +2 -7
- data/test/test_no_update_for_subclasses.rb +3 -3
- data/test/test_scope_with_user_defined_foreign_key.rb +42 -0
- metadata +17 -15
- data/gemfiles/rails_3_2.gemfile +0 -34
- data/gemfiles/rails_4_1.gemfile +0 -34
@@ -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
|
-
|
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
|
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)
|
data/lib/acts_as_list/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -13,7 +13,7 @@ rescue Bundler::BundlerError => e
|
|
13
13
|
end
|
14
14
|
require "active_record"
|
15
15
|
require "minitest/autorun"
|
16
|
-
require "mocha/
|
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
|
data/test/shared_list.rb
CHANGED
@@ -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
|
-
|
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
|
data/test/shared_list_sub.rb
CHANGED
@@ -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.
|
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)
|
data/test/test_list.rb
CHANGED
@@ -11,7 +11,7 @@ def setup_db(position_options = {})
|
|
11
11
|
|
12
12
|
# AR caches columns options like defaults etc. Clear them!
|
13
13
|
ActiveRecord::Base.connection.create_table :mixins do |t|
|
14
|
-
t.column :pos, :integer, position_options unless position_options[:positive] && sqlite
|
14
|
+
t.column :pos, :integer, **position_options unless position_options[:positive] && sqlite
|
15
15
|
t.column :active, :boolean, default: true
|
16
16
|
t.column :parent_id, :integer
|
17
17
|
t.column :parent_type, :string
|
@@ -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
|
-
|
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
|
-
|
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
|
-
|
111
|
-
|
112
|
-
|
113
|
-
enum state: STATE_VALUES
|
100
|
+
class EnumArrayScopeListMixin < Mixin
|
101
|
+
STATE_VALUES = %w(active archived)
|
102
|
+
enum state: STATE_VALUES
|
114
103
|
|
115
|
-
|
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
|
-
|
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
|
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.
|
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).
|
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).
|
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
|
-
|
667
|
-
|
668
|
-
|
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
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
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
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
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).
|
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).
|
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).
|
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).
|
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).
|
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).
|
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
|
@@ -56,13 +56,13 @@ class NoUpdateForCollectionClassesTest < NoUpdateForCollectionClassesTestCase
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_update
|
59
|
-
@item_1.
|
59
|
+
@item_1.update position: 2
|
60
60
|
assert_equal 2, @item_1.reload.position
|
61
61
|
assert_equal 1, @item_2.reload.position
|
62
62
|
end
|
63
63
|
|
64
64
|
def test_no_update_for_single_class_instances
|
65
|
-
TodoItem.acts_as_list_no_update { @item_1.
|
65
|
+
TodoItem.acts_as_list_no_update { @item_1.update position: 2 }
|
66
66
|
|
67
67
|
assert_equal 2, @item_1.reload.position
|
68
68
|
assert_equal 2, @item_2.reload.position
|
@@ -124,8 +124,8 @@ class NoUpdateForCollectionClassesTest < NoUpdateForCollectionClassesTestCase
|
|
124
124
|
private
|
125
125
|
|
126
126
|
def update_records!
|
127
|
-
@item_1.
|
128
|
-
@attachment_1.
|
129
|
-
@list_1.
|
127
|
+
@item_1.update position: 2
|
128
|
+
@attachment_1.update position: 2
|
129
|
+
@list_1.update position: 2
|
130
130
|
end
|
131
131
|
end
|
@@ -53,13 +53,8 @@ class NoUpdateForScopeDestructionTestCase < Minitest::Test
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_no_update_children_when_parent_destroyed
|
56
|
-
|
57
|
-
|
58
|
-
DestructionTadaItem.any_instance.expects(:decrement_positions_on_lower_items).once
|
59
|
-
else
|
60
|
-
DestructionTodoItem.any_instance.expects(:decrement_positions_on_lower_items).never
|
61
|
-
DestructionTadaItem.any_instance.expects(:decrement_positions_on_lower_items).never
|
62
|
-
end
|
56
|
+
DestructionTodoItem.any_instance.expects(:decrement_positions_on_lower_items).never
|
57
|
+
DestructionTadaItem.any_instance.expects(:decrement_positions_on_lower_items).never
|
63
58
|
assert @list.destroy
|
64
59
|
end
|
65
60
|
|