acts_as_list 1.0.4 → 1.2.4

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -4
  3. data/README.md +17 -9
  4. data/Rakefile +0 -8
  5. data/lib/acts_as_list/active_record/acts/callback_definer.rb +2 -4
  6. data/lib/acts_as_list/active_record/acts/list.rb +33 -34
  7. data/lib/acts_as_list/active_record/acts/position_column_method_definer.rb +15 -6
  8. data/lib/acts_as_list/active_record/acts/scope_method_definer.rb +1 -2
  9. data/lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb +15 -15
  10. data/lib/acts_as_list/active_record/acts/with_connection.rb +25 -0
  11. data/lib/acts_as_list/version.rb +1 -1
  12. metadata +102 -61
  13. data/.github/FUNDING.yml +0 -3
  14. data/.gitignore +0 -12
  15. data/.travis.yml +0 -55
  16. data/Appraisals +0 -40
  17. data/Gemfile +0 -28
  18. data/acts_as_list.gemspec +0 -34
  19. data/gemfiles/rails_4_2.gemfile +0 -32
  20. data/gemfiles/rails_5_0.gemfile +0 -31
  21. data/gemfiles/rails_5_1.gemfile +0 -31
  22. data/gemfiles/rails_5_2.gemfile +0 -31
  23. data/gemfiles/rails_6_0.gemfile +0 -31
  24. data/gemfiles/rails_6_1.gemfile +0 -31
  25. data/test/database.yml +0 -16
  26. data/test/helper.rb +0 -69
  27. data/test/shared.rb +0 -12
  28. data/test/shared_array_scope_list.rb +0 -177
  29. data/test/shared_list.rb +0 -324
  30. data/test/shared_list_sub.rb +0 -188
  31. data/test/shared_no_addition.rb +0 -38
  32. data/test/shared_quoting.rb +0 -23
  33. data/test/shared_top_addition.rb +0 -110
  34. data/test/shared_zero_based.rb +0 -104
  35. data/test/test_default_scope_with_select.rb +0 -33
  36. data/test/test_joined_list.rb +0 -61
  37. data/test/test_list.rb +0 -1086
  38. data/test/test_no_update_for_extra_classes.rb +0 -131
  39. data/test/test_no_update_for_scope_destruction.rb +0 -69
  40. data/test/test_no_update_for_subclasses.rb +0 -56
  41. data/test/test_scope_with_user_defined_foreign_key.rb +0 -42
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Shared
4
- module NoAddition
5
- def setup
6
- (1..4).each { |counter| NoAdditionMixin.create! pos: counter, parent_id: 5 }
7
- end
8
-
9
- def test_insert
10
- new = NoAdditionMixin.create(parent_id: 20)
11
- assert_nil new.pos
12
- assert !new.in_list?
13
-
14
- new = NoAdditionMixin.create(parent_id: 20)
15
- assert_nil new.pos
16
- end
17
-
18
- def test_update_does_not_add_to_list
19
- new = NoAdditionMixin.create(parent_id: 20)
20
- new.update_attribute(:updated_at, Time.now) # force some change
21
- new.reload
22
-
23
- assert !new.in_list?
24
- end
25
-
26
- def test_update_scope_does_not_add_to_list
27
- new = NoAdditionMixin.create
28
-
29
- new.update_attribute(:parent_id, 20)
30
- new.reload
31
- assert !new.in_list?
32
-
33
- new.update_attribute(:parent_id, 5)
34
- new.reload
35
- assert !new.in_list?
36
- end
37
- end
38
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Shared
4
- module Quoting
5
-
6
- def setup
7
- 3.times { |counter| QuotedList.create! order: counter }
8
- end
9
-
10
- def test_create
11
- assert_equal QuotedList.in_list.size, 3
12
- end
13
-
14
- # This test execute raw queries involving table name
15
- def test_moving
16
- item = QuotedList.first
17
- item.higher_items
18
- item.lower_items
19
- item.send :bottom_item # Part of private api
20
- end
21
-
22
- end
23
- end
@@ -1,110 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Shared
4
- module TopAddition
5
- def setup
6
- (1..4).each { |counter| TopAdditionMixin.create! pos: counter, parent_id: 5 }
7
- end
8
-
9
- def test_setup_state
10
- # If we explicitly define a position (as above) then that position is what gets applied
11
- assert_equal [1, 2, 3, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
12
- end
13
-
14
- def test_reordering
15
- TopAdditionMixin.where(id: 2).first.move_lower
16
- assert_equal [1, 3, 2, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
17
-
18
- TopAdditionMixin.where(id: 2).first.move_higher
19
- assert_equal [1, 2, 3, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
20
-
21
- TopAdditionMixin.where(id: 1).first.move_to_bottom
22
- assert_equal [2, 3, 4, 1], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
23
-
24
- TopAdditionMixin.where(id: 1).first.move_to_top
25
- assert_equal [1, 2, 3, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
26
-
27
- TopAdditionMixin.where(id: 2).first.move_to_bottom
28
- assert_equal [1, 3, 4, 2], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
29
-
30
- TopAdditionMixin.where(id: 4).first.move_to_top
31
- assert_equal [4, 1, 3, 2], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
32
- end
33
-
34
- def test_injection
35
- item = TopAdditionMixin.new(parent_id: 1)
36
- assert_equal({ parent_id: 1 }, item.scope_condition)
37
- assert_equal "pos", item.position_column
38
- end
39
-
40
- def test_insert
41
- new = TopAdditionMixin.create(parent_id: 20)
42
- assert_equal 1, new.pos
43
- assert new.first?
44
- assert new.last?
45
-
46
- new = TopAdditionMixin.create(parent_id: 20)
47
- assert_equal 1, new.pos
48
- assert new.first?
49
- assert !new.last?
50
-
51
- new = TopAdditionMixin.acts_as_list_no_update { TopAdditionMixin.create(parent_id: 20) }
52
- assert_equal_or_nil $default_position, new.pos
53
- assert_equal $default_position.is_a?(Integer), new.first?
54
- assert !new.last?
55
-
56
- new = TopAdditionMixin.create(parent_id: 20)
57
- assert_equal 1, new.pos
58
- assert_equal $default_position.nil?, new.first?
59
- assert !new.last?
60
-
61
- new = TopAdditionMixin.create(parent_id: 0)
62
- assert_equal 1, new.pos
63
- assert new.first?
64
- assert new.last?
65
- end
66
-
67
- def test_insert_at
68
- new = TopAdditionMixin.create(parent_id: 20)
69
- assert_equal 1, new.pos
70
-
71
- new = TopAdditionMixin.create(parent_id: 20)
72
- assert_equal 1, new.pos
73
-
74
- new = TopAdditionMixin.create(parent_id: 20)
75
- assert_equal 1, new.pos
76
-
77
- new = TopAdditionMixin.acts_as_list_no_update { TopAdditionMixin.create(parent_id: 20) }
78
- assert_equal_or_nil $default_position, new.pos
79
-
80
- new4 = TopAdditionMixin.create(parent_id: 20)
81
- assert_equal 1, new4.pos
82
-
83
- new4.insert_at(3)
84
- assert_equal 3, new4.pos
85
- end
86
-
87
- def test_supplied_position
88
- new = TopAdditionMixin.create(parent_id: 20, pos: 3)
89
- assert_equal 3, new.pos
90
- end
91
-
92
- def test_delete_middle
93
- TopAdditionMixin.where(id: 2).first.destroy
94
-
95
- assert_equal [1, 3, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
96
-
97
- assert_equal 1, TopAdditionMixin.where(id: 1).first.pos
98
- assert_equal 2, TopAdditionMixin.where(id: 3).first.pos
99
- assert_equal 3, TopAdditionMixin.where(id: 4).first.pos
100
-
101
- TopAdditionMixin.acts_as_list_no_update { TopAdditionMixin.where(id: 3).first.destroy }
102
-
103
- assert_equal [1, 4], TopAdditionMixin.where(parent_id: 5).order('pos').map(&:id)
104
-
105
- assert_equal 1, TopAdditionMixin.where(id: 1).first.pos
106
- assert_equal 3, TopAdditionMixin.where(id: 4).first.pos
107
- end
108
-
109
- end
110
- end
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Shared
4
- module ZeroBased
5
- def setup
6
- (1..4).each { |counter| ZeroBasedMixin.create! pos: counter, parent_id: 5 }
7
- end
8
-
9
- def test_insert
10
- new = ZeroBasedMixin.create(parent_id: 20)
11
- assert_equal 0, new.pos
12
- assert new.first?
13
- assert new.last?
14
-
15
- new = ZeroBasedMixin.create(parent_id: 20)
16
- assert_equal 1, new.pos
17
- assert !new.first?
18
- assert new.last?
19
-
20
- new = ZeroBasedMixin.acts_as_list_no_update { ZeroBasedMixin.create(parent_id: 20) }
21
- assert_equal_or_nil $default_position, new.pos
22
- assert !new.first?
23
- assert !new.last?
24
-
25
- new = ZeroBasedMixin.create(parent_id: 20)
26
- assert_equal 2, new.pos
27
- assert !new.first?
28
- assert new.last?
29
-
30
- new = ZeroBasedMixin.create(parent_id: 0)
31
- assert_equal 0, new.pos
32
- assert new.first?
33
- assert new.last?
34
-
35
- new = ZeroBasedMixin.create(parent_id: 1, pos: -500)
36
- assert_equal 0, new.pos
37
- assert new.first?
38
- assert new.last?
39
- end
40
-
41
- def test_reordering
42
- assert_equal [1, 2, 3, 4], ZeroBasedMixin.where(parent_id: 5).order('pos').map(&:id)
43
-
44
- ListMixin.where(id: 2).first.move_lower
45
- assert_equal [1, 3, 2, 4], ZeroBasedMixin.where(parent_id: 5).order('pos').map(&:id)
46
-
47
- ListMixin.where(id: 2).first.move_higher
48
- assert_equal [1, 2, 3, 4], ZeroBasedMixin.where(parent_id: 5).order('pos').map(&:id)
49
-
50
- ListMixin.where(id: 1).first.move_to_bottom
51
- assert_equal [2, 3, 4, 1], ZeroBasedMixin.where(parent_id: 5).order('pos').map(&:id)
52
-
53
- ListMixin.where(id: 1).first.move_to_top
54
- assert_equal [1, 2, 3, 4], ZeroBasedMixin.where(parent_id: 5).order('pos').map(&:id)
55
-
56
- ListMixin.where(id: 2).first.move_to_bottom
57
- assert_equal [1, 3, 4, 2], ZeroBasedMixin.where(parent_id: 5).order('pos').map(&:id)
58
-
59
- ListMixin.where(id: 4).first.move_to_top
60
- assert_equal [4, 1, 3, 2], ZeroBasedMixin.where(parent_id: 5).order('pos').map(&:id)
61
- end
62
-
63
- def test_insert_at
64
- new = ZeroBasedMixin.create(parent_id: 20)
65
- assert_equal 0, new.pos
66
-
67
- new = ZeroBasedMixin.create(parent_id: 20)
68
- assert_equal 1, new.pos
69
-
70
- new = ZeroBasedMixin.create(parent_id: 20)
71
- assert_equal 2, new.pos
72
-
73
- new_noup = ZeroBasedMixin.acts_as_list_no_update { ZeroBasedMixin.create(parent_id: 20) }
74
- assert_equal_or_nil $default_position, new_noup.pos
75
-
76
- new4 = ZeroBasedMixin.create(parent_id: 20)
77
- assert_equal 3, new4.pos
78
-
79
- new4.insert_at(2)
80
- assert_equal 2, new4.pos
81
-
82
- new.reload
83
- assert_equal 3, new.pos
84
-
85
- new.insert_at(2)
86
- assert_equal 2, new.pos
87
-
88
- new4.reload
89
- assert_equal 3, new4.pos
90
-
91
- new5 = ListMixin.create(parent_id: 20)
92
- assert_equal 4, new5.pos
93
-
94
- new5.insert_at(1)
95
- assert_equal 1, new5.pos
96
-
97
- new4.reload
98
- assert_equal 4, new4.pos
99
-
100
- new_noup.reload
101
- assert_equal_or_nil $default_position, new_noup.pos
102
- end
103
- end
104
- end
@@ -1,33 +0,0 @@
1
- require 'helper'
2
-
3
- class Animal < ActiveRecord::Base
4
- acts_as_list
5
- default_scope -> { select(:name) }
6
- end
7
-
8
- class DefaultScopeWithSelectTest < Minitest::Test
9
- def setup
10
- ActiveRecord::Base.connection.create_table :animals do |t|
11
- t.column :position, :integer
12
- t.column :name, :string
13
- end
14
-
15
- ActiveRecord::Base.connection.schema_cache.clear!
16
- Animal.reset_column_information
17
- super
18
- end
19
-
20
- def teardown
21
- teardown_db
22
- super
23
- end
24
-
25
- def test_default_scope_with_select
26
- animal1 = Animal.create name: 'Fox'
27
- animal2 = Animal.create name: 'Panda'
28
- animal3 = Animal.create name: 'Wildebeast'
29
- assert_equal 1, animal1.position
30
- assert_equal 2, animal2.position
31
- assert_equal 3, animal3.position
32
- end
33
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
-
5
- class Section < ActiveRecord::Base
6
- has_many :items
7
- acts_as_list
8
-
9
- scope :visible, -> { where(visible: true) }
10
- end
11
-
12
- class Item < ActiveRecord::Base
13
- belongs_to :section
14
- acts_as_list scope: :section
15
-
16
- scope :visible, -> { where(visible: true).joins(:section).merge(Section.visible) }
17
- end
18
-
19
- class JoinedTestCase < Minitest::Test
20
- def setup
21
- ActiveRecord::Base.connection.create_table :sections do |t|
22
- t.column :position, :integer
23
- t.column :visible, :boolean, default: true
24
- end
25
-
26
- ActiveRecord::Base.connection.create_table :items do |t|
27
- t.column :position, :integer
28
- t.column :section_id, :integer
29
- t.column :visible, :boolean, default: true
30
- end
31
-
32
- ActiveRecord::Base.connection.schema_cache.clear!
33
- [Section, Item].each(&:reset_column_information)
34
- super
35
- end
36
-
37
- def teardown
38
- teardown_db
39
- super
40
- end
41
- end
42
-
43
- # joining the relation returned by `#higher_items` or `#lower_items` to another table
44
- # previously could result in ambiguous column names in the query
45
- class TestHigherLowerItems < JoinedTestCase
46
- def test_higher_items
47
- section = Section.create
48
- item1 = Item.create section: section
49
- item2 = Item.create section: section
50
- item3 = Item.create section: section
51
- assert_equal item3.higher_items.visible, [item2, item1]
52
- end
53
-
54
- def test_lower_items
55
- section = Section.create
56
- item1 = Item.create section: section
57
- item2 = Item.create section: section
58
- item3 = Item.create section: section
59
- assert_equal item1.lower_items.visible, [item2, item3]
60
- end
61
- end