acts_as_list 1.2.1 → 1.2.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/acts_as_list/version.rb +1 -1
- metadata +3 -45
- data/.github/FUNDING.yml +0 -3
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/continuous_integration.yml +0 -62
- data/.gitignore +0 -13
- data/Gemfile +0 -13
- data/acts_as_list.gemspec +0 -40
- data/test/helper.rb +0 -81
- data/test/shared.rb +0 -12
- data/test/shared_array_scope_list.rb +0 -177
- data/test/shared_list.rb +0 -347
- data/test/shared_list_sub.rb +0 -188
- data/test/shared_no_addition.rb +0 -73
- data/test/shared_quoting.rb +0 -23
- data/test/shared_top_addition.rb +0 -110
- data/test/shared_zero_based.rb +0 -104
- data/test/support/ci_database.yml +0 -20
- data/test/support/database.yml +0 -18
- data/test/test_default_scope_with_select.rb +0 -33
- data/test/test_joined_list.rb +0 -61
- data/test/test_list.rb +0 -1253
- data/test/test_no_update_for_extra_classes.rb +0 -131
- data/test/test_no_update_for_scope_destruction.rb +0 -69
- data/test/test_no_update_for_subclasses.rb +0 -56
- data/test/test_scope_with_user_defined_foreign_key.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc38c9c0378653bb5f8eb7194bd9cc22d906df7cf2b7a158e9fe763a0d6f5a94
|
4
|
+
data.tar.gz: c67158a399378bab4f1258ba6819f9cb7715eedc0b63e1f995869d0032075b75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b4b29d19abf1dbc2b0c75b4f0a0e4123ec4580084a170af83ca3431ca0bc7d46fa108ba3d6573620585bb00332c0b2b10b68779d2a4fd899fcfc888601e83ab
|
7
|
+
data.tar.gz: 2c999ec1287f4fafacd7406317075c5a0410f84a8c7e0b96ec787fffee0209033ca78aa4947948aee830fe41a6de173ad031fe5895daf33b12679140507aa278
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## Unreleased
|
8
8
|
|
9
|
+
## v1.2.2 - 2024-07-16
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
- Updated .gemspec to exclude unnecessary files from the gem package. [\#437](https://github.com/brendon/acts_as_list/pull/437) ([f440])
|
13
|
+
|
9
14
|
## v1.2.1 - 2024-06-06
|
10
15
|
|
11
16
|
### Fixed
|
data/lib/acts_as_list/version.rb
CHANGED
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: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Swanand Pagnis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -134,16 +134,10 @@ extensions: []
|
|
134
134
|
extra_rdoc_files: []
|
135
135
|
files:
|
136
136
|
- ".gemtest"
|
137
|
-
- ".github/FUNDING.yml"
|
138
|
-
- ".github/dependabot.yml"
|
139
|
-
- ".github/workflows/continuous_integration.yml"
|
140
|
-
- ".gitignore"
|
141
137
|
- CHANGELOG.md
|
142
|
-
- Gemfile
|
143
138
|
- MIT-LICENSE
|
144
139
|
- README.md
|
145
140
|
- Rakefile
|
146
|
-
- acts_as_list.gemspec
|
147
141
|
- init.rb
|
148
142
|
- lib/acts_as_list.rb
|
149
143
|
- lib/acts_as_list/active_record/acts/active_record.rb
|
@@ -157,24 +151,6 @@ files:
|
|
157
151
|
- lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
|
158
152
|
- lib/acts_as_list/active_record/acts/top_of_list_method_definer.rb
|
159
153
|
- lib/acts_as_list/version.rb
|
160
|
-
- test/helper.rb
|
161
|
-
- test/shared.rb
|
162
|
-
- test/shared_array_scope_list.rb
|
163
|
-
- test/shared_list.rb
|
164
|
-
- test/shared_list_sub.rb
|
165
|
-
- test/shared_no_addition.rb
|
166
|
-
- test/shared_quoting.rb
|
167
|
-
- test/shared_top_addition.rb
|
168
|
-
- test/shared_zero_based.rb
|
169
|
-
- test/support/ci_database.yml
|
170
|
-
- test/support/database.yml
|
171
|
-
- test/test_default_scope_with_select.rb
|
172
|
-
- test/test_joined_list.rb
|
173
|
-
- test/test_list.rb
|
174
|
-
- test/test_no_update_for_extra_classes.rb
|
175
|
-
- test/test_no_update_for_scope_destruction.rb
|
176
|
-
- test/test_no_update_for_subclasses.rb
|
177
|
-
- test/test_scope_with_user_defined_foreign_key.rb
|
178
154
|
homepage: https://github.com/brendon/acts_as_list
|
179
155
|
licenses:
|
180
156
|
- MIT
|
@@ -203,22 +179,4 @@ signing_key:
|
|
203
179
|
specification_version: 4
|
204
180
|
summary: A gem adding sorting, reordering capabilities to an active_record model,
|
205
181
|
allowing it to act as a list
|
206
|
-
test_files:
|
207
|
-
- test/helper.rb
|
208
|
-
- test/shared.rb
|
209
|
-
- test/shared_array_scope_list.rb
|
210
|
-
- test/shared_list.rb
|
211
|
-
- test/shared_list_sub.rb
|
212
|
-
- test/shared_no_addition.rb
|
213
|
-
- test/shared_quoting.rb
|
214
|
-
- test/shared_top_addition.rb
|
215
|
-
- test/shared_zero_based.rb
|
216
|
-
- test/support/ci_database.yml
|
217
|
-
- test/support/database.yml
|
218
|
-
- test/test_default_scope_with_select.rb
|
219
|
-
- test/test_joined_list.rb
|
220
|
-
- test/test_list.rb
|
221
|
-
- test/test_no_update_for_extra_classes.rb
|
222
|
-
- test/test_no_update_for_scope_destruction.rb
|
223
|
-
- test/test_no_update_for_subclasses.rb
|
224
|
-
- test/test_scope_with_user_defined_foreign_key.rb
|
182
|
+
test_files: []
|
data/.github/FUNDING.yml
DELETED
data/.github/dependabot.yml
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
name: Continuous Integration
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches:
|
6
|
-
- master
|
7
|
-
pull_request:
|
8
|
-
|
9
|
-
jobs:
|
10
|
-
tests:
|
11
|
-
runs-on: ubuntu-latest
|
12
|
-
name: Ruby ${{ matrix.ruby }}, DB ${{ matrix.db }}, Rails ${{ matrix.rails }}
|
13
|
-
strategy:
|
14
|
-
fail-fast: false
|
15
|
-
matrix:
|
16
|
-
ruby:
|
17
|
-
- '3.0'
|
18
|
-
- '3.1'
|
19
|
-
- '3.2'
|
20
|
-
- '3.3'
|
21
|
-
rails:
|
22
|
-
- '6.1'
|
23
|
-
- '7.0'
|
24
|
-
- '7.1'
|
25
|
-
db:
|
26
|
-
- mysql
|
27
|
-
- postgresql
|
28
|
-
- sqlite
|
29
|
-
exclude:
|
30
|
-
- rails: '7.0'
|
31
|
-
ruby: '3.1'
|
32
|
-
- rails: '7.0'
|
33
|
-
ruby: '3.2'
|
34
|
-
- rails: '7.0'
|
35
|
-
ruby: '3.3'
|
36
|
-
env:
|
37
|
-
DB: ${{ matrix.db }}
|
38
|
-
RAILS_VERSION: ${{ matrix.rails }}
|
39
|
-
steps:
|
40
|
-
- uses: actions/checkout@v4
|
41
|
-
- name: Set up Ruby
|
42
|
-
uses: ruby/setup-ruby@v1
|
43
|
-
with:
|
44
|
-
ruby-version: ${{ matrix.ruby }}
|
45
|
-
bundler-cache: true
|
46
|
-
- name: Enable MySQL
|
47
|
-
if: ${{ matrix.db == 'mysql' }}
|
48
|
-
run: sudo systemctl start mysql.service
|
49
|
-
- name: Create MySQL Database
|
50
|
-
if: ${{ matrix.db == 'mysql' }}
|
51
|
-
run: mysql -u root -proot -e 'CREATE DATABASE runner;'
|
52
|
-
- name: Enable PostgreSQL
|
53
|
-
if: ${{ matrix.db == 'postgresql' }}
|
54
|
-
run: sudo systemctl start postgresql.service
|
55
|
-
- name: Create PostgreSQL User
|
56
|
-
if: ${{ matrix.db == 'postgresql' }}
|
57
|
-
run: sudo -u postgres -i createuser runner -s
|
58
|
-
- name: Create PostgreSQL Database
|
59
|
-
if: ${{ matrix.db == 'postgresql' }}
|
60
|
-
run: createdb runner
|
61
|
-
- name: Run the default task
|
62
|
-
run: bundle exec rake
|
data/.gitignore
DELETED
data/Gemfile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in positioning.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
gem "rake", "~> 13.0"
|
7
|
-
|
8
|
-
gem "minitest", "~> 5.0"
|
9
|
-
|
10
|
-
if ENV["RAILS_VERSION"]
|
11
|
-
gem "activerecord", ENV["RAILS_VERSION"]
|
12
|
-
gem "activesupport", ENV["RAILS_VERSION"]
|
13
|
-
end
|
data/acts_as_list.gemspec
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "acts_as_list/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
# Description Meta...
|
7
|
-
s.name = "acts_as_list"
|
8
|
-
s.version = ActiveRecord::Acts::List::VERSION
|
9
|
-
s.platform = Gem::Platform::RUBY
|
10
|
-
s.authors = ["Swanand Pagnis", "Brendon Muir"]
|
11
|
-
s.email = %w(swanand.pagnis@gmail.com brendon@spikeatschool.co.nz)
|
12
|
-
s.homepage = "https://github.com/brendon/acts_as_list"
|
13
|
-
s.summary = "A gem adding sorting, reordering capabilities to an active_record model, allowing it to act as a list"
|
14
|
-
s.description = 'This "acts_as" extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a "position" column defined as an integer on the mapped database table.'
|
15
|
-
s.license = "MIT"
|
16
|
-
s.required_ruby_version = ">= 2.5"
|
17
|
-
|
18
|
-
if s.respond_to?(:metadata)
|
19
|
-
s.metadata['changelog_uri'] = 'https://github.com/brendon/acts_as_list/blob/master/CHANGELOG.md'
|
20
|
-
s.metadata['source_code_uri'] = 'https://github.com/brendon/acts_as_list'
|
21
|
-
s.metadata['bug_tracker_uri'] = 'https://github.com/brendon/acts_as_list/issues'
|
22
|
-
s.metadata['rubygems_mfa_required'] = 'true'
|
23
|
-
end
|
24
|
-
|
25
|
-
# Load Paths...
|
26
|
-
s.files = `git ls-files`.split("\n")
|
27
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
28
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f)}
|
29
|
-
s.require_paths = ["lib"]
|
30
|
-
|
31
|
-
# Dependencies (installed via "bundle install")
|
32
|
-
s.add_dependency "activerecord", ">= 6.1"
|
33
|
-
s.add_dependency "activesupport", ">= 6.1"
|
34
|
-
s.add_development_dependency "minitest-hooks", "~> 1.5.1"
|
35
|
-
s.add_development_dependency "mocha", "~> 2.1.0"
|
36
|
-
s.add_development_dependency "timecop", "~> 0.9.8"
|
37
|
-
s.add_development_dependency "mysql2", "~> 0.5.6"
|
38
|
-
s.add_development_dependency "pg", "~> 1.5.5"
|
39
|
-
s.add_development_dependency "sqlite3", "~> 1.7.2"
|
40
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# $DEBUG = true
|
4
|
-
|
5
|
-
require "rubygems"
|
6
|
-
require "bundler/setup"
|
7
|
-
begin
|
8
|
-
Bundler.setup(:default, :development)
|
9
|
-
rescue Bundler::BundlerError => e
|
10
|
-
$stderr.puts e.message
|
11
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
-
exit e.status_code
|
13
|
-
end
|
14
|
-
require "active_record"
|
15
|
-
require "minitest/autorun"
|
16
|
-
require "mocha/minitest"
|
17
|
-
require "#{File.dirname(__FILE__)}/../init"
|
18
|
-
|
19
|
-
ENV["DB"] = "mysql" unless ENV["DB"]
|
20
|
-
|
21
|
-
if defined?(ActiveRecord::VERSION) &&
|
22
|
-
ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 2
|
23
|
-
|
24
|
-
# Was removed in Rails 5 and is effectively true.
|
25
|
-
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
26
|
-
end
|
27
|
-
|
28
|
-
database_configuration = ENV["CI"] ? "test/support/ci_database.yml" : "test/support/database.yml"
|
29
|
-
|
30
|
-
ActiveRecord::Base.configurations = YAML.safe_load(IO.read(database_configuration))
|
31
|
-
ActiveRecord::Base.establish_connection(ENV["DB"].to_sym)
|
32
|
-
ActiveRecord::Schema.verbose = false
|
33
|
-
|
34
|
-
def teardown_db
|
35
|
-
if ActiveRecord::VERSION::MAJOR >= 5
|
36
|
-
tables = ActiveRecord::Base.connection.data_sources
|
37
|
-
else
|
38
|
-
tables = ActiveRecord::Base.connection.tables
|
39
|
-
end
|
40
|
-
|
41
|
-
tables.each do |table|
|
42
|
-
ActiveRecord::Base.connection.drop_table(table)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
require "shared"
|
47
|
-
|
48
|
-
# require 'logger'
|
49
|
-
# ActiveRecord::Base.logger = Logger.new(STDOUT)
|
50
|
-
|
51
|
-
def assert_equal_or_nil(a, b)
|
52
|
-
if a.nil?
|
53
|
-
assert_nil b
|
54
|
-
else
|
55
|
-
assert_equal a, b
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
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')
|
60
|
-
original_behavior = active_record_deprecator.behavior
|
61
|
-
active_record_deprecator.behavior = :raise
|
62
|
-
begin
|
63
|
-
yield
|
64
|
-
rescue ActiveSupport::DeprecationException => e
|
65
|
-
flunk "#{failure_message}: #{e}"
|
66
|
-
rescue
|
67
|
-
raise
|
68
|
-
else
|
69
|
-
pass pass_message
|
70
|
-
end
|
71
|
-
ensure
|
72
|
-
active_record_deprecator.behavior = original_behavior
|
73
|
-
end
|
74
|
-
|
75
|
-
def active_record_deprecator
|
76
|
-
if ActiveRecord::VERSION::MAJOR == 7 && ActiveRecord::VERSION::MINOR >= 1 || ActiveRecord::VERSION::MAJOR > 7
|
77
|
-
ActiveRecord.deprecator
|
78
|
-
else
|
79
|
-
ActiveSupport::Deprecation
|
80
|
-
end
|
81
|
-
end
|
data/test/shared.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Common shared behaviour.
|
4
|
-
module Shared
|
5
|
-
autoload :List, 'shared_list'
|
6
|
-
autoload :ListSub, 'shared_list_sub'
|
7
|
-
autoload :ZeroBased, 'shared_zero_based'
|
8
|
-
autoload :ArrayScopeList, 'shared_array_scope_list'
|
9
|
-
autoload :TopAddition, 'shared_top_addition'
|
10
|
-
autoload :NoAddition, 'shared_no_addition'
|
11
|
-
autoload :Quoting, 'shared_quoting'
|
12
|
-
end
|
@@ -1,177 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Shared
|
4
|
-
module ArrayScopeList
|
5
|
-
def setup
|
6
|
-
(1..4).each { |counter| ArrayScopeListMixin.create! pos: counter, parent_id: 5, parent_type: 'ParentClass' }
|
7
|
-
(1..4).each { |counter| ArrayScopeListMixin.create! pos: counter, parent_id: 6, parent_type: 'ParentClass' }
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_reordering
|
11
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
12
|
-
|
13
|
-
ArrayScopeListMixin.where(id: 2).first.move_lower
|
14
|
-
assert_equal [1, 3, 2, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
15
|
-
|
16
|
-
ArrayScopeListMixin.where(id: 2).first.move_higher
|
17
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
18
|
-
|
19
|
-
ArrayScopeListMixin.where(id: 1).first.move_to_bottom
|
20
|
-
assert_equal [2, 3, 4, 1], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
21
|
-
|
22
|
-
ArrayScopeListMixin.where(id: 1).first.move_to_top
|
23
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
24
|
-
|
25
|
-
ArrayScopeListMixin.where(id: 2).first.move_to_bottom
|
26
|
-
assert_equal [1, 3, 4, 2], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
27
|
-
|
28
|
-
ArrayScopeListMixin.where(id: 4).first.move_to_top
|
29
|
-
assert_equal [4, 1, 3, 2], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
30
|
-
|
31
|
-
ArrayScopeListMixin.where(id: 4).first.insert_at(4)
|
32
|
-
assert_equal [1, 3, 2, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
33
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:pos)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_move_to_bottom_with_next_to_last_item
|
37
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
38
|
-
ArrayScopeListMixin.where(id: 3).first.move_to_bottom
|
39
|
-
assert_equal [1, 2, 4, 3], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_next_prev
|
43
|
-
assert_equal ArrayScopeListMixin.where(id: 2).first, ArrayScopeListMixin.where(id: 1).first.lower_item
|
44
|
-
assert_nil ArrayScopeListMixin.where(id: 1).first.higher_item
|
45
|
-
assert_equal ArrayScopeListMixin.where(id: 3).first, ArrayScopeListMixin.where(id: 4).first.higher_item
|
46
|
-
assert_nil ArrayScopeListMixin.where(id: 4).first.lower_item
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_injection
|
50
|
-
item = ArrayScopeListMixin.new(parent_id: 1, parent_type: 'ParentClass')
|
51
|
-
assert_equal "pos", item.position_column
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_insert
|
55
|
-
new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
|
56
|
-
assert_equal 1, new.pos
|
57
|
-
assert new.first?
|
58
|
-
assert new.last?
|
59
|
-
|
60
|
-
new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
|
61
|
-
assert_equal 2, new.pos
|
62
|
-
assert !new.first?
|
63
|
-
assert new.last?
|
64
|
-
|
65
|
-
new = ArrayScopeListMixin.acts_as_list_no_update { ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass') }
|
66
|
-
assert_equal_or_nil $default_position,new.pos
|
67
|
-
assert_equal $default_position.is_a?(Integer), new.first?
|
68
|
-
assert !new.last?
|
69
|
-
|
70
|
-
new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
|
71
|
-
assert_equal 3, new.pos
|
72
|
-
assert !new.first?
|
73
|
-
assert new.last?
|
74
|
-
|
75
|
-
new = ArrayScopeListMixin.create(parent_id: 0, parent_type: 'ParentClass')
|
76
|
-
assert_equal 1, new.pos
|
77
|
-
assert new.first?
|
78
|
-
assert new.last?
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_insert_at
|
82
|
-
new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
|
83
|
-
assert_equal 1, new.pos
|
84
|
-
|
85
|
-
new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
|
86
|
-
assert_equal 2, new.pos
|
87
|
-
|
88
|
-
new = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
|
89
|
-
assert_equal 3, new.pos
|
90
|
-
|
91
|
-
new_noup = ArrayScopeListMixin.acts_as_list_no_update { ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass') }
|
92
|
-
assert_equal_or_nil $default_position,new_noup.pos
|
93
|
-
|
94
|
-
new4 = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
|
95
|
-
assert_equal 4, new4.pos
|
96
|
-
|
97
|
-
new4.insert_at(3)
|
98
|
-
assert_equal 3, new4.pos
|
99
|
-
|
100
|
-
new.reload
|
101
|
-
assert_equal 4, new.pos
|
102
|
-
|
103
|
-
new.insert_at(2)
|
104
|
-
assert_equal 2, new.pos
|
105
|
-
|
106
|
-
new4.reload
|
107
|
-
assert_equal 4, new4.pos
|
108
|
-
|
109
|
-
new5 = ArrayScopeListMixin.create(parent_id: 20, parent_type: 'ParentClass')
|
110
|
-
assert_equal 5, new5.pos
|
111
|
-
|
112
|
-
new5.insert_at(1)
|
113
|
-
assert_equal 1, new5.pos
|
114
|
-
|
115
|
-
new4.reload
|
116
|
-
assert_equal 5, new4.pos
|
117
|
-
|
118
|
-
new_noup.reload
|
119
|
-
assert_equal_or_nil $default_position, new_noup.pos
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_delete_middle
|
123
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
124
|
-
|
125
|
-
ArrayScopeListMixin.where(id: 2).first.destroy
|
126
|
-
|
127
|
-
assert_equal [1, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
128
|
-
|
129
|
-
assert_equal 1, ArrayScopeListMixin.where(id: 1).first.pos
|
130
|
-
assert_equal 2, ArrayScopeListMixin.where(id: 3).first.pos
|
131
|
-
assert_equal 3, ArrayScopeListMixin.where(id: 4).first.pos
|
132
|
-
|
133
|
-
ArrayScopeListMixin.where(id: 1).first.destroy
|
134
|
-
|
135
|
-
assert_equal [3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
136
|
-
|
137
|
-
assert_equal 1, ArrayScopeListMixin.where(id: 3).first.pos
|
138
|
-
assert_equal 2, ArrayScopeListMixin.where(id: 4).first.pos
|
139
|
-
|
140
|
-
ArrayScopeListMixin.acts_as_list_no_update { ArrayScopeListMixin.where(id: 3).first.destroy }
|
141
|
-
|
142
|
-
assert_equal [4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
143
|
-
|
144
|
-
assert_equal 2, ArrayScopeListMixin.where(id: 4).first.pos
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_remove_from_list_should_then_fail_in_list?
|
148
|
-
assert_equal true, ArrayScopeListMixin.where(id: 1).first.in_list?
|
149
|
-
ArrayScopeListMixin.where(id: 1).first.remove_from_list
|
150
|
-
assert_equal false, ArrayScopeListMixin.where(id: 1).first.in_list?
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_remove_from_list_should_set_position_to_nil
|
154
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
155
|
-
|
156
|
-
ArrayScopeListMixin.where(id: 2).first.remove_from_list
|
157
|
-
|
158
|
-
assert_equal 1, ArrayScopeListMixin.where(id: 1).first.pos
|
159
|
-
assert_nil ArrayScopeListMixin.where(id: 2).first.pos
|
160
|
-
assert_equal 2, ArrayScopeListMixin.where(id: 3).first.pos
|
161
|
-
assert_equal 3, ArrayScopeListMixin.where(id: 4).first.pos
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_remove_before_destroy_does_not_shift_lower_items_twice
|
165
|
-
assert_equal [1, 2, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
166
|
-
|
167
|
-
ArrayScopeListMixin.where(id: 2).first.remove_from_list
|
168
|
-
ArrayScopeListMixin.where(id: 2).first.destroy
|
169
|
-
|
170
|
-
assert_equal [1, 3, 4], ArrayScopeListMixin.where(parent_id: 5, parent_type: 'ParentClass').order('pos').map(&:id)
|
171
|
-
|
172
|
-
assert_equal 1, ArrayScopeListMixin.where(id: 1).first.pos
|
173
|
-
assert_equal 2, ArrayScopeListMixin.where(id: 3).first.pos
|
174
|
-
assert_equal 3, ArrayScopeListMixin.where(id: 4).first.pos
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|