acts_as_list 0.7.4 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +1 -0
- data/.travis.yml +15 -0
- data/Appraisals +13 -3
- data/CHANGELOG.md +117 -2
- data/Gemfile +2 -8
- data/README.md +12 -6
- data/gemfiles/rails_3_2.gemfile +2 -7
- data/gemfiles/rails_4_1.gemfile +2 -7
- data/gemfiles/rails_4_2.gemfile +2 -7
- data/gemfiles/rails_5_0.gemfile +18 -0
- data/lib/acts_as_list/active_record/acts/list.rb +172 -138
- data/lib/acts_as_list/version.rb +1 -1
- data/test/helper.rb +2 -2
- data/test/shared.rb +1 -0
- data/test/shared_list.rb +13 -1
- data/test/shared_list_sub.rb +45 -2
- data/test/shared_no_addition.rb +11 -0
- data/test/shared_quoting.rb +21 -0
- data/test/shared_top_addition.rb +18 -12
- data/test/test_joined_list.rb +64 -0
- data/test/test_list.rb +202 -27
- metadata +16 -11
data/test/shared_top_addition.rb
CHANGED
@@ -4,23 +4,26 @@ module Shared
|
|
4
4
|
(1..4).each { |counter| TopAdditionMixin.create! pos: counter, parent_id: 5 }
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def test_setup_state
|
8
|
+
# If we explicitly define a position (as above) then that position is what gets applied
|
9
|
+
assert_equal [1, 2, 3, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
|
10
|
+
end
|
9
11
|
|
12
|
+
def test_reordering
|
10
13
|
TopAdditionMixin.where(id: 2).first.move_lower
|
11
|
-
assert_equal [
|
14
|
+
assert_equal [1, 3, 2, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
|
12
15
|
|
13
16
|
TopAdditionMixin.where(id: 2).first.move_higher
|
14
|
-
assert_equal [
|
17
|
+
assert_equal [1, 2, 3, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
|
15
18
|
|
16
19
|
TopAdditionMixin.where(id: 1).first.move_to_bottom
|
17
|
-
assert_equal [
|
20
|
+
assert_equal [2, 3, 4, 1], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
|
18
21
|
|
19
22
|
TopAdditionMixin.where(id: 1).first.move_to_top
|
20
|
-
assert_equal [1,
|
23
|
+
assert_equal [1, 2, 3, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
|
21
24
|
|
22
25
|
TopAdditionMixin.where(id: 2).first.move_to_bottom
|
23
|
-
assert_equal [1,
|
26
|
+
assert_equal [1, 3, 4, 2], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
|
24
27
|
|
25
28
|
TopAdditionMixin.where(id: 4).first.move_to_top
|
26
29
|
assert_equal [4, 1, 3, 2], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
|
@@ -71,16 +74,19 @@ module Shared
|
|
71
74
|
assert_equal 3, new4.pos
|
72
75
|
end
|
73
76
|
|
74
|
-
def
|
75
|
-
|
77
|
+
def test_supplied_position
|
78
|
+
new = TopAdditionMixin.create(parent_id: 20, pos: 3)
|
79
|
+
assert_equal 3, new.pos
|
80
|
+
end
|
76
81
|
|
82
|
+
def test_delete_middle
|
77
83
|
TopAdditionMixin.where(id: 2).first.destroy
|
78
84
|
|
79
|
-
assert_equal [
|
85
|
+
assert_equal [1, 3, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
|
80
86
|
|
81
|
-
assert_equal
|
87
|
+
assert_equal 1, TopAdditionMixin.where(id: 1).first.pos
|
82
88
|
assert_equal 2, TopAdditionMixin.where(id: 3).first.pos
|
83
|
-
assert_equal
|
89
|
+
assert_equal 3, TopAdditionMixin.where(id: 4).first.pos
|
84
90
|
end
|
85
91
|
|
86
92
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
4
|
+
ActiveRecord::Schema.verbose = false
|
5
|
+
|
6
|
+
class Section < ActiveRecord::Base
|
7
|
+
has_many :items
|
8
|
+
acts_as_list
|
9
|
+
|
10
|
+
scope :visible, -> { where(visible: true) }
|
11
|
+
end
|
12
|
+
|
13
|
+
class Item < ActiveRecord::Base
|
14
|
+
belongs_to :section
|
15
|
+
acts_as_list scope: :section
|
16
|
+
|
17
|
+
scope :visible, -> { where(visible: true).joins(:section).merge(Section.visible) }
|
18
|
+
end
|
19
|
+
|
20
|
+
class JoinedTestCase < Minitest::Test
|
21
|
+
def setup
|
22
|
+
ActiveRecord::Base.connection.create_table :sections do |t|
|
23
|
+
t.column :position, :integer
|
24
|
+
t.column :visible, :boolean, default: true
|
25
|
+
end
|
26
|
+
|
27
|
+
ActiveRecord::Base.connection.create_table :items do |t|
|
28
|
+
t.column :position, :integer
|
29
|
+
t.column :section_id, :integer
|
30
|
+
t.column :visible, :boolean, default: true
|
31
|
+
end
|
32
|
+
|
33
|
+
ActiveRecord::Base.connection.schema_cache.clear!
|
34
|
+
[Section, Item].each(&:reset_column_information)
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
40
|
+
ActiveRecord::Base.connection.drop_table(table)
|
41
|
+
end
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# joining the relation returned by `#higher_items` or `#lower_items` to another table
|
47
|
+
# previously could result in ambiguous column names in the query
|
48
|
+
class TestHigherLowerItems < JoinedTestCase
|
49
|
+
def test_higher_items
|
50
|
+
section = Section.create
|
51
|
+
item1 = Item.create section: section
|
52
|
+
item2 = Item.create section: section
|
53
|
+
item3 = Item.create section: section
|
54
|
+
assert_equal item3.higher_items.visible, [item2, item1]
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_lower_items
|
58
|
+
section = Section.create
|
59
|
+
item1 = Item.create section: section
|
60
|
+
item2 = Item.create section: section
|
61
|
+
item3 = Item.create section: section
|
62
|
+
assert_equal item1.lower_items.visible, [item2, item3]
|
63
|
+
end
|
64
|
+
end
|
data/test/test_list.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# NOTE: following now done in helper.rb (better Readability)
|
2
2
|
require 'helper'
|
3
3
|
|
4
|
-
ActiveRecord::Base.establish_connection(
|
4
|
+
ActiveRecord::Base.establish_connection(
|
5
|
+
adapter: "sqlite3",
|
6
|
+
database: 'file:memdb1?mode=memory&cache=shared'
|
7
|
+
)
|
5
8
|
ActiveRecord::Schema.verbose = false
|
6
9
|
|
7
10
|
def setup_db(position_options = {})
|
@@ -16,9 +19,14 @@ def setup_db(position_options = {})
|
|
16
19
|
t.column :state, :integer
|
17
20
|
end
|
18
21
|
|
22
|
+
# This table is used to test table names and column names quoting
|
23
|
+
ActiveRecord::Base.connection.create_table 'table-name' do |t|
|
24
|
+
t.column :order, :integer
|
25
|
+
end
|
26
|
+
|
19
27
|
mixins = [ Mixin, ListMixin, ListMixinSub1, ListMixinSub2, ListWithStringScopeMixin,
|
20
28
|
ArrayScopeListMixin, ZeroBasedMixin, DefaultScopedMixin,
|
21
|
-
DefaultScopedWhereMixin, TopAdditionMixin, NoAdditionMixin ]
|
29
|
+
DefaultScopedWhereMixin, TopAdditionMixin, NoAdditionMixin, QuotedList ]
|
22
30
|
|
23
31
|
mixins << EnumArrayScopeListMixin if rails_4
|
24
32
|
|
@@ -42,7 +50,13 @@ def rails_4
|
|
42
50
|
end
|
43
51
|
|
44
52
|
def teardown_db
|
45
|
-
ActiveRecord::
|
53
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
54
|
+
tables = ActiveRecord::Base.connection.data_sources
|
55
|
+
else
|
56
|
+
tables = ActiveRecord::Base.connection.tables
|
57
|
+
end
|
58
|
+
|
59
|
+
tables.each do |table|
|
46
60
|
ActiveRecord::Base.connection.drop_table(table)
|
47
61
|
end
|
48
62
|
end
|
@@ -149,6 +163,18 @@ end
|
|
149
163
|
class TheBaseSubclass < TheBaseClass
|
150
164
|
end
|
151
165
|
|
166
|
+
class DBConfigTest < Minitest::Test
|
167
|
+
def test_db_config
|
168
|
+
# make sure sqlite3 accepts multi threaded access
|
169
|
+
assert_equal "file:memdb1?mode=memory&cache=shared", ActiveRecord::Base.connection.pool.spec.config[:database]
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
class QuotedList < ActiveRecord::Base
|
174
|
+
self.table_name = 'table-name'
|
175
|
+
acts_as_list column: :order
|
176
|
+
end
|
177
|
+
|
152
178
|
class ActsAsListTestCase < Minitest::Test
|
153
179
|
# No default test required as this class is abstract.
|
154
180
|
# Need for test/unit.
|
@@ -184,6 +210,37 @@ class ListTest < ActsAsListTestCase
|
|
184
210
|
setup_db
|
185
211
|
super
|
186
212
|
end
|
213
|
+
|
214
|
+
def test_insert_race_condition
|
215
|
+
# the bigger n is the more likely we will have a race condition
|
216
|
+
n = 1000
|
217
|
+
(1..n).each do |counter|
|
218
|
+
node = ListMixin.new parent_id: 1
|
219
|
+
node.pos = counter
|
220
|
+
node.save!
|
221
|
+
end
|
222
|
+
|
223
|
+
wait_for_it = true
|
224
|
+
threads = []
|
225
|
+
4.times do |i|
|
226
|
+
threads << Thread.new do
|
227
|
+
true while wait_for_it
|
228
|
+
ActiveRecord::Base.connection_pool.with_connection do |c|
|
229
|
+
n.times do
|
230
|
+
begin
|
231
|
+
ListMixin.where(parent_id: 1).order('pos').last.insert_at(1)
|
232
|
+
rescue Exception
|
233
|
+
# ignore SQLite3::SQLException due to table locking
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
wait_for_it = false
|
240
|
+
threads.each(&:join)
|
241
|
+
|
242
|
+
assert_equal (1..n).to_a, ListMixin.where(parent_id: 1).order('pos').map(&:pos)
|
243
|
+
end
|
187
244
|
end
|
188
245
|
|
189
246
|
class ListWithCallbackTest < ActsAsListTestCase
|
@@ -243,6 +300,15 @@ class ArrayScopeListTestWithDefault < ActsAsListTestCase
|
|
243
300
|
end
|
244
301
|
end
|
245
302
|
|
303
|
+
class QuotingTestList < ActsAsListTestCase
|
304
|
+
include Shared::Quoting
|
305
|
+
|
306
|
+
def setup
|
307
|
+
setup_db_with_default
|
308
|
+
super
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
246
312
|
class DefaultScopedTest < ActsAsListTestCase
|
247
313
|
def setup
|
248
314
|
setup_db
|
@@ -512,19 +578,19 @@ class MultipleListsTest < ActsAsListTestCase
|
|
512
578
|
end
|
513
579
|
|
514
580
|
def test_check_scope_order
|
515
|
-
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 1).order(
|
516
|
-
assert_equal [5, 6, 7, 8], ListMixin.where(:parent_id => 2).order(
|
581
|
+
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 1).order('pos').map(&:id)
|
582
|
+
assert_equal [5, 6, 7, 8], ListMixin.where(:parent_id => 2).order('pos').map(&:id)
|
517
583
|
ListMixin.find(4).update_attributes(:parent_id => 2, :pos => 2)
|
518
|
-
assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order(
|
519
|
-
assert_equal [5, 4, 6, 7, 8], ListMixin.where(:parent_id => 2).order(
|
584
|
+
assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order('pos').map(&:id)
|
585
|
+
assert_equal [5, 4, 6, 7, 8], ListMixin.where(:parent_id => 2).order('pos').map(&:id)
|
520
586
|
end
|
521
587
|
|
522
588
|
def test_check_scope_position
|
523
589
|
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 1).map(&:pos)
|
524
590
|
assert_equal [1, 2, 3, 4], ListMixin.where(:parent_id => 2).map(&:pos)
|
525
591
|
ListMixin.find(4).update_attributes(:parent_id => 2, :pos => 2)
|
526
|
-
assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order(
|
527
|
-
assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 2).order(
|
592
|
+
assert_equal [1, 2, 3], ListMixin.where(:parent_id => 1).order('pos').map(&:pos)
|
593
|
+
assert_equal [1, 2, 3, 4, 5], ListMixin.where(:parent_id => 2).order('pos').map(&:pos)
|
528
594
|
end
|
529
595
|
end
|
530
596
|
|
@@ -556,50 +622,159 @@ class MultipleListsArrayScopeTest < ActsAsListTestCase
|
|
556
622
|
end
|
557
623
|
|
558
624
|
def test_order_after_all_scope_properties_are_changed
|
559
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
560
|
-
assert_equal [5, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order(
|
625
|
+
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
|
626
|
+
assert_equal [5, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order('pos').map(&:id)
|
561
627
|
ArrayScopeListMixin.find(2).update_attributes(:parent_id => 2, :pos => 2,:parent_type => 'something')
|
562
|
-
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order(
|
563
|
-
assert_equal [5, 2, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2,:parent_type => 'something').order(
|
628
|
+
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
|
629
|
+
assert_equal [5, 2, 6, 7, 8], ArrayScopeListMixin.where(:parent_id => 2,:parent_type => 'something').order('pos').map(&:id)
|
564
630
|
end
|
565
631
|
|
566
632
|
def test_position_after_all_scope_properties_are_changed
|
567
633
|
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
|
568
634
|
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').map(&:pos)
|
569
635
|
ArrayScopeListMixin.find(4).update_attributes(:parent_id => 2, :pos => 2, :parent_type => 'something')
|
570
|
-
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
571
|
-
assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order(
|
636
|
+
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
|
637
|
+
assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 2, :parent_type => 'something').order('pos').map(&:pos)
|
572
638
|
end
|
573
639
|
|
574
640
|
def test_order_after_one_scope_property_is_changed
|
575
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
576
|
-
assert_equal [9, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order(
|
641
|
+
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
|
642
|
+
assert_equal [9, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order('pos').map(&:id)
|
577
643
|
ArrayScopeListMixin.find(2).update_attributes(:parent_id => 3, :pos => 2)
|
578
|
-
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order(
|
579
|
-
assert_equal [9, 2, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3,:parent_type => 'anything').order(
|
644
|
+
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
|
645
|
+
assert_equal [9, 2, 10, 11, 12], ArrayScopeListMixin.where(:parent_id => 3,:parent_type => 'anything').order('pos').map(&:id)
|
580
646
|
end
|
581
647
|
|
582
648
|
def test_position_after_one_scope_property_is_changed
|
583
649
|
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
|
584
650
|
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').map(&:pos)
|
585
651
|
ArrayScopeListMixin.find(4).update_attributes(:parent_id => 3, :pos => 2)
|
586
|
-
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
587
|
-
assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order(
|
652
|
+
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
|
653
|
+
assert_equal [1, 2, 3, 4, 5], ArrayScopeListMixin.where(:parent_id => 3, :parent_type => 'anything').order('pos').map(&:pos)
|
588
654
|
end
|
589
655
|
|
590
656
|
def test_order_after_moving_to_empty_list
|
591
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
592
|
-
assert_equal [], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order(
|
657
|
+
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:id)
|
658
|
+
assert_equal [], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order('pos').map(&:id)
|
593
659
|
ArrayScopeListMixin.find(2).update_attributes(:parent_id => 4, :pos => 1)
|
594
|
-
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order(
|
595
|
-
assert_equal [2], ArrayScopeListMixin.where(:parent_id => 4,:parent_type => 'anything').order(
|
660
|
+
assert_equal [1, 3, 4], ArrayScopeListMixin.where(:parent_id => 1,:parent_type => 'anything').order('pos').map(&:id)
|
661
|
+
assert_equal [2], ArrayScopeListMixin.where(:parent_id => 4,:parent_type => 'anything').order('pos').map(&:id)
|
596
662
|
end
|
597
663
|
|
598
664
|
def test_position_after_moving_to_empty_list
|
599
665
|
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').map(&:pos)
|
600
666
|
assert_equal [], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').map(&:pos)
|
601
667
|
ArrayScopeListMixin.find(2).update_attributes(:parent_id => 4, :pos => 1)
|
602
|
-
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order(
|
603
|
-
assert_equal [1], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order(
|
668
|
+
assert_equal [1, 2, 3], ArrayScopeListMixin.where(:parent_id => 1, :parent_type => 'anything').order('pos').map(&:pos)
|
669
|
+
assert_equal [1], ArrayScopeListMixin.where(:parent_id => 4, :parent_type => 'anything').order('pos').map(&:pos)
|
604
670
|
end
|
605
671
|
end
|
672
|
+
|
673
|
+
class TouchTest < ActsAsListTestCase
|
674
|
+
def setup
|
675
|
+
setup_db
|
676
|
+
4.times { ListMixin.create! updated_at: yesterday }
|
677
|
+
end
|
678
|
+
|
679
|
+
def now
|
680
|
+
Time.now.utc
|
681
|
+
end
|
682
|
+
|
683
|
+
def yesterday
|
684
|
+
1.day.ago
|
685
|
+
end
|
686
|
+
|
687
|
+
def updated_ats
|
688
|
+
ListMixin.pluck(:updated_at)
|
689
|
+
end
|
690
|
+
|
691
|
+
def test_moving_item_lower_touches_self_and_lower_item
|
692
|
+
ListMixin.first.move_lower
|
693
|
+
updated_ats[0..1].each do |updated_at|
|
694
|
+
assert_in_delta updated_at, now, 1.second
|
695
|
+
end
|
696
|
+
updated_ats[2..3].each do |updated_at|
|
697
|
+
assert_in_delta updated_at, yesterday, 1.second
|
698
|
+
end
|
699
|
+
end
|
700
|
+
|
701
|
+
def test_moving_item_higher_touches_self_and_higher_item
|
702
|
+
ListMixin.all.second.move_higher
|
703
|
+
updated_ats[0..1].each do |updated_at|
|
704
|
+
assert_in_delta updated_at, now, 1.second
|
705
|
+
end
|
706
|
+
updated_ats[2..3].each do |updated_at|
|
707
|
+
assert_in_delta updated_at, yesterday, 1.second
|
708
|
+
end
|
709
|
+
end
|
710
|
+
|
711
|
+
def test_moving_item_to_bottom_touches_all_other_items
|
712
|
+
ListMixin.first.move_to_bottom
|
713
|
+
updated_ats.each do |updated_at|
|
714
|
+
assert_in_delta updated_at, now, 1.second
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
718
|
+
def test_moving_item_to_top_touches_all_other_items
|
719
|
+
ListMixin.last.move_to_top
|
720
|
+
updated_ats.each do |updated_at|
|
721
|
+
assert_in_delta updated_at, now, 1.second
|
722
|
+
end
|
723
|
+
end
|
724
|
+
|
725
|
+
def test_removing_item_touches_all_lower_items
|
726
|
+
ListMixin.all.third.remove_from_list
|
727
|
+
updated_ats[0..1].each do |updated_at|
|
728
|
+
assert_in_delta updated_at, yesterday, 1.second
|
729
|
+
end
|
730
|
+
updated_ats[2..2].each do |updated_at|
|
731
|
+
assert_in_delta updated_at, now, 1.second
|
732
|
+
end
|
733
|
+
end
|
734
|
+
end
|
735
|
+
|
736
|
+
class ActsAsListTopTest < ActsAsListTestCase
|
737
|
+
def setup
|
738
|
+
setup_db
|
739
|
+
end
|
740
|
+
|
741
|
+
def test_acts_as_list_top
|
742
|
+
assert_equal 1, TheBaseSubclass.new.acts_as_list_top
|
743
|
+
assert_equal 0, ZeroBasedMixin.new.acts_as_list_top
|
744
|
+
end
|
745
|
+
|
746
|
+
def test_class_acts_as_list_top
|
747
|
+
assert_equal 1, TheBaseSubclass.acts_as_list_top
|
748
|
+
assert_equal 0, ZeroBasedMixin.acts_as_list_top
|
749
|
+
end
|
750
|
+
end
|
751
|
+
|
752
|
+
class NilPositionTest < ActsAsListTestCase
|
753
|
+
def setup
|
754
|
+
setup_db
|
755
|
+
end
|
756
|
+
|
757
|
+
def test_nil_position_ordering
|
758
|
+
new1 = DefaultScopedMixin.create pos: nil
|
759
|
+
new2 = DefaultScopedMixin.create pos: nil
|
760
|
+
new3 = DefaultScopedMixin.create pos: nil
|
761
|
+
DefaultScopedMixin.update_all(pos: nil)
|
762
|
+
|
763
|
+
assert_equal [nil, nil, nil], DefaultScopedMixin.all.map(&:pos)
|
764
|
+
|
765
|
+
new1.reload.pos = 1
|
766
|
+
new1.save
|
767
|
+
|
768
|
+
new3.reload.pos = 1
|
769
|
+
new3.save
|
770
|
+
|
771
|
+
assert_equal [nil, 1, 2], DefaultScopedMixin.all.map(&:pos)
|
772
|
+
assert_equal [2, 3, 1], DefaultScopedMixin.all.map(&:id)
|
773
|
+
|
774
|
+
new2.reload.pos = 1
|
775
|
+
new2.save
|
776
|
+
|
777
|
+
assert_equal [1, 2, 3], DefaultScopedMixin.all.map(&:pos)
|
778
|
+
assert_equal [2, 3, 1], DefaultScopedMixin.all.map(&:id)
|
779
|
+
end
|
780
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
@@ -10,34 +10,34 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-09-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '3.0'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: bundler
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: 1.0.0
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 1.0.0
|
43
43
|
description: This "acts_as" extension provides the capabilities for sorting and reordering
|
@@ -49,9 +49,9 @@ executables: []
|
|
49
49
|
extensions: []
|
50
50
|
extra_rdoc_files: []
|
51
51
|
files:
|
52
|
-
- .gemtest
|
53
|
-
- .gitignore
|
54
|
-
- .travis.yml
|
52
|
+
- ".gemtest"
|
53
|
+
- ".gitignore"
|
54
|
+
- ".travis.yml"
|
55
55
|
- Appraisals
|
56
56
|
- CHANGELOG.md
|
57
57
|
- Gemfile
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- gemfiles/rails_3_2.gemfile
|
63
63
|
- gemfiles/rails_4_1.gemfile
|
64
64
|
- gemfiles/rails_4_2.gemfile
|
65
|
+
- gemfiles/rails_5_0.gemfile
|
65
66
|
- init.rb
|
66
67
|
- lib/acts_as_list.rb
|
67
68
|
- lib/acts_as_list/active_record/acts/list.rb
|
@@ -72,8 +73,10 @@ files:
|
|
72
73
|
- test/shared_list.rb
|
73
74
|
- test/shared_list_sub.rb
|
74
75
|
- test/shared_no_addition.rb
|
76
|
+
- test/shared_quoting.rb
|
75
77
|
- test/shared_top_addition.rb
|
76
78
|
- test/shared_zero_based.rb
|
79
|
+
- test/test_joined_list.rb
|
77
80
|
- test/test_list.rb
|
78
81
|
homepage: http://github.com/swanandp/acts_as_list
|
79
82
|
licenses:
|
@@ -85,12 +88,12 @@ require_paths:
|
|
85
88
|
- lib
|
86
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
90
|
requirements:
|
88
|
-
- -
|
91
|
+
- - ">="
|
89
92
|
- !ruby/object:Gem::Version
|
90
93
|
version: 1.9.2
|
91
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
95
|
requirements:
|
93
|
-
- -
|
96
|
+
- - ">="
|
94
97
|
- !ruby/object:Gem::Version
|
95
98
|
version: '0'
|
96
99
|
requirements: []
|
@@ -107,6 +110,8 @@ test_files:
|
|
107
110
|
- test/shared_list.rb
|
108
111
|
- test/shared_list_sub.rb
|
109
112
|
- test/shared_no_addition.rb
|
113
|
+
- test/shared_quoting.rb
|
110
114
|
- test/shared_top_addition.rb
|
111
115
|
- test/shared_zero_based.rb
|
116
|
+
- test/test_joined_list.rb
|
112
117
|
- test/test_list.rb
|