database_cleaner-active_record 2.2.0 → 2.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85e54fe3fd85573506fd946df28f0ba19101ca6d854317ea38596e42d7d3e2c8
4
- data.tar.gz: 746f002f2a5b7fe97b39550db8d5ac945cc9e7d0ae46a04aafd2001eb214a226
3
+ metadata.gz: 1c30dde1a5104c77a1bf907b7d5d5bb8aa187776246b8b02639d0ea8e352fd1d
4
+ data.tar.gz: 982552da4f5c169ddf5a0d16c9703eb2b73623e1330c476dd8116683409951fd
5
5
  SHA512:
6
- metadata.gz: e823f4e8874d3369dcbce8f3e626cacac42cca7270544a91afda9b8bda3927577c1c85e50d57bf3ec21bce8c7443c65a845c364e404c04a8b3983678cb2e3bfd
7
- data.tar.gz: 538b0e24fc2ff9f1756defdac05ce7290e3c2d24bd42f3d6f59c0001364976a183b42fafba7c847c1113f31265889b79614ab00da4c793abcc12d85bea9d4070
6
+ metadata.gz: 9d46caf98521a0a53b67655e1eb55947108b13cf37b2ce8398fcdc53f34b334c51fa34acf65135c04689a1022394a396dc0648c0406d2d92a147c005bf488551
7
+ data.tar.gz: fd15224bc593acc67996d9a2c04840df1e95d3eafb49a68ba6d73dd64c0e92cd6984d9bb7b972ed7d6ef6063d67cd918ba1474630c8675520e932ef57c267108
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,11 @@
1
1
  # Development (unreleased)
2
2
 
3
+ ## v2.2.1 2025-05-13
4
+
5
+ * https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/111 by @tagliala
6
+ * https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/104 by @fatkodima
7
+ * https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/118 by @pat, @thegeorgeous, and @nnishimura
8
+
3
9
  ## v2.2.0 2024-07-12
4
10
 
5
11
  * Fix "ERROR: currval of sequence" in Postgres adapter: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/103
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:
@@ -1,4 +1,3 @@
1
- require 'active_record'
2
1
  require 'database_cleaner/strategy'
3
2
  require 'erb'
4
3
  require 'yaml'
@@ -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
@@ -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
@@ -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 :cache_tables. You specified #{opts.keys.join(',')}."
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,6 +14,7 @@ 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
 
@@ -22,7 +23,7 @@ module DatabaseCleaner
22
23
  if pre_count? && connection.respond_to?(:pre_count_truncate_tables)
23
24
  connection.pre_count_truncate_tables(tables_to_clean(connection))
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
28
29
  end
@@ -102,7 +103,7 @@ module DatabaseCleaner
102
103
  execute("DELETE FROM #{quote_table_name(table_name)}")
103
104
  end
104
105
 
105
- def truncate_tables(tables)
106
+ def truncate_tables(tables, opts)
106
107
  tables.each { |t| truncate_table(t) }
107
108
  end
108
109
  end
@@ -152,7 +153,7 @@ module DatabaseCleaner
152
153
  end
153
154
  end
154
155
 
155
- def truncate_tables(tables)
156
+ def truncate_tables(tables, opts)
156
157
  tables.each { |t| truncate_table(t) }
157
158
  end
158
159
 
@@ -193,9 +194,10 @@ module DatabaseCleaner
193
194
  tables_with_schema
194
195
  end
195
196
 
196
- def truncate_tables(table_names)
197
+ def truncate_tables(table_names, opts)
197
198
  return if table_names.nil? || table_names.empty?
198
- execute("TRUNCATE TABLE #{table_names.map{|name| quote_table_name(name)}.join(', ')} RESTART IDENTITY RESTRICT;")
199
+
200
+ execute("TRUNCATE TABLE #{table_names.map{|name| quote_table_name(name)}.join(', ')} RESTART IDENTITY #{opts[:truncate_option]};")
199
201
  end
200
202
 
201
203
  def pre_count_truncate_tables(tables)
@@ -1,5 +1,5 @@
1
1
  module DatabaseCleaner
2
2
  module ActiveRecord
3
- VERSION = "2.2.0"
3
+ VERSION = "2.2.1"
4
4
  end
5
5
  end
@@ -1,7 +1,11 @@
1
- require 'database_cleaner/active_record/version'
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
- DatabaseCleaner[:active_record].strategy = :transaction
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.0
4
+ version: 2.2.1
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: 2024-07-12 00:00:00.000000000 Z
11
+ date: 2025-05-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: database_cleaner-core
@@ -189,7 +188,6 @@ homepage: https://github.com/DatabaseCleaner/database_cleaner-active_record
189
188
  licenses:
190
189
  - MIT
191
190
  metadata: {}
192
- post_install_message:
193
191
  rdoc_options: []
194
192
  require_paths:
195
193
  - lib
@@ -204,8 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
202
  - !ruby/object:Gem::Version
205
203
  version: '0'
206
204
  requirements: []
207
- rubygems_version: 3.5.10
208
- signing_key:
205
+ rubygems_version: 3.6.2
209
206
  specification_version: 4
210
207
  summary: Strategies for cleaning databases using ActiveRecord. Can be used to ensure
211
208
  a clean state for testing.