acts_as_list 0.7.4 → 1.1.0

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 (52) hide show
  1. checksums.yaml +5 -13
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/dependabot.yml +6 -0
  4. data/.github/workflows/ci.yml +123 -0
  5. data/.gitignore +1 -0
  6. data/.travis.yml +50 -12
  7. data/Appraisals +39 -6
  8. data/CHANGELOG.md +565 -148
  9. data/Gemfile +19 -14
  10. data/README.md +206 -19
  11. data/Rakefile +4 -4
  12. data/acts_as_list.gemspec +16 -11
  13. data/gemfiles/rails_4_2.gemfile +18 -9
  14. data/gemfiles/rails_5_0.gemfile +31 -0
  15. data/gemfiles/rails_5_1.gemfile +31 -0
  16. data/gemfiles/rails_5_2.gemfile +31 -0
  17. data/gemfiles/rails_6_0.gemfile +31 -0
  18. data/gemfiles/rails_6_1.gemfile +31 -0
  19. data/gemfiles/rails_7_0.gemfile +31 -0
  20. data/init.rb +2 -0
  21. data/lib/acts_as_list/active_record/acts/active_record.rb +5 -0
  22. data/lib/acts_as_list/active_record/acts/add_new_at_method_definer.rb +11 -0
  23. data/lib/acts_as_list/active_record/acts/aux_method_definer.rb +11 -0
  24. data/lib/acts_as_list/active_record/acts/callback_definer.rb +19 -0
  25. data/lib/acts_as_list/active_record/acts/list.rb +299 -306
  26. data/lib/acts_as_list/active_record/acts/no_update.rb +125 -0
  27. data/lib/acts_as_list/active_record/acts/position_column_method_definer.rb +101 -0
  28. data/lib/acts_as_list/active_record/acts/scope_method_definer.rb +77 -0
  29. data/lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb +28 -0
  30. data/lib/acts_as_list/active_record/acts/top_of_list_method_definer.rb +15 -0
  31. data/lib/acts_as_list/version.rb +3 -1
  32. data/lib/acts_as_list.rb +11 -14
  33. data/test/database.yml +18 -0
  34. data/test/helper.rb +50 -2
  35. data/test/shared.rb +3 -0
  36. data/test/shared_array_scope_list.rb +21 -4
  37. data/test/shared_list.rb +86 -12
  38. data/test/shared_list_sub.rb +63 -2
  39. data/test/shared_no_addition.rb +50 -2
  40. data/test/shared_quoting.rb +23 -0
  41. data/test/shared_top_addition.rb +36 -13
  42. data/test/shared_zero_based.rb +13 -0
  43. data/test/test_default_scope_with_select.rb +33 -0
  44. data/test/test_joined_list.rb +61 -0
  45. data/test/test_list.rb +601 -84
  46. data/test/test_no_update_for_extra_classes.rb +131 -0
  47. data/test/test_no_update_for_scope_destruction.rb +69 -0
  48. data/test/test_no_update_for_subclasses.rb +56 -0
  49. data/test/test_scope_with_user_defined_foreign_key.rb +42 -0
  50. metadata +56 -22
  51. data/gemfiles/rails_3_2.gemfile +0 -24
  52. data/gemfiles/rails_4_1.gemfile +0 -24
@@ -0,0 +1,131 @@
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
@@ -0,0 +1,69 @@
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
@@ -0,0 +1,56 @@
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
@@ -0,0 +1,42 @@
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
metadata CHANGED
@@ -1,43 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - David Heinemeier Hansson
8
7
  - Swanand Pagnis
9
- - Quinn Chaffee
8
+ - Brendon Muir
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2016-04-15 00:00:00.000000000 Z
12
+ date: 2023-01-31 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
16
  requirement: !ruby/object:Gem::Requirement
18
17
  requirements:
19
- - - ! '>='
18
+ - - ">="
20
19
  - !ruby/object:Gem::Version
