database_cleaner-active_record 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 997c59d22ce3ef9178c0b69c3d30b98d2e1126ddf099b5630bf0fbc272c76280
4
- data.tar.gz: c8fc2baa15ceb2d6efb1b6b3a0890868dad0b5b51c78929b39564cc6e2be0c0f
3
+ metadata.gz: 85e54fe3fd85573506fd946df28f0ba19101ca6d854317ea38596e42d7d3e2c8
4
+ data.tar.gz: 746f002f2a5b7fe97b39550db8d5ac945cc9e7d0ae46a04aafd2001eb214a226
5
5
  SHA512:
6
- metadata.gz: 6ddd99b203a2a712c8adbf01de42dbc751894ffe52f61cc540ebc116ceb9efc0ad8bb7cdeba08630d77b6754ac81fcad19adb1031d9c84bb4d7cbfcddd250675
7
- data.tar.gz: fd9f66f85aa80d0247f9bbb753aad05d58b129723d36676ef09927091630a6e65025180dbb01fb7e9d31f4180933df5f98103c98ba71b0f4f2ff9ea639e31916
6
+ metadata.gz: e823f4e8874d3369dcbce8f3e626cacac42cca7270544a91afda9b8bda3927577c1c85e50d57bf3ec21bce8c7443c65a845c364e404c04a8b3983678cb2e3bfd
7
+ data.tar.gz: 538b0e24fc2ff9f1756defdac05ce7290e3c2d24bd42f3d6f59c0001364976a183b42fafba7c847c1113f31265889b79614ab00da4c793abcc12d85bea9d4070
@@ -4,44 +4,51 @@ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  test:
7
- name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.rails }}'
7
+ name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.rails }}, Channel: ${{ matrix.channel }}'
8
8
  runs-on: 'ubuntu-22.04'
9
9
  strategy:
10
10
  fail-fast: false
11
11
  matrix:
12
- ruby: ['3.2', '3.1', '3.0', '2.7', '2.6', '2.5']
13
- rails: ['5.1', '5.2', '6.0', '6.1', '7.0', '7.1']
14
- exclude:
15
- - ruby: '3.2'
16
- rails: '5.1'
17
- - ruby: '3.2'
18
- rails: '5.2'
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'
19
30
  - ruby: '3.2'
20
- rails: '6.0'
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
+
21
43
  - ruby: '3.2'
22
44
  rails: '6.1'
23
- - ruby: '3.1'
24
- rails: '5.1'
25
- - ruby: '3.1'
26
- rails: '5.2'
27
- - ruby: '3.1'
28
- rails: '6.0'
29
- - ruby: '3.0'
30
- rails: '5.1'
31
- - ruby: '3.0'
32
- rails: '5.2'
33
- - ruby: '2.6'
34
- rails: '7.0'
35
- - ruby: '2.5'
36
- rails: '7.0'
37
- - ruby: '2.5'
38
- rails: '7.1'
39
- - ruby: '2.6'
40
- rails: '7.1'
45
+
46
+ continue-on-error: ${{ matrix.channel != 'stable' }}
47
+
41
48
  env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
42
49
  BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile
43
50
  steps:
44
- - uses: actions/checkout@v3
51
+ - uses: actions/checkout@v4
45
52
  - name: Set up Ruby ${{ matrix.ruby }}
46
53
  uses: ruby/setup-ruby@v1
47
54
  with:
data/Appraisals CHANGED
@@ -8,16 +8,28 @@ end
8
8
 
9
9
  appraise "rails-6.0" do
10
10
  gem "rails", "~> 6.0.0"
11
+ gem "sqlite3", "~> 1.5"
11
12
  end
12
13
 
13
14
  appraise "rails-6.1" do
14
15
  gem "rails", "~> 6.1.0"
16
+ gem "sqlite3", "~> 1.5"
15
17
  end
16
18
 
17
19
  appraise "rails-7.0" do
18
20
  gem "rails", "~> 7.0.0"
21
+ gem "sqlite3", "~> 1.7"
19
22
  end
20
23
 
21
24
  appraise "rails-7.1" do
22
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"
23
35
  end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Development (unreleased)
2
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
+
3
18
  ## v2.1.0 2023-02-17
4
19
 
5
20
  * Add Ruby 3.2 to CI matrix: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/79
