database_cleaner-active_record 2.2.0 → 2.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/.github/workflows/ci.yml +14 -7
- data/Appraisals +0 -13
- data/CHANGELOG.md +17 -1
- data/CONTRIBUTE.md +45 -0
- data/Dockerfile +19 -0
- data/README.md +6 -0
- data/database_cleaner-active_record.gemspec +3 -1
- data/docker-compose.db.yml +19 -0
- data/docker-compose.yml +26 -0
- data/gemfiles/rails_6.1.gemfile +4 -0
- data/gemfiles/rails_7.0.gemfile +4 -0
- data/gemfiles/rails_7.1.gemfile +3 -0
- data/gemfiles/rails_7.2.gemfile +4 -1
- data/gemfiles/rails_8.0.gemfile +16 -0
- data/gemfiles/rails_edge.gemfile +3 -0
- data/lib/database_cleaner/active_record/base.rb +0 -1
- data/lib/database_cleaner/active_record/deletion.rb +2 -3
- data/lib/database_cleaner/active_record/transaction.rb +2 -2
- data/lib/database_cleaner/active_record/truncation.rb +18 -14
- data/lib/database_cleaner/active_record/version.rb +1 -1
- data/lib/database_cleaner/active_record.rb +9 -5
- metadata +12 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4009a9e2733cc775473d2357dedf4005e14abc0be5a1b2841241dc9ac0a8afd
|
4
|
+
data.tar.gz: 89a9750d057f21fb543f2f7ca93926c48df4e2b08fec1276589063ca42254146
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0daef1af314e3a7f432257e7b6051076d7963e685861b5b232811bcb9bcc6cdf0d9a020b980536ca9533c804c0aebe258dbaf6ef642a96c56950be6faf50ce3a
|
7
|
+
data.tar.gz: 3166ab8f41926b33a005f458ad601de7f2cc0fff3c2a36151a5c217271fe3dd84a7db332c448ece8aafab396d5e730c3b4760acfc5b56edd6129201e12977f86
|
data/.github/workflows/ci.yml
CHANGED
@@ -9,14 +9,17 @@ jobs:
|
|
9
9
|
strategy:
|
10
10
|
fail-fast: false
|
11
11
|
matrix:
|
12
|
-
ruby: ['3.3', '3.2', '3.1']
|
13
|
-
rails: ['6.1', '7.0', '7.1', '7.2']
|
12
|
+
ruby: ['3.4', '3.3', '3.2', '3.1']
|
13
|
+
rails: ['6.1', '7.0', '7.1', '7.2', '8.0']
|
14
14
|
channel: ['stable']
|
15
15
|
|
16
16
|
include:
|
17
17
|
- ruby: 'ruby-head'
|
18
18
|
rails: 'edge'
|
19
19
|
channel: 'experimental'
|
20
|
+
- ruby: 'ruby-head'
|
21
|
+
rails: '8.0'
|
22
|
+
channel: 'experimental'
|
20
23
|
- ruby: 'ruby-head'
|
21
24
|
rails: '7.2'
|
22
25
|
channel: 'experimental'
|
@@ -24,25 +27,29 @@ jobs:
|
|
24
27
|
rails: '7.1'
|
25
28
|
channel: 'experimental'
|
26
29
|
|
27
|
-
- ruby: '3.
|
30
|
+
- ruby: '3.4'
|
28
31
|
rails: 'edge'
|
29
32
|
channel: 'experimental'
|
30
|
-
- ruby: '3.
|
33
|
+
- ruby: '3.3'
|
31
34
|
rails: 'edge'
|
32
35
|
channel: 'experimental'
|
33
|
-
- ruby: '3.
|
36
|
+
- ruby: '3.2'
|
34
37
|
rails: 'edge'
|
35
38
|
channel: 'experimental'
|
36
39
|
|
37
40
|
exclude:
|
38
|
-
- ruby: '3.
|
39
|
-
rails: '
|
41
|
+
- ruby: '3.4'
|
42
|
+
rails: '6.1'
|
43
|
+
|
40
44
|
- ruby: '3.3'
|
41
45
|
rails: '6.1'
|
42
46
|
|
43
47
|
- ruby: '3.2'
|
44
48
|
rails: '6.1'
|
45
49
|
|
50
|
+
- ruby: '3.1'
|
51
|
+
rails: '8.0'
|
52
|
+
|
46
53
|
continue-on-error: ${{ matrix.channel != 'stable' }}
|
47
54
|
|
48
55
|
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
data/Appraisals
CHANGED
@@ -1,16 +1,3 @@
|
|
1
|
-
appraise "rails-5.1" do
|
2
|
-
gem "rails", "~> 5.1.0"
|
3
|
-
end
|
4
|
-
|
5
|
-
appraise "rails-5.2" do
|
6
|
-
gem "rails", "~> 5.2.0"
|
7
|
-
end
|
8
|
-
|
9
|
-
appraise "rails-6.0" do
|
10
|
-
gem "rails", "~> 6.0.0"
|
11
|
-
gem "sqlite3", "~> 1.5"
|
12
|
-
end
|
13
|
-
|
14
1
|
appraise "rails-6.1" do
|
15
2
|
gem "rails", "~> 6.1.0"
|
16
3
|
gem "sqlite3", "~> 1.5"
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Development (unreleased)
|
2
2
|
|
3
|
+
## v2.2.2 2025-07-30
|
4
|
+
|
5
|
+
* Release database connections after cleaning: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/122
|
6
|
+
* Provide a 'Changelog' link on Rubygems: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/114
|
7
|
+
* Fix bundling and CONTRIBUTE.md instructions: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/123
|
8
|
+
* https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/121 by @etagwerker
|
9
|
+
* Fix order of arguments in `truncate_tables` expectation https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/124
|
10
|
+
* Add Docker to make it easier to run tests locally for maintainers and contributors https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/109
|
11
|
+
* Allow truncation option https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/121 by @etagwerker
|
12
|
+
|
13
|
+
## v2.2.1 2025-05-13
|
14
|
+
|
15
|
+
* https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/111 by @tagliala
|
16
|
+
* https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/104 by @fatkodima
|
17
|
+
* https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/118 by @pat, @thegeorgeous, and @nnishimura
|
18
|
+
|
3
19
|
## v2.2.0 2024-07-12
|
4
20
|
|
5
21
|
* Fix "ERROR: currval of sequence" in Postgres adapter: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/103
|
@@ -19,4 +35,4 @@
|
|
19
35
|
|
20
36
|
* Add Ruby 3.2 to CI matrix: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/79
|
21
37
|
* Add Rails 7.1 support: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/78
|
22
|
-
* Add WHERE clause to make `ruby-spanner-activerecord` happy: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/77
|
38
|
+
* Add WHERE clause to make `ruby-spanner-activerecord` happy: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/77
|
data/CONTRIBUTE.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Guidelines for contributing
|
2
|
+
|
3
|
+
## 1. Fork & Clone
|
4
|
+
|
5
|
+
Since you probably don't have rights to the main repo, you should Fork it (big
|
6
|
+
button up top). After that, clone your fork locally and optionally add an
|
7
|
+
upstream:
|
8
|
+
|
9
|
+
git remote add upstream git@github.com:DatabaseCleaner/database_cleaner-active_record.git
|
10
|
+
|
11
|
+
## 2. Make sure the tests run fine
|
12
|
+
|
13
|
+
The gem uses Appraisal to configure different Gemfiles to test different Rails versions.
|
14
|
+
|
15
|
+
### Run tests without Docker (or using Docker only for the databases)
|
16
|
+
|
17
|
+
- You can run all the databases through docker if needed with `docker compose -f docker-compose.db.yml up` (you can also have them running on your system, just comment out the ones you don't need from the `docker-compose.db.yml` file)
|
18
|
+
- Copy `spec/support/sample.config.yml` to `spec/support/config.yml` and edit it as needed
|
19
|
+
- `BUNDLE_GEMFILE=gemfiles/rails_6.1.gemfile bundle install` (change `6.1` with any version from the `gemfiles` directory)
|
20
|
+
- `BUNDLE_GEMFILE=gemfiles/rails_6.1.gemfile bundle exec rake`
|
21
|
+
|
22
|
+
Note that if you don't have all the supported databases installed and running,
|
23
|
+
some tests will fail.
|
24
|
+
|
25
|
+
> Check the `.github/workflows/ci.yml` file for different combinations of Ruby and Rails that are expected to work
|
26
|
+
|
27
|
+
### Run tests with Docker
|
28
|
+
|
29
|
+
- Open `docker-compose.yml` and configure the Ruby version and Gemfile file to use
|
30
|
+
- Copy `spec/support/sample.docker.config.yml` to `spec/support/config.yml` (not this config file is specific for the Docker setup)
|
31
|
+
- Run `docker compose up` to start the container, run the tests, and exit
|
32
|
+
- Run `docker compose run ruby bash` to open `bash` inside the container for more control, run `rake` to run the tests
|
33
|
+
|
34
|
+
> Note that the code is mounted inside the docker container, so changes in the container will reflect in the code. There's no need to re-build the container for code changes, but changing the Ruby version or Gemfile in the docker-compose.yml will require a container re-build with `docker compose build --no-cache`
|
35
|
+
|
36
|
+
> Check the `.github/workflows/ci.yml` file for different combinations of Ruby and Rails that are expected to work
|
37
|
+
|
38
|
+
## 3. Prepare your contribution
|
39
|
+
|
40
|
+
This is all up to you but a few points should be kept in mind:
|
41
|
+
|
42
|
+
- Please write tests for your contribution
|
43
|
+
- Make sure that previous tests still pass
|
44
|
+
- Push it to a branch of your fork
|
45
|
+
- Submit a pull request
|
data/Dockerfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
ARG RUBY_VERSION=3.3
|
2
|
+
FROM ruby:${RUBY_VERSION}
|
3
|
+
|
4
|
+
# Set the working directory in the container
|
5
|
+
WORKDIR /app
|
6
|
+
|
7
|
+
# Copy the current directory contents into the container at /app
|
8
|
+
# This is copied so we can bundle the application, but it's replaced
|
9
|
+
# by a mounted volume with the current code when executed with docker compose
|
10
|
+
COPY . /app
|
11
|
+
|
12
|
+
ARG BUNDLE_GEMFILE=Gemfile
|
13
|
+
ENV BUNDLE_GEMFILE=${BUNDLE_GEMFILE}
|
14
|
+
|
15
|
+
# Install any needed packages specified in Gemfile
|
16
|
+
RUN ./bin/setup
|
17
|
+
|
18
|
+
# Command to run the application
|
19
|
+
CMD ["bash"]
|
data/README.md
CHANGED
@@ -63,6 +63,8 @@ DatabaseCleaner[:active_record].strategy = DatabaseCleaner::ActiveRecord::Deleti
|
|
63
63
|
|
64
64
|
* `:reset_ids` - Only valid for deletion strategy, when set to `true` resets ids to 1 after each table is cleaned.
|
65
65
|
|
66
|
+
* `:truncate_option` - Only valid for PostgreSQL. Acceptable values are `:restrict` and `:cascade`. Default is `:restrict`
|
67
|
+
|
66
68
|
## Adapter configuration options
|
67
69
|
|
68
70
|
`#db` defaults to the default ActiveRecord database, but can be specified manually in a few ways:
|
@@ -100,6 +102,10 @@ test:
|
|
100
102
|
min_messages: WARNING
|
101
103
|
</pre>
|
102
104
|
|
105
|
+
## Development
|
106
|
+
|
107
|
+
Check the CONTRIBUTE.md file for instructions running tests with and withour Docker.
|
108
|
+
|
103
109
|
## COPYRIGHT
|
104
110
|
|
105
111
|
See [LICENSE](LICENSE) for details.
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = []
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "database_cleaner-core", "~>2.0
|
21
|
+
spec.add_dependency "database_cleaner-core", "~>2.0"
|
22
22
|
spec.add_dependency "activerecord", ">= 5.a"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler"
|
@@ -29,4 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency "pg"
|
30
30
|
spec.add_development_dependency "sqlite3"
|
31
31
|
spec.add_development_dependency "trilogy"
|
32
|
+
|
33
|
+
spec.metadata["changelog_uri"] = spec.homepage + "/blob/main/CHANGELOG.md"
|
32
34
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
services:
|
2
|
+
postgres:
|
3
|
+
image: postgres:16 # specify the version needed for a given app
|
4
|
+
environment:
|
5
|
+
- POSTGRES_PASSWORD=postgres # this is required
|
6
|
+
ports:
|
7
|
+
- "127.0.0.1:5432:5432" # so we can use `localhost` as the host
|
8
|
+
mysql:
|
9
|
+
image: mysql:5.7
|
10
|
+
environment:
|
11
|
+
- MYSQL_ROOT_PASSWORD=mysql
|
12
|
+
ports:
|
13
|
+
- "127.0.0.1:3306:3306"
|
14
|
+
redis:
|
15
|
+
image: redis:6.2-alpine
|
16
|
+
restart: always
|
17
|
+
ports:
|
18
|
+
- "127.0.0.1:6379:6379"
|
19
|
+
command: redis-server --save 20 1 --loglevel warning
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
services:
|
2
|
+
postgres:
|
3
|
+
image: postgres:16 # specify the version needed for a given app
|
4
|
+
environment:
|
5
|
+
- POSTGRES_PASSWORD=postgres # this is required
|
6
|
+
mysql:
|
7
|
+
image: mysql:5.7
|
8
|
+
environment:
|
9
|
+
- MYSQL_ROOT_PASSWORD=mysql
|
10
|
+
redis:
|
11
|
+
image: redis:6.2-alpine
|
12
|
+
restart: always
|
13
|
+
command: redis-server --save 20 1 --loglevel warning
|
14
|
+
ruby:
|
15
|
+
build:
|
16
|
+
context: .
|
17
|
+
args:
|
18
|
+
BUNDLE_GEMFILE: gemfiles/rails_7.2.gemfile # Manually change this based on the desired Rails version
|
19
|
+
RUBY_VERSION: 3.3 # Manually change this based on the desired Ruby version
|
20
|
+
volumes:
|
21
|
+
- ".:/app:delegated"
|
22
|
+
command: rake
|
23
|
+
depends_on:
|
24
|
+
- mysql
|
25
|
+
- postgres
|
26
|
+
- redis
|
data/gemfiles/rails_6.1.gemfile
CHANGED
@@ -5,6 +5,10 @@ source "https://rubygems.org"
|
|
5
5
|
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
|
6
6
|
gem "rails", "~> 6.1.0"
|
7
7
|
gem "sqlite3", "~> 1.5"
|
8
|
+
gem "concurrent-ruby", "1.3.4"
|
9
|
+
gem "logger"
|
10
|
+
gem "mutex_m"
|
11
|
+
gem "bigdecimal"
|
8
12
|
|
9
13
|
group :test do
|
10
14
|
gem "simplecov", require: false
|
data/gemfiles/rails_7.0.gemfile
CHANGED
@@ -5,6 +5,10 @@ source "https://rubygems.org"
|
|
5
5
|
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
|
6
6
|
gem "rails", "~> 7.0.0"
|
7
7
|
gem "sqlite3", "~> 1.7"
|
8
|
+
gem "concurrent-ruby", "1.3.4"
|
9
|
+
gem "logger"
|
10
|
+
gem "mutex_m"
|
11
|
+
gem "bigdecimal"
|
8
12
|
|
9
13
|
group :test do
|
10
14
|
gem "simplecov", require: false
|
data/gemfiles/rails_7.1.gemfile
CHANGED
@@ -5,6 +5,9 @@ source "https://rubygems.org"
|
|
5
5
|
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
|
6
6
|
gem "rails", "~> 7.1.0"
|
7
7
|
gem "sqlite3", "~> 1.7"
|
8
|
+
gem "logger"
|
9
|
+
gem "mutex_m"
|
10
|
+
gem "bigdecimal"
|
8
11
|
|
9
12
|
group :test do
|
10
13
|
gem "simplecov", require: false
|
data/gemfiles/rails_7.2.gemfile
CHANGED
@@ -3,7 +3,10 @@
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
5
|
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
|
6
|
-
gem "rails", "~> 7.2.0
|
6
|
+
gem "rails", "~> 7.2.0"
|
7
|
+
gem "logger"
|
8
|
+
gem "mutex_m"
|
9
|
+
gem "bigdecimal"
|
7
10
|
|
8
11
|
group :test do
|
9
12
|
gem "simplecov", require: false
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
|
6
|
+
gem "rails", "~> 8.0"
|
7
|
+
gem "logger"
|
8
|
+
gem "mutex_m"
|
9
|
+
gem "bigdecimal"
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem "simplecov", require: false
|
13
|
+
gem "codecov", require: false
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec path: "../"
|
data/gemfiles/rails_edge.gemfile
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
require 'database_cleaner/active_record/truncation'
|
3
|
-
|
4
1
|
module DatabaseCleaner
|
5
2
|
module ActiveRecord
|
6
3
|
class Deletion < Truncation
|
@@ -12,6 +9,8 @@ module DatabaseCleaner
|
|
12
9
|
delete_tables(connection, tables_to_clean(connection))
|
13
10
|
end
|
14
11
|
end
|
12
|
+
|
13
|
+
connection_class.connection_pool.release_connection
|
15
14
|
end
|
16
15
|
|
17
16
|
private
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'database_cleaner/active_record/base'
|
2
|
-
|
3
1
|
module DatabaseCleaner
|
4
2
|
module ActiveRecord
|
5
3
|
class Transaction < Base
|
@@ -24,6 +22,8 @@ module DatabaseCleaner
|
|
24
22
|
connection.rollback_transaction
|
25
23
|
end
|
26
24
|
end
|
25
|
+
|
26
|
+
connection_class.connection_pool.release_connection
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -5,8 +5,8 @@ module DatabaseCleaner
|
|
5
5
|
module ActiveRecord
|
6
6
|
class Truncation < Base
|
7
7
|
def initialize(opts={})
|
8
|
-
if !opts.empty? && !(opts.keys - [:only, :except, :pre_count, :cache_tables, :reset_ids]).empty?
|
9
|
-
raise ArgumentError, "The only valid options are :only, :except, :pre_count, :reset_ids, and :
|
8
|
+
if !opts.empty? && !(opts.keys - [:only, :except, :pre_count, :cache_tables, :reset_ids, :truncate_option]).empty?
|
9
|
+
raise ArgumentError, "The only valid options are :only, :except, :pre_count, :reset_ids, :cache_tables and :truncate_option. You specified #{opts.keys.join(',')}."
|
10
10
|
end
|
11
11
|
|
12
12
|
@only = Array(opts[:only]).dup
|
@@ -14,17 +14,20 @@ module DatabaseCleaner
|
|
14
14
|
|
15
15
|
@reset_ids = opts[:reset_ids]
|
16
16
|
@pre_count = opts[:pre_count]
|
17
|
+
@truncate_option = opts[:truncate_option] || :restrict
|
17
18
|
@cache_tables = opts.has_key?(:cache_tables) ? !!opts[:cache_tables] : true
|
18
19
|
end
|
19
20
|
|
20
21
|
def clean
|
21
22
|
connection.disable_referential_integrity do
|
22
23
|
if pre_count? && connection.respond_to?(:pre_count_truncate_tables)
|
23
|
-
connection.pre_count_truncate_tables(tables_to_clean(connection))
|
24
|
+
connection.pre_count_truncate_tables(tables_to_clean(connection), { truncate_option: @truncate_option })
|
24
25
|
else
|
25
|
-
connection.truncate_tables(tables_to_clean(connection))
|
26
|
+
connection.truncate_tables(tables_to_clean(connection), { truncate_option: @truncate_option })
|
26
27
|
end
|
27
28
|
end
|
29
|
+
|
30
|
+
connection_class.connection_pool.release_connection
|
28
31
|
end
|
29
32
|
|
30
33
|
private
|
@@ -102,14 +105,14 @@ module DatabaseCleaner
|
|
102
105
|
execute("DELETE FROM #{quote_table_name(table_name)}")
|
103
106
|
end
|
104
107
|
|
105
|
-
def truncate_tables(tables)
|
108
|
+
def truncate_tables(tables, opts)
|
106
109
|
tables.each { |t| truncate_table(t) }
|
107
110
|
end
|
108
111
|
end
|
109
112
|
|
110
113
|
module AbstractMysqlAdapter
|
111
|
-
def pre_count_truncate_tables(tables)
|
112
|
-
truncate_tables(pre_count_tables(tables))
|
114
|
+
def pre_count_truncate_tables(tables, opts = {})
|
115
|
+
truncate_tables(pre_count_tables(tables), opts)
|
113
116
|
end
|
114
117
|
|
115
118
|
def pre_count_tables(tables)
|
@@ -152,12 +155,12 @@ module DatabaseCleaner
|
|
152
155
|
end
|
153
156
|
end
|
154
157
|
|
155
|
-
def truncate_tables(tables)
|
158
|
+
def truncate_tables(tables, opts)
|
156
159
|
tables.each { |t| truncate_table(t) }
|
157
160
|
end
|
158
161
|
|
159
|
-
def pre_count_truncate_tables(tables)
|
160
|
-
truncate_tables(pre_count_tables(tables))
|
162
|
+
def pre_count_truncate_tables(tables, opts = {})
|
163
|
+
truncate_tables(pre_count_tables(tables), opts)
|
161
164
|
end
|
162
165
|
|
163
166
|
def pre_count_tables(tables)
|
@@ -193,13 +196,14 @@ module DatabaseCleaner
|
|
193
196
|
tables_with_schema
|
194
197
|
end
|
195
198
|
|
196
|
-
def truncate_tables(table_names)
|
199
|
+
def truncate_tables(table_names, opts)
|
197
200
|
return if table_names.nil? || table_names.empty?
|
198
|
-
|
201
|
+
|
202
|
+
execute("TRUNCATE TABLE #{table_names.map{|name| quote_table_name(name)}.join(', ')} RESTART IDENTITY #{opts[:truncate_option]};")
|
199
203
|
end
|
200
204
|
|
201
|
-
def pre_count_truncate_tables(tables)
|
202
|
-
truncate_tables(pre_count_tables(tables))
|
205
|
+
def pre_count_truncate_tables(tables, opts = {})
|
206
|
+
truncate_tables(pre_count_tables(tables), opts)
|
203
207
|
end
|
204
208
|
|
205
209
|
def pre_count_tables(tables)
|
@@ -1,7 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_record'
|
2
2
|
require 'database_cleaner/core'
|
3
|
-
require 'database_cleaner/active_record/transaction'
|
4
|
-
require 'database_cleaner/active_record/truncation'
|
5
|
-
require 'database_cleaner/active_record/deletion'
|
6
3
|
|
7
|
-
|
4
|
+
ActiveSupport.on_load(:active_record) do
|
5
|
+
require 'database_cleaner/active_record/base'
|
6
|
+
require 'database_cleaner/active_record/transaction'
|
7
|
+
require 'database_cleaner/active_record/truncation'
|
8
|
+
require 'database_cleaner/active_record/deletion'
|
9
|
+
|
10
|
+
DatabaseCleaner[:active_record].strategy = :transaction
|
11
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_cleaner-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernesto Tagwerker
|
8
8
|
- Micah Geisel
|
9
|
-
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2025-07-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: database_cleaner-core
|
@@ -17,14 +16,14 @@ dependencies:
|
|
17
16
|
requirements:
|
18
17
|
- - "~>"
|
19
18
|
- !ruby/object:Gem::Version
|
20
|
-
version: 2.0
|
19
|
+
version: '2.0'
|
21
20
|
type: :runtime
|
22
21
|
prerelease: false
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
24
|
- - "~>"
|
26
25
|
- !ruby/object:Gem::Version
|
27
|
-
version: 2.0
|
26
|
+
version: '2.0'
|
28
27
|
- !ruby/object:Gem::Dependency
|
29
28
|
name: activerecord
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +163,8 @@ files:
|
|
164
163
|
- ".rspec"
|
165
164
|
- Appraisals
|
166
165
|
- CHANGELOG.md
|
166
|
+
- CONTRIBUTE.md
|
167
|
+
- Dockerfile
|
167
168
|
- Gemfile
|
168
169
|
- LICENSE.txt
|
169
170
|
- README.md
|
@@ -171,11 +172,14 @@ files:
|
|
171
172
|
- bin/console
|
172
173
|
- bin/setup
|
173
174
|
- database_cleaner-active_record.gemspec
|
175
|
+
- docker-compose.db.yml
|
176
|
+
- docker-compose.yml
|
174
177
|
- gemfiles/.bundle/config
|
175
178
|
- gemfiles/rails_6.1.gemfile
|
176
179
|
- gemfiles/rails_7.0.gemfile
|
177
180
|
- gemfiles/rails_7.1.gemfile
|
178
181
|
- gemfiles/rails_7.2.gemfile
|
182
|
+
- gemfiles/rails_8.0.gemfile
|
179
183
|
- gemfiles/rails_edge.gemfile
|
180
184
|
- lib/database_cleaner-active_record.rb
|
181
185
|
- lib/database_cleaner/active_record.rb
|
@@ -188,8 +192,8 @@ files:
|
|
188
192
|
homepage: https://github.com/DatabaseCleaner/database_cleaner-active_record
|
189
193
|
licenses:
|
190
194
|
- MIT
|
191
|
-
metadata:
|
192
|
-
|
195
|
+
metadata:
|
196
|
+
changelog_uri: https://github.com/DatabaseCleaner/database_cleaner-active_record/blob/main/CHANGELOG.md
|
193
197
|
rdoc_options: []
|
194
198
|
require_paths:
|
195
199
|
- lib
|
@@ -204,8 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
208
|
- !ruby/object:Gem::Version
|
205
209
|
version: '0'
|
206
210
|
requirements: []
|
207
|
-
rubygems_version: 3.
|
208
|
-
signing_key:
|
211
|
+
rubygems_version: 3.6.2
|
209
212
|
specification_version: 4
|
210
213
|
summary: Strategies for cleaning databases using ActiveRecord. Can be used to ensure
|
211
214
|
a clean state for testing.
|