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,131 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
-
5
- class TodoList < ActiveRecord::Base
6
- has_many :todo_items
7
- acts_as_list
8
- end
9
-
10
- class TodoItem < ActiveRecord::Base
11
- belongs_to :todo_list
12
- has_many :todo_item_attachments
13
- acts_as_list scope: :todo_list
14
- end
15
-
16
- class TodoItemAttachment < ActiveRecord::Base
17
- belongs_to :todo_item
18
- acts_as_list scope: :todo_item
19
- end
20
-
21
- class NoUpdateForCollectionClassesTestCase < Minitest::Test
22
- def setup
23
- ActiveRecord::Base.connection.create_table :todo_lists do |t|
24
- t.column :position, :integer
25
- end
26
-
27
- ActiveRecord::Base.connection.create_table :todo_items do |t|
28
- t.column :position, :integer
29
- t.column :todo_list_id, :integer
30
- end
31
-
32
- ActiveRecord::Base.connection.create_table :todo_item_attachments do |t|
33
- t.column :position, :integer
34
- t.column :todo_item_id, :integer
35
- end
36
-
37
- ActiveRecord::Base.connection.schema_cache.clear!
38
- [TodoList, TodoItem, TodoItemAttachment].each(&:reset_column_information)
39
- super
40
- end
41
-
42
- def teardown
43
- teardown_db
44
- super
45
- end
46
- end
47
-
48
- class NoUpdateForCollectionClassesTest < NoUpdateForCollectionClassesTestCase
49
- def setup
50
- super
51
- @list_1, @list_2 = (1..2).map { |counter| TodoList.create!(position: counter) }
52
-
53
- @item_1, @item_2 = (1..2).map { |counter| TodoItem.create!(position: counter, todo_list_id: @list_1.id) }
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)}
56
- end
57
-
58
- def test_update
59
- @item_1.update position: 2
60
- assert_equal 2, @item_1.reload.position
61
- assert_equal 1, @item_2.reload.position
62
- end
63
-
64
- def test_no_update_for_single_class_instances
65
- TodoItem.acts_as_list_no_update { @item_1.update position: 2 }
66
-
67
- assert_equal 2, @item_1.reload.position
68
- assert_equal 2, @item_2.reload.position
69
- end
70
-
71
- def test_no_update_for_different_class_instances
72
- TodoItem.acts_as_list_no_update([TodoItemAttachment]) { update_records! }
73
-
74
- assert_equal 2, @item_1.reload.position
75
- assert_equal 2, @item_2.reload.position
76
-
77
- assert_equal 2, @attachment_1.reload.position
78
- assert_equal 2, @attachment_2.reload.position
79
-
80
- assert_equal 2, @list_1.reload.position
81
- assert_equal 1, @list_2.reload.position
82
- end
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
-
108
- def test_raising_array_type_error
109
- exception = assert_raises ActiveRecord::Acts::List::NoUpdate::ArrayTypeError do
110
- TodoList.acts_as_list_no_update(nil)
111
- end
112
-
113
- assert_equal("The first argument must be an array", exception.message )
114
- end
115
-
116
- def test_non_disparity_classes_error
117
- exception = assert_raises ActiveRecord::Acts::List::NoUpdate::DisparityClassesError do
118
- TodoList.acts_as_list_no_update([Class])
119
- end
120
-
121
- assert_equal("The first argument should contain ActiveRecord or ApplicationRecord classes", exception.message )
122
- end
123
-
124
- private
125
-
126
- def update_records!
127
- @item_1.update position: 2
128
- @attachment_1.update position: 2
129
- @list_1.update position: 2
130
- end
131
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
-
5
- class DestructionTodoList < ActiveRecord::Base
6
- has_many :destruction_todo_items, dependent: :destroy
7
- has_many :destruction_tada_items, dependent: :destroy
8
- end
9
-
10
- class DestructionTodoItem < ActiveRecord::Base
11
- belongs_to :destruction_todo_list
12
- acts_as_list scope: :destruction_todo_list
13
- end
14
-
15
- class DestructionTadaItem < ActiveRecord::Base
16
- belongs_to :destruction_todo_list
17
- acts_as_list scope: [:destruction_todo_list_id, :enabled]
18
- end
19
-
20
- class NoUpdateForScopeDestructionTestCase < Minitest::Test
21
- def setup
22
- ActiveRecord::Base.connection.create_table :destruction_todo_lists do |t|
23
- end
24
-
25
- ActiveRecord::Base.connection.create_table :destruction_todo_items do |t|
26
- t.column :position, :integer
27
- t.column :destruction_todo_list_id, :integer
28
- end
29
-
30
- ActiveRecord::Base.connection.create_table :destruction_tada_items do |t|
31
- t.column :position, :integer
32
- t.column :destruction_todo_list_id, :integer
33
- t.column :enabled, :boolean
34
- end
35
-
36
- ActiveRecord::Base.connection.schema_cache.clear!
37
- [DestructionTodoList, DestructionTodoItem, DestructionTadaItem].each(&:reset_column_information)
38
- super
39
- end
40
-
41
- def teardown
42
- teardown_db
43
- super
44
- end
45
-
46
- class NoUpdateForScopeDestructionTest < NoUpdateForScopeDestructionTestCase
47
- def setup
48
- super
49
- @list = DestructionTodoList.create!
50
-
51
- @todo_item_1 = DestructionTodoItem.create! position: 1, destruction_todo_list_id: @list.id
52
- @tada_item_1 = DestructionTadaItem.create! position: 1, destruction_todo_list_id: @list.id, enabled: true
53
- end
54
-
55
- def test_no_update_children_when_parent_destroyed
56
- DestructionTodoItem.any_instance.expects(:decrement_positions_on_lower_items).never
57
- DestructionTadaItem.any_instance.expects(:decrement_positions_on_lower_items).never
58
- assert @list.destroy
59
- end
60
-
61
- def test_update_children_when_sibling_destroyed
62
- @todo_item_1.expects(:decrement_positions_on_lower_items).once
63
- @tada_item_1.expects(:decrement_positions_on_lower_items).once
64
- assert @todo_item_1.destroy
65
- assert @tada_item_1.destroy
66
- end
67
-
68
- end
69
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
-
5
- class MasterItem < ActiveRecord::Base
6
- acts_as_list
7
- end
8
-
9
- class SlaveItem < MasterItem; end
10
-
11
- class NoUpdateForSubclassesTestCase < Minitest::Test
12
- def setup
13
- ActiveRecord::Base.connection.create_table :master_items do |t|
14
- t.column :position, :integer
15
- t.column :type, :string
16
- end
17
-
18
- ActiveRecord::Base.connection.schema_cache.clear!
19
- [MasterItem, SlaveItem].each(&:reset_column_information)
20
- super
21
- end
22
-
23
- def teardown
24
- teardown_db
25
- super
26
- end
27
- end
28
-
29
- class NoUpdateForSubclassesTest < NoUpdateForSubclassesTestCase
30
- def setup
31
- super
32
- @item_1, @item_2 = (1..2).map do |counter|
33
- SlaveItem.create!(position: counter)
34
- end
35
- end
36
-
37
- def test_update
38
- @item_1.update position: 2
39
- assert_equal 2, @item_1.reload.position
40
- assert_equal 1, @item_2.reload.position
41
- end
42
-
43
- def test_no_update_for_subclass_instances_with_no_update_on_superclass
44
- MasterItem.acts_as_list_no_update { @item_1.update position: 2 }
45
-
46
- assert_equal 2, @item_1.reload.position
47
- assert_equal 2, @item_2.reload.position
48
- end
49
-
50
- def test_no_update_for_subclass_instances_with_no_update_on_subclass
51
- SlaveItem.acts_as_list_no_update { @item_1.update position: 2 }
52
-
53
- assert_equal 2, @item_1.reload.position
54
- assert_equal 2, @item_2.reload.position
55
- end
56
- end
@@ -1,42 +0,0 @@
1
- require 'helper'
2
-
3
- class Checklist < ActiveRecord::Base
4
- has_many :checklist_items, foreign_key: 'list_id', inverse_of: :checklist
5
- end
6
-
7
- class ChecklistItem < ActiveRecord::Base
8
- belongs_to :checklist, foreign_key: 'list_id', inverse_of: :checklist_items
9
- acts_as_list scope: :checklist
10
- end
11
-
12
- class ScopeWithUserDefinedForeignKeyTest < Minitest::Test
13
- def setup
14
- ActiveRecord::Base.connection.create_table :checklists do |t|
15
- end
16
-
17
- ActiveRecord::Base.connection.create_table :checklist_items do |t|
18
- t.column :list_id, :integer
19
- t.column :position, :integer
20
- end
21
-
22
- ActiveRecord::Base.connection.schema_cache.clear!
23
- [Checklist, ChecklistItem].each(&:reset_column_information)
24
- super
25
- end
26
-
27
- def teardown
28
- teardown_db
29
- super
30
- end
31
-
32
- def test_scope_with_user_defined_foreign_key
33
- checklist = Checklist.create
34
- checklist_item_1 = checklist.checklist_items.create
35
- checklist_item_2 = checklist.checklist_items.create
36
- checklist_item_3 = checklist.checklist_items.create
37
-
38
- assert_equal 1, checklist_item_1.position
39
- assert_equal 2, checklist_item_2.position
40
- assert_equal 3, checklist_item_3.position
41
- end
42
- end