acts_as_list 1.1.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/continuous_integration.yml +62 -0
- data/.gitignore +3 -2
- data/CHANGELOG.md +18 -4
- data/Gemfile +6 -21
- data/README.md +9 -4
- data/Rakefile +0 -8
- data/acts_as_list.gemspec +11 -5
- data/lib/acts_as_list/active_record/acts/list.rb +10 -5
- data/lib/acts_as_list/active_record/acts/position_column_method_definer.rb +6 -5
- data/lib/acts_as_list/active_record/acts/scope_method_definer.rb +1 -2
- data/lib/acts_as_list/version.rb +1 -1
- data/test/helper.rb +17 -5
- data/test/shared_list.rb +131 -108
- data/test/support/ci_database.yml +20 -0
- data/test/{database.yml → support/database.yml} +1 -1
- data/test/test_list.rb +136 -5
- metadata +104 -26
- data/.github/workflows/ci.yml +0 -123
- data/.travis.yml +0 -55
- data/Appraisals +0 -44
- data/gemfiles/rails_4_2.gemfile +0 -32
- data/gemfiles/rails_5_0.gemfile +0 -31
- data/gemfiles/rails_5_1.gemfile +0 -31
- data/gemfiles/rails_5_2.gemfile +0 -31
- data/gemfiles/rails_6_0.gemfile +0 -31
- data/gemfiles/rails_6_1.gemfile +0 -31
- data/gemfiles/rails_7_0.gemfile +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9d85921cd5b149fa3581d5868734c62fb42e449e4058db26cffb0e62a146b9c
|
4
|
+
data.tar.gz: 94b6b6a6599ec0fa381f737bd5b2132258b7620905016bb467e1663f9552021a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f991880d1399bdbe56e4ef2511368115fc382dfebe2549188e0b8123f5cd8a93b33f067a602aadd8dbfa70893662b6fe5072d9deea7aba26d8827b83b9e1ac41
|
7
|
+
data.tar.gz: df1570e602643b91b602ed3044c9fbe8457ce95e42cf8fdca5858d8bd1460f4105f8839bf87c5338cb0fb4cbac11c46b15c6206dc039cc39cc3c1b561129fcee
|
@@ -0,0 +1,62 @@
|
|
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
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## Unreleased
|
8
8
|
|
9
|
+
## v1.2.1 - 2024-06-06
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
- We no longer delegate the class `connection` method to the instance. [\#436](https://github.com/brendon/acts_as_list/pull/436) ([davidcelis])
|
13
|
+
|
14
|
+
## v1.2.0 - 2024-06-03
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- Add support for composite primary keys. [\#430](https://github.com/brendon/acts_as_list/pull/430) ([divagueame])
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
- Refactored CI testing framework and removed the Appraisals gem. Use RAILS_VERSION to switch the Rails version you are currently running the tests against.
|
21
|
+
- We now only explicitly test against Rails 6.1+ and Ruby 3.0+.
|
22
|
+
|
9
23
|
## v1.1.0 - 2023-02-01
|
10
24
|
|
11
25
|
### Fixed (Possibly Breaking)
|
@@ -256,7 +270,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
256
270
|
**Closed issues:**
|
257
271
|
|
258
272
|
- DEPRECATION WARNING on rails 5.0 as of acts\_as\_list 0.9 [\#251](https://github.com/brendon/acts_as_list/issues/251)
|
259
|
-
-
|
273
|
+
- higher\_items returns items with the same position value [\#247](https://github.com/brendon/acts_as_list/issues/247)
|
260
274
|
- Broken with unique constraint on position [\#245](https://github.com/brendon/acts_as_list/issues/245)
|
261
275
|
|
262
276
|
**Merged pull requests:**
|
@@ -484,7 +498,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
484
498
|
- 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))
|
485
499
|
- Simpler method to find the subclass name [\#139](https://github.com/brendon/acts_as_list/pull/139) ([brendon](https://github.com/brendon))
|
486
500
|
- Rails4 enum column support [\#130](https://github.com/brendon/acts_as_list/pull/130) ([arunagw](https://github.com/arunagw))
|
487
|
-
- use eval for
|
501
|
+
- 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))
|
488
502
|
|
489
503
|
## [0.5.0](https://github.com/brendon/acts_as_list/tree/0.5.0) (2014-10-31)
|
490
504
|
[Full Changelog](https://github.com/brendon/acts_as_list/compare/0.4.0...0.5.0)
|
@@ -624,7 +638,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
624
638
|
- acts\_as\_list :scope =\> "doesnt\_seem\_to\_work" [\#12](https://github.com/brendon/acts_as_list/issues/12)
|
625
639
|
- don't work perfectly with default\_scope [\#11](https://github.com/brendon/acts_as_list/issues/11)
|
626
640
|
- MySQL: Position column MUST NOT have default [\#10](https://github.com/brendon/acts_as_list/issues/10)
|
627
|
-
- insert\_at fails on postgresql w/ non-null constraint on
|
641
|
+
- insert\_at fails on postgresql w/ non-null constraint on position\_column [\#8](https://github.com/brendon/acts_as_list/issues/8)
|
628
642
|
|
629
643
|
**Merged pull requests:**
|
630
644
|
|
@@ -633,7 +647,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
633
647
|
- Massive test refactorings. [\#24](https://github.com/brendon/acts_as_list/pull/24) ([splattael](https://github.com/splattael))
|
634
648
|
- Silent migrations to reduce test noise. [\#22](https://github.com/brendon/acts_as_list/pull/22) ([splattael](https://github.com/splattael))
|
635
649
|
- 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))
|
636
|
-
- Fix spelling and
|
650
|
+
- Fix spelling and grammar [\#15](https://github.com/brendon/acts_as_list/pull/15) ([tmiller](https://github.com/tmiller))
|
637
651
|
- 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))
|
638
652
|
- Support default\_scope ordering by calling .unscoped [\#13](https://github.com/brendon/acts_as_list/pull/13) ([tanordheim](https://github.com/tanordheim))
|
639
653
|
|
data/Gemfile
CHANGED
@@ -1,28 +1,13 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
+
# Specify your gem's dependencies in positioning.gemspec
|
3
4
|
gemspec
|
4
5
|
|
5
|
-
gem "rake"
|
6
|
-
gem "appraisal"
|
6
|
+
gem "rake", "~> 13.0"
|
7
7
|
|
8
|
-
|
9
|
-
gem "github_changelog_generator", "1.9.0"
|
10
|
-
end
|
11
|
-
|
12
|
-
group :test do
|
13
|
-
gem "minitest", "~> 5.0"
|
14
|
-
gem "timecop"
|
15
|
-
gem "mocha"
|
16
|
-
end
|
17
|
-
|
18
|
-
group :sqlite do
|
19
|
-
gem "sqlite3", "~> 1.4"
|
20
|
-
end
|
21
|
-
|
22
|
-
group :postgresql do
|
23
|
-
gem "pg", "~> 1.2.0"
|
24
|
-
end
|
8
|
+
gem "minitest", "~> 5.0"
|
25
9
|
|
26
|
-
|
27
|
-
gem "
|
10
|
+
if ENV["RAILS_VERSION"]
|
11
|
+
gem "activerecord", ENV["RAILS_VERSION"]
|
12
|
+
gem "activesupport", ENV["RAILS_VERSION"]
|
28
13
|
end
|
data/README.md
CHANGED
@@ -1,9 +1,14 @@
|
|
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
|
+
## ANNOUNCING: Positioning, the gem
|
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
|
+
|
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
|
+
|
7
12
|
## Description
|
8
13
|
|
9
14
|
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.
|
@@ -117,7 +122,7 @@ When using PostgreSQL, it is also possible to leave this migration up to the dat
|
|
117
122
|
ROW_NUMBER() OVER (
|
118
123
|
PARTITION BY todo_list_id
|
119
124
|
ORDER BY updated_at
|
120
|
-
)
|
125
|
+
) AS new_position
|
121
126
|
FROM todo_items
|
122
127
|
) AS mapping
|
123
128
|
WHERE todo_items.id = mapping.id;
|
@@ -195,7 +200,7 @@ class TodoItem < ActiveRecord::Base
|
|
195
200
|
end
|
196
201
|
|
197
202
|
class TodoAttachment < ActiveRecord::Base
|
198
|
-
belongs_to :
|
203
|
+
belongs_to :todo_item
|
199
204
|
acts_as_list scope: :todo_item
|
200
205
|
end
|
201
206
|
|
@@ -285,7 +290,7 @@ All versions `0.1.5` onwards require Rails 3.0.x and higher.
|
|
285
290
|
|
286
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:
|
287
292
|
|
288
|
-
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).
|
289
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.
|
290
295
|
|
291
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.
|
data/Rakefile
CHANGED
@@ -32,11 +32,3 @@ rescue LoadError
|
|
32
32
|
rescue StandardError
|
33
33
|
puts "RDocTask is not supported on this platform."
|
34
34
|
end
|
35
|
-
|
36
|
-
# See https://github.com/skywinder/github-changelog-generator#rake-task for details
|
37
|
-
# and github_changelog_generator --help for available options
|
38
|
-
require 'github_changelog_generator/task'
|
39
|
-
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
40
|
-
config.project = 'acts_as_list'
|
41
|
-
config.user = 'brendon'
|
42
|
-
end
|
data/acts_as_list.gemspec
CHANGED
@@ -9,16 +9,17 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.authors = ["Swanand Pagnis", "Brendon Muir"]
|
11
11
|
s.email = %w(swanand.pagnis@gmail.com brendon@spikeatschool.co.nz)
|
12
|
-
s.homepage = "
|
12
|
+
s.homepage = "https://github.com/brendon/acts_as_list"
|
13
13
|
s.summary = "A gem adding sorting, reordering capabilities to an active_record model, allowing it to act as a list"
|
14
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
15
|
s.license = "MIT"
|
16
|
-
s.required_ruby_version = ">= 2.
|
16
|
+
s.required_ruby_version = ">= 2.5"
|
17
17
|
|
18
18
|
if s.respond_to?(:metadata)
|
19
19
|
s.metadata['changelog_uri'] = 'https://github.com/brendon/acts_as_list/blob/master/CHANGELOG.md'
|
20
20
|
s.metadata['source_code_uri'] = 'https://github.com/brendon/acts_as_list'
|
21
21
|
s.metadata['bug_tracker_uri'] = 'https://github.com/brendon/acts_as_list/issues'
|
22
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
22
23
|
end
|
23
24
|
|
24
25
|
# Load Paths...
|
@@ -27,8 +28,13 @@ Gem::Specification.new do |s|
|
|
27
28
|
s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f)}
|
28
29
|
s.require_paths = ["lib"]
|
29
30
|
|
30
|
-
|
31
31
|
# Dependencies (installed via "bundle install")
|
32
|
-
s.add_dependency "activerecord", ">=
|
33
|
-
s.
|
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"
|
34
40
|
end
|
@@ -171,7 +171,7 @@ module ActiveRecord
|
|
171
171
|
limit ||= acts_as_list_list.count
|
172
172
|
acts_as_list_list.
|
173
173
|
where("#{quoted_position_column_with_table_name} <= ?", current_position).
|
174
|
-
where
|
174
|
+
where.not(primary_key_condition).
|
175
175
|
reorder(acts_as_list_order_argument(:desc)).
|
176
176
|
limit(limit)
|
177
177
|
end
|
@@ -188,7 +188,7 @@ module ActiveRecord
|
|
188
188
|
limit ||= acts_as_list_list.count
|
189
189
|
acts_as_list_list.
|
190
190
|
where("#{quoted_position_column_with_table_name} >= ?", current_position).
|
191
|
-
where
|
191
|
+
where.not(primary_key_condition).
|
192
192
|
reorder(acts_as_list_order_argument(:asc)).
|
193
193
|
limit(limit)
|
194
194
|
end
|
@@ -273,7 +273,7 @@ module ActiveRecord
|
|
273
273
|
scope = acts_as_list_list
|
274
274
|
|
275
275
|
if except
|
276
|
-
scope = scope.where(
|
276
|
+
scope = scope.where.not(primary_key_condition(except.id))
|
277
277
|
end
|
278
278
|
|
279
279
|
scope.in_list.reorder(acts_as_list_order_argument(:desc)).first
|
@@ -300,7 +300,7 @@ module ActiveRecord
|
|
300
300
|
scope = acts_as_list_list
|
301
301
|
|
302
302
|
if avoid_id
|
303
|
-
scope = scope.where(
|
303
|
+
scope = scope.where.not(primary_key_condition(avoid_id))
|
304
304
|
end
|
305
305
|
|
306
306
|
if sequential_updates?
|
@@ -341,7 +341,7 @@ module ActiveRecord
|
|
341
341
|
scope = acts_as_list_list
|
342
342
|
|
343
343
|
if avoid_id
|
344
|
-
scope = scope.where(
|
344
|
+
scope = scope.where.not(primary_key_condition(avoid_id))
|
345
345
|
end
|
346
346
|
|
347
347
|
if old_position < new_position
|
@@ -480,6 +480,11 @@ module ActiveRecord
|
|
480
480
|
version = Gem.loaded_specs['activerecord'].version
|
481
481
|
requirement.satisfied_by?(version)
|
482
482
|
end
|
483
|
+
|
484
|
+
def primary_key_condition(id = nil)
|
485
|
+
primary_keys = Array.wrap(self.class.primary_key)
|
486
|
+
id ? primary_keys.zip(Array.wrap(id)).to_h : slice(*primary_keys)
|
487
|
+
end
|
483
488
|
end
|
484
489
|
|
485
490
|
end
|
@@ -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
|
@@ -2,7 +2,6 @@
|
|
2
2
|
require "active_support/inflector"
|
3
3
|
|
4
4
|
module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
|
5
|
-
extend ActiveSupport::Inflector
|
6
5
|
|
7
6
|
def self.call(caller_class, scope)
|
8
7
|
scope = idify(caller_class, scope) if scope.is_a?(Symbol)
|
@@ -71,7 +70,7 @@ module ActiveRecord::Acts::List::ScopeMethodDefiner #:nodoc:
|
|
71
70
|
if caller_class.reflections.key?(name.to_s)
|
72
71
|
caller_class.reflections[name.to_s].foreign_key.to_sym
|
73
72
|
else
|
74
|
-
foreign_key(name).to_sym
|
73
|
+
ActiveSupport::Inflector.foreign_key(name).to_sym
|
75
74
|
end
|
76
75
|
end
|
77
76
|
end
|
data/lib/acts_as_list/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -16,6 +16,8 @@ require "minitest/autorun"
|
|
16
16
|
require "mocha/minitest"
|
17
17
|
require "#{File.dirname(__FILE__)}/../init"
|
18
18
|
|
19
|
+
ENV["DB"] = "mysql" unless ENV["DB"]
|
20
|
+
|
19
21
|
if defined?(ActiveRecord::VERSION) &&
|
20
22
|
ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 2
|
21
23
|
|
@@ -23,8 +25,10 @@ if defined?(ActiveRecord::VERSION) &&
|
|
23
25
|
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
24
26
|
end
|
25
27
|
|
26
|
-
|
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)
|
28
32
|
ActiveRecord::Schema.verbose = false
|
29
33
|
|
30
34
|
def teardown_db
|
@@ -53,8 +57,8 @@ def assert_equal_or_nil(a, b)
|
|
53
57
|
end
|
54
58
|
|
55
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')
|
56
|
-
original_behavior =
|
57
|
-
|
60
|
+
original_behavior = active_record_deprecator.behavior
|
61
|
+
active_record_deprecator.behavior = :raise
|
58
62
|
begin
|
59
63
|
yield
|
60
64
|
rescue ActiveSupport::DeprecationException => e
|
@@ -65,5 +69,13 @@ def assert_no_deprecation_warning_raised_by(failure_message = 'ActiveRecord depr
|
|
65
69
|
pass pass_message
|
66
70
|
end
|
67
71
|
ensure
|
68
|
-
|
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
|
69
81
|
end
|