21
- version: '3.0'
20
+ version: '4.2'
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
24
  requirements:
26
- - - ! '>='
25
+ - - ">="
27
26
  - !ruby/object:Gem::Version
28
- version: '3.0'
27
+ version: '4.2'
29
28
  - !ruby/object:Gem::Dependency
30
29
  name: bundler
31
30
  requirement: !ruby/object:Gem::Requirement
32
31
  requirements:
33
- - - ! '>='
32
+ - - ">="
34
33
  - !ruby/object:Gem::Version
35
34
  version: 1.0.0
36
35
  type: :development
37
36
  prerelease: false
38
37
  version_requirements: !ruby/object:Gem::Requirement
39
38
  requirements:
40
- - - ! '>='
39
+ - - ">="
41
40
  - !ruby/object:Gem::Version
42
41
  version: 1.0.0
43
42
  description: This "acts_as" extension provides the capabilities for sorting and reordering
@@ -45,13 +44,17 @@ description: This "acts_as" extension provides the capabilities for sorting and
45
44
  "position" column defined as an integer on the mapped database table.
46
45
  email:
47
46
  - swanand.pagnis@gmail.com
47
+ - brendon@spikeatschool.co.nz
48
48
  executables: []
49
49
  extensions: []
50
50
  extra_rdoc_files: []
51
51
  files:
52
- - .gemtest
53
- - .gitignore
54
- - .travis.yml
52
+ - ".gemtest"
53
+ - ".github/FUNDING.yml"
54
+ - ".github/dependabot.yml"
55
+ - ".github/workflows/ci.yml"
56
+ - ".gitignore"
57
+ - ".travis.yml"
55
58
  - Appraisals
56
59
  - CHANGELOG.md
57
60
  - Gemfile
@@ -59,54 +62,85 @@ files:
59
62
  - README.md
60
63
  - Rakefile
61
64
  - acts_as_list.gemspec
62
- - gemfiles/rails_3_2.gemfile
63
- - gemfiles/rails_4_1.gemfile
64
65
  - gemfiles/rails_4_2.gemfile
66
+ - gemfiles/rails_5_0.gemfile
67
+ - gemfiles/rails_5_1.gemfile
68
+ - gemfiles/rails_5_2.gemfile
69
+ - gemfiles/rails_6_0.gemfile
70
+ - gemfiles/rails_6_1.gemfile
71
+ - gemfiles/rails_7_0.gemfile
65
72
  - init.rb
66
73
  - lib/acts_as_list.rb
74
+ - lib/acts_as_list/active_record/acts/active_record.rb
75
+ - lib/acts_as_list/active_record/acts/add_new_at_method_definer.rb
76
+ - lib/acts_as_list/active_record/acts/aux_method_definer.rb
77
+ - lib/acts_as_list/active_record/acts/callback_definer.rb
67
78
  - lib/acts_as_list/active_record/acts/list.rb
79
+ - lib/acts_as_list/active_record/acts/no_update.rb
80
+ - lib/acts_as_list/active_record/acts/position_column_method_definer.rb
81
+ - lib/acts_as_list/active_record/acts/scope_method_definer.rb
82
+ - lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
83
+ - lib/acts_as_list/active_record/acts/top_of_list_method_definer.rb
68
84
  - lib/acts_as_list/version.rb
85
+ - test/database.yml
69
86
  - test/helper.rb
70
87
  - test/shared.rb
71
88
  - test/shared_array_scope_list.rb
72
89
  - test/shared_list.rb
73
90
  - test/shared_list_sub.rb
74
91
  - test/shared_no_addition.rb
92
+ - test/shared_quoting.rb
75
93
  - test/shared_top_addition.rb
76
94
  - test/shared_zero_based.rb
95
+ - test/test_default_scope_with_select.rb
96
+ - test/test_joined_list.rb
77
97
  - test/test_list.rb
