acts_as_list 1.2.0 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -4
- data/README.md +3 -3
- data/lib/acts_as_list/active_record/acts/position_column_method_definer.rb +6 -5
- data/lib/acts_as_list/version.rb +1 -1
- metadata +5 -46
- 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 -39
- 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,16 @@ 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
|
+
|
14
|
+
## v1.2.1 - 2024-06-06
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- We no longer delegate the class `connection` method to the instance. [\#436](https://github.com/brendon/acts_as_list/pull/436) ([davidcelis])
|
18
|
+
|
9
19
|
## v1.2.0 - 2024-06-03
|
10
20
|
|
11
21
|
### Added
|
@@ -265,7 +275,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
265
275
|
**Closed issues:**
|
266
276
|
|
267
277
|
- DEPRECATION WARNING on rails 5.0 as of acts\_as\_list 0.9 [\#251](https://github.com/brendon/acts_as_list/issues/251)
|
268
|
-
-
|
278
|
+
- higher\_items returns items with the same position value [\#247](https://github.com/brendon/acts_as_list/issues/247)
|
269
279
|
- Broken with unique constraint on position [\#245](https://github.com/brendon/acts_as_list/issues/245)
|
270
280
|
|
271
281
|
**Merged pull requests:**
|
@@ -493,7 +503,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
493
503
|
- Fix sanitize\_sql\_hash\_for\_conditions deprecation warning in Rails 4.2 [\#140](https://github.com/brendon/acts_as_list/pull/140) ([eagletmt](https://github.com/eagletmt))
|
494
504
|
- Simpler method to find the subclass name [\#139](https://github.com/brendon/acts_as_list/pull/139) ([brendon](https://github.com/brendon))
|
495
505
|
- Rails4 enum column support [\#130](https://github.com/brendon/acts_as_list/pull/130) ([arunagw](https://github.com/arunagw))
|
496
|
-
- use eval for
|
506
|
+
- use eval for determining the self.class.name useful when this is used in an abstract class [\#123](https://github.com/brendon/acts_as_list/pull/123) ([flarik](https://github.com/flarik))
|
497
507
|
|
498
508
|
## [0.5.0](https://github.com/brendon/acts_as_list/tree/0.5.0) (2014-10-31)
|
499
509
|
[Full Changelog](https://github.com/brendon/acts_as_list/compare/0.4.0...0.5.0)
|
@@ -633,7 +643,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
633
643
|
- acts\_as\_list :scope =\> "doesnt\_seem\_to\_work" [\#12](https://github.com/brendon/acts_as_list/issues/12)
|
634
644
|
- don't work perfectly with default\_scope [\#11](https://github.com/brendon/acts_as_list/issues/11)
|
635
645
|
- MySQL: Position column MUST NOT have default [\#10](https://github.com/brendon/acts_as_list/issues/10)
|
636
|
-
- insert\_at fails on postgresql w/ non-null constraint on
|
646
|
+
- insert\_at fails on postgresql w/ non-null constraint on position\_column [\#8](https://github.com/brendon/acts_as_list/issues/8)
|
637
647
|
|
638
648
|
**Merged pull requests:**
|
639
649
|
|
@@ -642,7 +652,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
642
652
|
- Massive test refactorings. [\#24](https://github.com/brendon/acts_as_list/pull/24) ([splattael](https://github.com/splattael))
|
643
653
|
- Silent migrations to reduce test noise. [\#22](https://github.com/brendon/acts_as_list/pull/22) ([splattael](https://github.com/splattael))
|
644
654
|
- Should decrement lower items after the item has been destroyed to avoid unique key conflicts. [\#18](https://github.com/brendon/acts_as_list/pull/18) ([aepstein](https://github.com/aepstein))
|
645
|
-
- Fix spelling and
|
655
|
+
- Fix spelling and grammar [\#15](https://github.com/brendon/acts_as_list/pull/15) ([tmiller](https://github.com/tmiller))
|
646
656
|
- store\_at\_0 should yank item from the list then decrement items to avoid r [\#14](https://github.com/brendon/acts_as_list/pull/14) ([aepstein](https://github.com/aepstein))
|
647
657
|
- Support default\_scope ordering by calling .unscoped [\#13](https://github.com/brendon/acts_as_list/pull/13) ([tanordheim](https://github.com/tanordheim))
|
648
658
|
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Acts As List
|
2
2
|
|
3
3
|
## Build Status
|
4
|
-
[![
|
4
|
+
[![Continuous Integration](https://github.com/brendon/acts_as_list/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/brendon/acts_as_list/actions/workflows/continuous_integration.yml)
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/acts_as_list.svg)](https://badge.fury.io/rb/acts_as_list)
|
6
6
|
|
7
7
|
## ANNOUNCING: Positioning, the gem
|
8
|
-
As maintainer of both Acts As List and the Ranked Model gems, I've become intimately
|
8
|
+
As maintainer of both Acts As List and the Ranked Model gems, I've become intimately acquainted with the strengths and weaknesses of each. I ended up writing a small scale Rails Concern for positioning database rows for a recent project and it worked really well so I've decided to release it as a gem: [Positioning](https://github.com/brendon/positioning)
|
9
9
|
|
10
10
|
Positioning works similarly to Acts As List in that it maintains a sequential list of integer values as positions. It differs in that it encourages a unique constraints on the position column and supports multiple lists per database table. It borrows Ranked Model's concept of relative positioning. I encourage you to check it out and give it a whirl on your project!
|
11
11
|
|
@@ -290,7 +290,7 @@ All versions `0.1.5` onwards require Rails 3.0.x and higher.
|
|
290
290
|
|
291
291
|
We often hear complaints that `position` values are repeated, incorrect etc. For example, #254. To ensure data integrity, you should rely on your database. There are two things you can do:
|
292
292
|
|
293
|
-
1. Use constraints. If you model `Item` that `belongs_to` an `Order`, and it has a `position` column, then add a unique constraint on `items` with `[:order_id, :position]`. Think of it as a list invariant. What are the properties of your list that don't change no matter how many items you have in it? One such
|
293
|
+
1. Use constraints. If you model `Item` that `belongs_to` an `Order`, and it has a `position` column, then add a unique constraint on `items` with `[:order_id, :position]`. Think of it as a list invariant. What are the properties of your list that don't change no matter how many items you have in it? One such property is that each item has a distinct position. Another _could be_ that position is always greater than 0. It is strongly recommended that you rely on your database to enforce these invariants or constraints. Here are the docs for [PostgreSQL](https://www.postgresql.org/docs/9.5/static/ddl-constraints.html) and [MySQL](https://dev.mysql.com/doc/refman/8.0/en/alter-table.html).
|
294
294
|
2. Use mutexes or row level locks. At its heart the duplicate problem is that of handling concurrency. Adding a contention resolution mechanism like locks will solve it to some extent. But it is not a solution or replacement for constraints. Locks are also prone to deadlocks.
|
295
295
|
|
296
296
|
As a library, `acts_as_list` may not always have all the context needed to apply these tools. They are much better suited at the application level.
|
@@ -72,17 +72,18 @@ module ActiveRecord::Acts::List::PositionColumnMethodDefiner #:nodoc:
|
|
72
72
|
cached_quoted_now = quoted_current_time_from_proper_timezone
|
73
73
|
|
74
74
|
timestamp_attributes_for_update_in_model.map do |attr|
|
75
|
-
", #{connection.quote_column_name(attr)} = #{cached_quoted_now}"
|
75
|
+
", #{self.class.connection.quote_column_name(attr)} = #{cached_quoted_now}"
|
76
76
|
end.join
|
77
77
|
end
|
78
78
|
|
79
79
|
private
|
80
80
|
|
81
|
-
delegate :connection, to: self
|
82
|
-
|
83
81
|
def quoted_current_time_from_proper_timezone
|
84
|
-
connection.quote(
|
85
|
-
|
82
|
+
self.class.connection.quote(
|
83
|
+
self.class.connection.quoted_date(
|
84
|
+
current_time_from_proper_timezone
|
85
|
+
)
|
86
|
+
)
|
86
87
|
end
|
87
88
|
end
|
88
89
|
end
|
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
|
@@ -182,6 +158,7 @@ metadata:
|
|
182
158
|
changelog_uri: https://github.com/brendon/acts_as_list/blob/master/CHANGELOG.md
|
183
159
|
source_code_uri: https://github.com/brendon/acts_as_list
|
184
160
|
bug_tracker_uri: https://github.com/brendon/acts_as_list/issues
|
161
|
+
rubygems_mfa_required: 'true'
|
185
162
|
post_install_message:
|
186
163
|
rdoc_options: []
|
187
164
|
require_paths:
|
@@ -190,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
167
|
requirements:
|
191
168
|
- - ">="
|
192
169
|
- !ruby/object:Gem::Version
|
193
|
-
version: 2.
|
170
|
+
version: '2.5'
|
194
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
172
|
requirements:
|
196
173
|
- - ">="
|
@@ -202,22 +179,4 @@ signing_key:
|
|
202
179
|
specification_version: 4
|
203
180
|
summary: A gem adding sorting, reordering capabilities to an active_record model,
|
204
181
|
allowing it to act as a list
|
205
|
-
test_files:
|
206
|
-
- test/helper.rb
|
207
|
-
- test/shared.rb
|
208
|
-
- test/shared_array_scope_list.rb
|
209
|
-
- test/shared_list.rb
|
210
|
-
- test/shared_list_sub.rb
|
211
|
-
- test/shared_no_addition.rb
|
212
|
-
- test/shared_quoting.rb
|
213
|
-
- test/shared_top_addition.rb
|
214
|
-
- test/shared_zero_based.rb
|
215
|
-
- test/support/ci_database.yml
|
216
|
-
- test/support/database.yml
|
217
|
-
- test/test_default_scope_with_select.rb
|
218
|
-
- test/test_joined_list.rb
|
219
|
-
- test/test_list.rb
|
220
|
-
- test/test_no_update_for_extra_classes.rb
|
221
|
-
- test/test_no_update_for_scope_destruction.rb
|
222
|
-
- test/test_no_update_for_subclasses.rb
|
223
|
-
- 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,39 +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.4.7"
|
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
|
-
end
|
23
|
-
|
24
|
-
# Load Paths...
|
25
|
-
s.files = `git ls-files`.split("\n")
|
26
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f)}
|
28
|
-
s.require_paths = ["lib"]
|
29
|
-
|
30
|
-
# Dependencies (installed via "bundle install")
|
31
|
-
s.add_dependency "activerecord", ">= 6.1"
|
32
|
-
s.add_dependency "activesupport", ">= 6.1"
|
33
|
-
s.add_development_dependency "minitest-hooks", "~> 1.5.1"
|
34
|
-
s.add_development_dependency "mocha", "~> 2.1.0"
|
35
|
-
s.add_development_dependency "timecop", "~> 0.9.8"
|
36
|
-
s.add_development_dependency "mysql2", "~> 0.5.6"
|
37
|
-
s.add_development_dependency "pg", "~> 1.5.5"
|
38
|
-
s.add_development_dependency "sqlite3", "~> 1.7.2"
|
39
|
-
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
|