database_cleaner-active_record 2.0.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +87 -0
- data/Appraisals +24 -4
- data/CHANGELOG.md +22 -0
- data/Gemfile +0 -1
- data/README.md +7 -5
- data/database_cleaner-active_record.gemspec +2 -1
- data/gemfiles/rails_6.1.gemfile +2 -2
- data/gemfiles/{rails_6.0.gemfile → rails_7.0.gemfile} +2 -2
- data/gemfiles/rails_7.1.gemfile +14 -0
- data/gemfiles/{rails_5.1.gemfile → rails_7.2.gemfile} +1 -2
- data/gemfiles/{rails_5.2.gemfile → rails_edge.gemfile} +1 -2
- data/lib/database_cleaner/active_record/base.rb +13 -2
- data/lib/database_cleaner/active_record/deletion.rb +19 -5
- data/lib/database_cleaner/active_record/transaction.rb +12 -4
- data/lib/database_cleaner/active_record/truncation.rb +15 -10
- data/lib/database_cleaner/active_record/version.rb +1 -1
- metadata +26 -10
- data/.travis.yml +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85e54fe3fd85573506fd946df28f0ba19101ca6d854317ea38596e42d7d3e2c8
|
4
|
+
data.tar.gz: 746f002f2a5b7fe97b39550db8d5ac945cc9e7d0ae46a04aafd2001eb214a226
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e823f4e8874d3369dcbce8f3e626cacac42cca7270544a91afda9b8bda3927577c1c85e50d57bf3ec21bce8c7443c65a845c364e404c04a8b3983678cb2e3bfd
|
7
|
+
data.tar.gz: 538b0e24fc2ff9f1756defdac05ce7290e3c2d24bd42f3d6f59c0001364976a183b42fafba7c847c1113f31265889b79614ab00da4c793abcc12d85bea9d4070
|
@@ -0,0 +1,87 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.rails }}, Channel: ${{ matrix.channel }}'
|
8
|
+
runs-on: 'ubuntu-22.04'
|
9
|
+
strategy:
|
10
|
+
fail-fast: false
|
11
|
+
matrix:
|
12
|
+
ruby: ['3.3', '3.2', '3.1']
|
13
|
+
rails: ['6.1', '7.0', '7.1', '7.2']
|
14
|
+
channel: ['stable']
|
15
|
+
|
16
|
+
include:
|
17
|
+
- ruby: 'ruby-head'
|
18
|
+
rails: 'edge'
|
19
|
+
channel: 'experimental'
|
20
|
+
- ruby: 'ruby-head'
|
21
|
+
rails: '7.2'
|
22
|
+
channel: 'experimental'
|
23
|
+
- ruby: 'ruby-head'
|
24
|
+
rails: '7.1'
|
25
|
+
channel: 'experimental'
|
26
|
+
|
27
|
+
- ruby: '3.3'
|
28
|
+
rails: 'edge'
|
29
|
+
channel: 'experimental'
|
30
|
+
- ruby: '3.2'
|
31
|
+
rails: 'edge'
|
32
|
+
channel: 'experimental'
|
33
|
+
- ruby: '3.1'
|
34
|
+
rails: 'edge'
|
35
|
+
channel: 'experimental'
|
36
|
+
|
37
|
+
exclude:
|
38
|
+
- ruby: '3.3'
|
39
|
+
rails: '7.0' # TODO: works on 7-0-stable branch, remove after a 7.0.x patch release
|
40
|
+
- ruby: '3.3'
|
41
|
+
rails: '6.1'
|
42
|
+
|
43
|
+
- ruby: '3.2'
|
44
|
+
rails: '6.1'
|
45
|
+
|
46
|
+
continue-on-error: ${{ matrix.channel != 'stable' }}
|
47
|
+
|
48
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
49
|
+
BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile
|
50
|
+
steps:
|
51
|
+
- uses: actions/checkout@v4
|
52
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
53
|
+
uses: ruby/setup-ruby@v1
|
54
|
+
with:
|
55
|
+
ruby-version: ${{ matrix.ruby }}
|
56
|
+
bundler-cache: true # 'bundle install' and cache
|
57
|
+
rubygems: ${{ matrix.ruby == '2.5' && 'default' || 'latest' }}
|
58
|
+
- name: Copy config file
|
59
|
+
run: cp spec/support/sample.config.yml spec/support/config.yml
|
60
|
+
- name: Run tests
|
61
|
+
run: bundle exec rake
|
62
|
+
|
63
|
+
services:
|
64
|
+
mysql:
|
65
|
+
image: mysql:5.7
|
66
|
+
env:
|
67
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
68
|
+
ports:
|
69
|
+
- 3306:3306
|
70
|
+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
71
|
+
|
72
|
+
postgres:
|
73
|
+
# Docker Hub image
|
74
|
+
image: postgres
|
75
|
+
# Provide the password for postgres
|
76
|
+
env:
|
77
|
+
POSTGRES_USER: postgres
|
78
|
+
POSTGRES_PASSWORD: postgres
|
79
|
+
ports:
|
80
|
+
- 5432:5432
|
81
|
+
# Set health checks to wait until postgres has started
|
82
|
+
options: >-
|
83
|
+
--health-cmd pg_isready
|
84
|
+
--health-interval 10s
|
85
|
+
--health-timeout 5s
|
86
|
+
--health-retries 5
|
87
|
+
|
data/Appraisals
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
appraise "rails-5.1" do
|
2
|
-
gem "rails", "~>5.1.0"
|
2
|
+
gem "rails", "~> 5.1.0"
|
3
3
|
end
|
4
4
|
|
5
5
|
appraise "rails-5.2" do
|
6
|
-
gem "rails", "~>5.2.0"
|
6
|
+
gem "rails", "~> 5.2.0"
|
7
7
|
end
|
8
8
|
|
9
9
|
appraise "rails-6.0" do
|
10
|
-
gem "rails", "~>6.0.0"
|
10
|
+
gem "rails", "~> 6.0.0"
|
11
|
+
gem "sqlite3", "~> 1.5"
|
11
12
|
end
|
12
13
|
|
13
14
|
appraise "rails-6.1" do
|
14
|
-
gem "rails", "~>6.1.0"
|
15
|
+
gem "rails", "~> 6.1.0"
|
16
|
+
gem "sqlite3", "~> 1.5"
|
17
|
+
end
|
18
|
+
|
19
|
+
appraise "rails-7.0" do
|
20
|
+
gem "rails", "~> 7.0.0"
|
21
|
+
gem "sqlite3", "~> 1.7"
|
22
|
+
end
|
23
|
+
|
24
|
+
appraise "rails-7.1" do
|
25
|
+
gem "rails", "~> 7.1.0"
|
26
|
+
gem "sqlite3", "~> 1.7" # FIXME: remove after rails/rails#51592
|
27
|
+
end
|
28
|
+
|
29
|
+
appraise "rails-7.2" do
|
30
|
+
gem "rails", "~> 7.2.0.beta2"
|
31
|
+
end
|
32
|
+
|
33
|
+
appraise "rails-edge" do
|
34
|
+
gem "rails", github: "rails/rails"
|
15
35
|
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Development (unreleased)
|
2
|
+
|
3
|
+
## v2.2.0 2024-07-12
|
4
|
+
|
5
|
+
* Fix "ERROR: currval of sequence" in Postgres adapter: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/103
|
6
|
+
* Use lock synchronize on transaction callback: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/73
|
7
|
+
* Stop testing with EOLed Ruby & Rails versions: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/105
|
8
|
+
* Fix compatibility issue with Rails 7.2: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/107
|
9
|
+
* Fix typo in truncation methods: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/94/files
|
10
|
+
* Address deprecation of ActiveRecord::Base.connection in Rails 7.2: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/102
|
11
|
+
* Support Rails 7.2+: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/101
|
12
|
+
* Fix reset_ids test with Trilogy adapter: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/93
|
13
|
+
* Implement resetting ids for deletion strategy: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/71
|
14
|
+
* Avoid loading ActiveRecord::Base early: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/91
|
15
|
+
* Fix specs to account for trilogy: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/88
|
16
|
+
* Add basic support for trilogy: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/85
|
17
|
+
|
18
|
+
## v2.1.0 2023-02-17
|
19
|
+
|
20
|
+
* Add Ruby 3.2 to CI matrix: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/79
|
21
|
+
* 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
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Database Cleaner Adapter for ActiveRecord
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Tests](https://github.com/DatabaseCleaner/database_cleaner-active_record/actions/workflows/ci.yml/badge.svg)](https://github.com/DatabaseCleaner/database_cleaner-active_record/actions/workflows/ci.yml)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner-active_record/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner-active_record)
|
5
5
|
[![codecov](https://codecov.io/gh/DatabaseCleaner/database_cleaner-active_record/branch/master/graph/badge.svg)](https://codecov.io/gh/DatabaseCleaner/database_cleaner-active_record)
|
6
6
|
|
@@ -8,7 +8,7 @@ Clean your ActiveRecord databases with Database Cleaner.
|
|
8
8
|
|
9
9
|
See https://github.com/DatabaseCleaner/database_cleaner for more information.
|
10
10
|
|
11
|
-
For support or to discuss development please use
|
11
|
+
For support or to discuss development please use GitHub Issues.
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
@@ -51,16 +51,18 @@ The truncation and deletion strategies may accept the following options:
|
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
# Only truncate the "users" table.
|
54
|
-
DatabaseCleaner[:active_record].strategy =
|
54
|
+
DatabaseCleaner[:active_record].strategy = DatabaseCleaner::ActiveRecord::Truncation.new(only: ["users"])
|
55
55
|
|
56
56
|
# Delete all tables except the "users" table.
|
57
|
-
DatabaseCleaner[:active_record].strategy =
|
57
|
+
DatabaseCleaner[:active_record].strategy = DatabaseCleaner::ActiveRecord::Deletion.new(except: ["users"])
|
58
58
|
```
|
59
59
|
|
60
60
|
* `:pre_count` - When set to `true` this will check each table for existing rows before truncating or deleting it. This can speed up test suites when many of the tables are never populated. Defaults to `false`. (Also, see the section on [What strategy is fastest?](#what-strategy-is-fastest))
|
61
61
|
|
62
62
|
* `:cache_tables` - When set to `true` the list of tables to truncate or delete from will only be read from the DB once, otherwise it will be read before each cleanup run. Set this to `false` if (1) you create and drop tables in your tests, or (2) you change Postgres schemas (`ActiveRecord::Base.connection.schema_search_path`) in your tests (for example, in a multitenancy setup with each tenant in a different Postgres schema). Defaults to `true`.
|
63
63
|
|
64
|
+
* `:reset_ids` - Only valid for deletion strategy, when set to `true` resets ids to 1 after each table is cleaned.
|
65
|
+
|
64
66
|
## Adapter configuration options
|
65
67
|
|
66
68
|
`#db` defaults to the default ActiveRecord database, but can be specified manually in a few ways:
|
@@ -95,7 +97,7 @@ You can also add this parameter to your database.yml file:
|
|
95
97
|
test:
|
96
98
|
adapter: postgresql
|
97
99
|
# ...
|
98
|
-
min_messages: WARNING
|
100
|
+
min_messages: WARNING
|
99
101
|
</pre>
|
100
102
|
|
101
103
|
## COPYRIGHT
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
f.match(%r{^(test|spec|features)/})
|
16
16
|
end
|
17
17
|
spec.bindir = "exe"
|
18
|
-
spec.executables =
|
18
|
+
spec.executables = []
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "database_cleaner-core", "~>2.0.0"
|
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "mysql2"
|
29
29
|
spec.add_development_dependency "pg"
|
30
30
|
spec.add_development_dependency "sqlite3"
|
31
|
+
spec.add_development_dependency "trilogy"
|
31
32
|
end
|
data/gemfiles/rails_6.1.gemfile
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
5
|
gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
|
6
|
-
gem "rails", "~>6.1.0"
|
7
|
-
gem "
|
6
|
+
gem "rails", "~> 6.1.0"
|
7
|
+
gem "sqlite3", "~> 1.5"
|
8
8
|
|
9
9
|
group :test do
|
10
10
|
gem "simplecov", require: false
|
@@ -3,8 +3,8 @@
|
|
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
|
-
gem "
|
6
|
+
gem "rails", "~> 7.0.0"
|
7
|
+
gem "sqlite3", "~> 1.7"
|
8
8
|
|
9
9
|
group :test do
|
10
10
|
gem "simplecov", require: false
|
@@ -0,0 +1,14 @@
|
|
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", "~> 7.1.0"
|
7
|
+
gem "sqlite3", "~> 1.7"
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem "simplecov", require: false
|
11
|
+
gem "codecov", require: false
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -15,7 +15,13 @@ module DatabaseCleaner
|
|
15
15
|
|
16
16
|
class Base < DatabaseCleaner::Strategy
|
17
17
|
def self.migration_table_name
|
18
|
-
::ActiveRecord::
|
18
|
+
if ::ActiveRecord::Base.connection_pool.respond_to?(:schema_migration) # Rails >= 7.2
|
19
|
+
::ActiveRecord::Base.connection_pool.schema_migration.table_name
|
20
|
+
elsif ::ActiveRecord::Base.connection.respond_to?(:schema_migration) # Rails >= 6.0
|
21
|
+
::ActiveRecord::Base.connection.schema_migration.table_name
|
22
|
+
else
|
23
|
+
::ActiveRecord::SchemaMigration.table_name
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
27
|
def self.exclusion_condition(column_name)
|
@@ -46,7 +52,12 @@ module DatabaseCleaner
|
|
46
52
|
|
47
53
|
def load_config
|
48
54
|
if db != :default && db.is_a?(Symbol) && File.file?(DatabaseCleaner::ActiveRecord.config_file_location)
|
49
|
-
connection_details =
|
55
|
+
connection_details =
|
56
|
+
if RUBY_VERSION.match?(/\A2\.5/)
|
57
|
+
YAML.safe_load(ERB.new(IO.read(DatabaseCleaner::ActiveRecord.config_file_location)).result, [], [], true)
|
58
|
+
else
|
59
|
+
YAML.safe_load(ERB.new(IO.read(DatabaseCleaner::ActiveRecord.config_file_location)).result, aliases: true)
|
60
|
+
end
|
50
61
|
@connection_hash = valid_config(connection_details, db.to_s)
|
51
62
|
end
|
52
63
|
end
|
@@ -7,9 +7,9 @@ module DatabaseCleaner
|
|
7
7
|
def clean
|
8
8
|
connection.disable_referential_integrity do
|
9
9
|
if pre_count? && connection.respond_to?(:pre_count_tables)
|
10
|
-
delete_tables(connection, connection.pre_count_tables(
|
10
|
+
delete_tables(connection, connection.pre_count_tables(tables_to_clean(connection)))
|
11
11
|
else
|
12
|
-
delete_tables(connection,
|
12
|
+
delete_tables(connection, tables_to_clean(connection))
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -19,14 +19,28 @@ module DatabaseCleaner
|
|
19
19
|
def delete_tables(connection, table_names)
|
20
20
|
table_names.each do |table_name|
|
21
21
|
delete_table(connection, table_name)
|
22
|
+
reset_id_sequence(connection, table_name) if @reset_ids
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
26
|
def delete_table connection, table_name
|
26
|
-
connection.execute("DELETE FROM #{connection.quote_table_name(table_name)}")
|
27
|
+
connection.execute("DELETE FROM #{connection.quote_table_name(table_name)} WHERE 1=1")
|
27
28
|
end
|
28
29
|
|
29
|
-
def
|
30
|
+
def reset_id_sequence connection, table_name
|
31
|
+
case connection.adapter_name
|
32
|
+
when 'Mysql2', 'Trilogy'
|
33
|
+
connection.execute("ALTER TABLE #{table_name} AUTO_INCREMENT = 1;")
|
34
|
+
when 'SQLite'
|
35
|
+
connection.execute("delete from sqlite_sequence where name='#{table_name}';")
|
36
|
+
when 'PostgreSQL'
|
37
|
+
connection.reset_pk_sequence!(table_name)
|
38
|
+
else
|
39
|
+
raise "reset_id option not supported for #{connection.adapter_name}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def tables_to_clean(connection)
|
30
44
|
if information_schema_exists?(connection)
|
31
45
|
@except += connection.database_cleaner_view_cache + migration_storage_names
|
32
46
|
(@only.any? ? @only : tables_with_new_rows(connection)) - @except
|
@@ -64,7 +78,7 @@ module DatabaseCleaner
|
|
64
78
|
end
|
65
79
|
|
66
80
|
def information_schema_exists? connection
|
67
|
-
connection.adapter_name
|
81
|
+
["Mysql2", "Trilogy"].include?(connection.adapter_name)
|
68
82
|
end
|
69
83
|
end
|
70
84
|
end
|
@@ -4,17 +4,25 @@ module DatabaseCleaner
|
|
4
4
|
module ActiveRecord
|
5
5
|
class Transaction < Base
|
6
6
|
def start
|
7
|
+
connection = if ::ActiveRecord.version >= Gem::Version.new("7.2")
|
8
|
+
connection_class.lease_connection
|
9
|
+
else
|
10
|
+
connection_class.connection
|
11
|
+
end
|
12
|
+
|
7
13
|
# Hack to make sure that the connection is properly set up before cleaning
|
8
|
-
|
14
|
+
connection.transaction {}
|
9
15
|
|
10
|
-
|
16
|
+
connection.begin_transaction joinable: false
|
11
17
|
end
|
12
18
|
|
13
19
|
|
14
20
|
def clean
|
15
21
|
connection_class.connection_pool.connections.each do |connection|
|
16
|
-
|
17
|
-
|
22
|
+
connection.lock.synchronize do
|
23
|
+
next unless connection.open_transactions > 0
|
24
|
+
connection.rollback_transaction
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
20
28
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require "delegate"
|
2
|
-
require 'active_record/base'
|
3
2
|
require 'database_cleaner/active_record/base'
|
4
3
|
|
5
4
|
module DatabaseCleaner
|
6
5
|
module ActiveRecord
|
7
6
|
class Truncation < Base
|
8
7
|
def initialize(opts={})
|
9
|
-
if !opts.empty? && !(opts.keys - [:only, :except, :pre_count, :cache_tables]).empty?
|
10
|
-
raise ArgumentError, "The only valid options are :only, :except, :pre_count, and :cache_tables. You specified #{opts.keys.join(',')}."
|
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 :cache_tables. You specified #{opts.keys.join(',')}."
|
11
10
|
end
|
12
11
|
|
13
12
|
@only = Array(opts[:only]).dup
|
14
13
|
@except = Array(opts[:except]).dup
|
15
14
|
|
15
|
+
@reset_ids = opts[:reset_ids]
|
16
16
|
@pre_count = opts[:pre_count]
|
17
17
|
@cache_tables = opts.has_key?(:cache_tables) ? !!opts[:cache_tables] : true
|
18
18
|
end
|
@@ -20,9 +20,9 @@ module DatabaseCleaner
|
|
20
20
|
def clean
|
21
21
|
connection.disable_referential_integrity do
|
22
22
|
if pre_count? && connection.respond_to?(:pre_count_truncate_tables)
|
23
|
-
connection.pre_count_truncate_tables(
|
23
|
+
connection.pre_count_truncate_tables(tables_to_clean(connection))
|
24
24
|
else
|
25
|
-
connection.truncate_tables(
|
25
|
+
connection.truncate_tables(tables_to_clean(connection))
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -30,10 +30,16 @@ module DatabaseCleaner
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def connection
|
33
|
-
@connection ||= ConnectionWrapper.new(
|
33
|
+
@connection ||= ConnectionWrapper.new(
|
34
|
+
if ::ActiveRecord.version >= Gem::Version.new("7.2")
|
35
|
+
connection_class.lease_connection
|
36
|
+
else
|
37
|
+
connection_class.connection
|
38
|
+
end
|
39
|
+
)
|
34
40
|
end
|
35
41
|
|
36
|
-
def
|
42
|
+
def tables_to_clean(connection)
|
37
43
|
if @only.none?
|
38
44
|
all_tables = cache_tables? ? connection.database_cleaner_table_cache : connection.database_tables
|
39
45
|
@only = all_tables.map { |table| table.split(".").last }
|
@@ -62,7 +68,7 @@ module DatabaseCleaner
|
|
62
68
|
def initialize(connection)
|
63
69
|
extend AbstractAdapter
|
64
70
|
case connection.adapter_name
|
65
|
-
when "Mysql2"
|
71
|
+
when "Mysql2", "Trilogy"
|
66
72
|
extend AbstractMysqlAdapter
|
67
73
|
when "SQLite"
|
68
74
|
extend AbstractMysqlAdapter
|
@@ -218,7 +224,7 @@ module DatabaseCleaner
|
|
218
224
|
def has_been_used?(table)
|
219
225
|
return has_rows?(table) unless has_sequence?(table)
|
220
226
|
|
221
|
-
cur_val = select_value("SELECT
|
227
|
+
cur_val = select_value("SELECT last_value from #{table}_id_seq;").to_i
|
222
228
|
cur_val > 0
|
223
229
|
end
|
224
230
|
|
@@ -246,4 +252,3 @@ module DatabaseCleaner
|
|
246
252
|
private_constant :ConnectionWrapper
|
247
253
|
end
|
248
254
|
end
|
249
|
-
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_cleaner-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernesto Tagwerker
|
8
8
|
- Micah Geisel
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: database_cleaner-core
|
@@ -137,6 +137,20 @@ dependencies:
|
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: trilogy
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
140
154
|
description: Strategies for cleaning databases using ActiveRecord. Can be used to
|
141
155
|
ensure a clean state for testing.
|
142
156
|
email:
|
@@ -145,10 +159,11 @@ executables: []
|
|
145
159
|
extensions: []
|
146
160
|
extra_rdoc_files: []
|
147
161
|
files:
|
162
|
+
- ".github/workflows/ci.yml"
|
148
163
|
- ".gitignore"
|
149
164
|
- ".rspec"
|
150
|
-
- ".travis.yml"
|
151
165
|
- Appraisals
|
166
|
+
- CHANGELOG.md
|
152
167
|
- Gemfile
|
153
168
|
- LICENSE.txt
|
154
169
|
- README.md
|
@@ -157,10 +172,11 @@ files:
|
|
157
172
|
- bin/setup
|
158
173
|
- database_cleaner-active_record.gemspec
|
159
174
|
- gemfiles/.bundle/config
|
160
|
-
- gemfiles/rails_5.1.gemfile
|
161
|
-
- gemfiles/rails_5.2.gemfile
|
162
|
-
- gemfiles/rails_6.0.gemfile
|
163
175
|
- gemfiles/rails_6.1.gemfile
|
176
|
+
- gemfiles/rails_7.0.gemfile
|
177
|
+
- gemfiles/rails_7.1.gemfile
|
178
|
+
- gemfiles/rails_7.2.gemfile
|
179
|
+
- gemfiles/rails_edge.gemfile
|
164
180
|
- lib/database_cleaner-active_record.rb
|
165
181
|
- lib/database_cleaner/active_record.rb
|
166
182
|
- lib/database_cleaner/active_record/base.rb
|
@@ -173,7 +189,7 @@ homepage: https://github.com/DatabaseCleaner/database_cleaner-active_record
|
|
173
189
|
licenses:
|
174
190
|
- MIT
|
175
191
|
metadata: {}
|
176
|
-
post_install_message:
|
192
|
+
post_install_message:
|
177
193
|
rdoc_options: []
|
178
194
|
require_paths:
|
179
195
|
- lib
|
@@ -188,8 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
204
|
- !ruby/object:Gem::Version
|
189
205
|
version: '0'
|
190
206
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
192
|
-
signing_key:
|
207
|
+
rubygems_version: 3.5.10
|
208
|
+
signing_key:
|
193
209
|
specification_version: 4
|
194
210
|
summary: Strategies for cleaning databases using ActiveRecord. Can be used to ensure
|
195
211
|
a clean state for testing.
|
data/.travis.yml
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
services:
|
3
|
-
- mysql
|
4
|
-
- postgresql
|
5
|
-
rvm:
|
6
|
-
- 2.5
|
7
|
-
- 2.6
|
8
|
-
- 2.7
|
9
|
-
- 3.0
|
10
|
-
gemfile:
|
11
|
-
- gemfiles/rails_5.1.gemfile
|
12
|
-
- gemfiles/rails_5.2.gemfile
|
13
|
-
- gemfiles/rails_6.0.gemfile
|
14
|
-
- gemfiles/rails_6.1.gemfile
|
15
|
-
jobs:
|
16
|
-
exclude: # Unsupported combos: https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html
|
17
|
-
- rvm: 3.0
|
18
|
-
gemfiles/rails_5.1.gemfile
|
19
|
-
- rvm: 3.0
|
20
|
-
gemfiles/rails_5.2.gemfile
|
21
|
-
|
22
|
-
before_install:
|
23
|
-
- bin/setup
|
24
|
-
cache:
|
25
|
-
bundler: true
|