data/README.md CHANGED
@@ -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 the [Google Group](https://groups.google.com/group/database_cleaner).
11
+ For support or to discuss development please use GitHub Issues.
12
12
 
13
13
  ## Installation
14
14
 
@@ -61,6 +61,8 @@ DatabaseCleaner[:active_record].strategy = DatabaseCleaner::ActiveRecord::Deleti
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
@@ -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
@@ -4,17 +4,11 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
6
6
  gem "rails", "~> 6.1.0"
7
+ gem "sqlite3", "~> 1.5"
7
8
 
8
9
  group :test do
9
10
  gem "simplecov", require: false
10
11
  gem "codecov", require: false
11
12
  end
12
13
 
13
- if RUBY_VERSION >= '3.1'
14
- gem 'net-smtp', require: false
15
- gem 'net-imap', require: false
16
- gem 'net-pop', require: false
17
- end
18
-
19
-
20
14
  gemspec path: "../"
@@ -4,6 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
6
6
  gem "rails", "~> 7.0.0"
7
+ gem "sqlite3", "~> 1.7"
7
8
 
8
9
  group :test do
9
10
  gem "simplecov", require: false
@@ -3,7 +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", github: 'rails/rails' # "~> 7.1.0"
6
+ gem "rails", "~> 7.1.0"
7
+ gem "sqlite3", "~> 1.7"
7
8
 
8
9
  group :test do
9
10
  gem "simplecov", require: false
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
6
- gem "rails", "~> 5.1.0"
6
+ gem "rails", "~> 7.2.0.beta2"
7
7
 
8
8
  group :test do
9
9
  gem "simplecov", require: false
@@ -3,7 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "database_cleaner-core", git: "https://github.com/DatabaseCleaner/database_cleaner"
6
- gem "rails", "~> 5.2.0"
6
+ gem "rails", github: "rails/rails"
7
7
 
8
8
  group :test do
9
9
  gem "simplecov", require: false
@@ -15,7 +15,9 @@ module DatabaseCleaner
15
15
 
16
16
  class Base < DatabaseCleaner::Strategy
17
17
  def self.migration_table_name
18
- if Gem::Version.new("6.0.0") <= ::ActiveRecord.version
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
19
21
  ::ActiveRecord::Base.connection.schema_migration.table_name
20
22
  else
21
23
  ::ActiveRecord::SchemaMigration.table_name
@@ -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(tables_to_truncate(connection)))
10
+ delete_tables(connection, connection.pre_count_tables(tables_to_clean(connection)))
11
11
  else
12
- delete_tables(connection, tables_to_truncate(connection))
12
+ delete_tables(connection, tables_to_clean(connection))
13
13
  end
14
14
  end
15
15
  end
@@ -19,6 +19,7 @@ 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
 
@@ -26,7 +27,20 @@ module DatabaseCleaner
26
27
  connection.execute("DELETE FROM #{connection.quote_table_name(table_name)} WHERE 1=1")
27
28
  end
28
29
 
29
- def tables_to_truncate(connection)
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 == "Mysql2"
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
- connection_class.connection.transaction {}
14
+ connection.transaction {}
9
15
 
10
- connection_class.connection.begin_transaction joinable: false
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
- next unless connection.open_transactions > 0
17
- connection.rollback_transaction
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(tables_to_truncate(connection))
23
+ connection.pre_count_truncate_tables(tables_to_clean(connection))
24
24
  else
25
- connection.truncate_tables(tables_to_truncate(connection))
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(connection_class.connection)
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 tables_to_truncate(connection)
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 currval('#{table}_id_seq');").to_i rescue 0
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
-
@@ -1,5 +1,5 @@
1
1
  module DatabaseCleaner
2
2
  module ActiveRecord
3
- VERSION = "2.1.0"
3
+ VERSION = "2.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: database_cleaner-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernesto Tagwerker
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-02-17 00:00:00.000000000 Z
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:
@@ -148,7 +162,6 @@ files:
148
162
  - ".github/workflows/ci.yml"
149
163
  - ".gitignore"
150
164
  - ".rspec"
151
- - ".travis.yml"
152
165
  - Appraisals
153
166
  - CHANGELOG.md
154
167
  - Gemfile
@@ -159,12 +172,11 @@ files:
159
172
  - bin/setup
160
173
  - database_cleaner-active_record.gemspec
161
174
  - gemfiles/.bundle/config
162
- - gemfiles/rails_5.1.gemfile
163
- - gemfiles/rails_5.2.gemfile
164
- - gemfiles/rails_6.0.gemfile
165
175
  - gemfiles/rails_6.1.gemfile
166
176
  - gemfiles/rails_7.0.gemfile
167
177
  - gemfiles/rails_7.1.gemfile
178
+ - gemfiles/rails_7.2.gemfile
179
+ - gemfiles/rails_edge.gemfile
168
180
  - lib/database_cleaner-active_record.rb
169
181
  - lib/database_cleaner/active_record.rb
170
182
  - lib/database_cleaner/active_record/base.rb
@@ -192,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
204
  - !ruby/object:Gem::Version
193
205
  version: '0'
194
206
  requirements: []
195
- rubygems_version: 3.0.3
207
+ rubygems_version: 3.5.10
196
208
  signing_key:
197
209
  specification_version: 4
198
210
  summary: Strategies for cleaning databases using ActiveRecord. Can be used to ensure
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
- gemfile: gemfiles/rails_5.1.gemfile
19
- - rvm: 3.0
20
- gemfile: gemfiles/rails_5.2.gemfile
21
-
22
- before_install:
23
- - bin/setup
24
- cache:
25
- bundler: true
@@ -1,13 +0,0 @@
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", "~> 6.0.0"
7
-
8
- group :test do
9
- gem "simplecov", require: false
10
- gem "codecov", require: false
11
- end
12
-
13
- gemspec path: "../"