78
- homepage: http://github.com/swanandp/acts_as_list
98
+ - test/test_no_update_for_extra_classes.rb
99
+ - test/test_no_update_for_scope_destruction.rb
100
+ - test/test_no_update_for_subclasses.rb
101
+ - test/test_scope_with_user_defined_foreign_key.rb
102
+ homepage: http://github.com/brendon/acts_as_list
79
103
  licenses:
80
104
  - MIT
81
- metadata: {}
105
+ metadata:
106
+ changelog_uri: https://github.com/brendon/acts_as_list/blob/master/CHANGELOG.md
107
+ source_code_uri: https://github.com/brendon/acts_as_list
108
+ bug_tracker_uri: https://github.com/brendon/acts_as_list/issues
82
109
  post_install_message:
83
110
  rdoc_options: []
84
111
  require_paths:
85
112
  - lib
86
113
  required_ruby_version: !ruby/object:Gem::Requirement
87
114
  requirements:
88
- - - ! '>='
115
+ - - ">="
89
116
  - !ruby/object:Gem::Version
90
- version: 1.9.2
117
+ version: 2.4.7
91
118
  required_rubygems_version: !ruby/object:Gem::Requirement
92
119
  requirements:
93
- - - ! '>='
120
+ - - ">="
94
121
  - !ruby/object:Gem::Version
95
122
  version: '0'
96
123
  requirements: []
97
- rubyforge_project: acts_as_list
98
- rubygems_version: 2.4.5
124
+ rubygems_version: 3.0.3.1
99
125
  signing_key:
100
126
  specification_version: 4
101
127
  summary: A gem adding sorting, reordering capabilities to an active_record model,
102
128
  allowing it to act as a list
103
129
  test_files:
130
+ - test/database.yml
104
131
  - test/helper.rb
105
132
  - test/shared.rb
106
133
  - test/shared_array_scope_list.rb
107
134
  - test/shared_list.rb
108
135
  - test/shared_list_sub.rb
109
136
  - test/shared_no_addition.rb
137
+ - test/shared_quoting.rb
110
138
  - test/shared_top_addition.rb
111
139
  - test/shared_zero_based.rb
140
+ - test/test_default_scope_with_select.rb
141
+ - test/test_joined_list.rb
112
142
  - test/test_list.rb
143
+ - test/test_no_update_for_extra_classes.rb
144
+ - test/test_no_update_for_scope_destruction.rb
145
+ - test/test_no_update_for_subclasses.rb
146
+ - test/test_scope_with_user_defined_foreign_key.rb
@@ -1,24 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "sqlite3", :platforms => [:ruby]
6
- gem "activerecord-jdbcsqlite3-adapter", :platforms => [:jruby]
7
- gem "rake"
8
- gem "appraisal"
9
- gem "github_changelog_generator", "1.9.0"
10
- gem "activerecord", "~> 3.2.21"
11
-
12
- group :test do
13
- gem "minitest", "~> 5.0"
14
- gem "test_after_commit", "~> 0.4.2"
15
- gem "after_commit_exception_notification"
16
- end
17
-
18
- platforms :rbx do
19
- gem "rubysl", "~> 2.0"
20
- gem "rubinius-developer_tools"
21
- gem "rubysl-test-unit"
22
- end
23
-
24
- gemspec :path => "../"
@@ -1,24 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "sqlite3", :platforms => [:ruby]
6
- gem "activerecord-jdbcsqlite3-adapter", :platforms => [:jruby]
7
- gem "rake"
8
- gem "appraisal"
9
- gem "github_changelog_generator", "1.9.0"
10
- gem "activerecord", "~> 4.1.10"
11
-
12
- group :test do
13
- gem "minitest", "~> 5.0"
14
- gem "test_after_commit", "~> 0.4.2"
15
- gem "after_commit_exception_notification"
16
- end
17
-
18
- platforms :rbx do
19
- gem "rubysl", "~> 2.0"
20
- gem "rubinius-developer_tools"
21
- gem "rubysl-test-unit"
22
- end
23
-
24
- gemspec :path => "../"