Skip to content

Commit f625783

Browse files
etagwerkerarieljnerdrew
authored
Fixes Issue #120 (#121)
* Fixes #120 * Add a reference to #121 * Patch test expectation * [Feature][DX] Add Docker Configuration for Development (#109) * Fixes #120 * Add docker configuration for development This makes it easier to run the test suite in your local dev environment * Add a development section for contributors This should make it easier for people to set up the library and run the test suite within Docker * Added ruby service to make it easier to get started with your contribution * Update password to match Docker configuration * Removed outdated docker-compose file * Use older mysql to avoid trilogy error, fix docker compose and instructions, mount code for easier development * Update readme to point to CONTRIBUTE.md file * Run ./bin/setup so that we have the config file in place for tests * Relax dependency * Add a line about the Docker + DX change --------- Co-authored-by: Ariel Juodziukynas <arieljuod@gmail.com> * release_connection after cleaning (#122) For Rails >= 7.2, this library gets a connection via `#lease_connection`. But it never releases the connection. Release the connection back to the pool after `#clean`-ing. Rails >= 7.2 does connection health checks / reconnect on connection checkout. If the connection is never checked back into the pool, it will never get "repaired", which makes testing database connection issues tricky. * Add a reference to #121 * Change expectation to allow for a cascade option --------- Co-authored-by: Ariel Juodziukynas <arieljuod@gmail.com> Co-authored-by: Andrew Lazarus <nerdrew@gmail.com>
1 parent 988ccc3 commit f625783

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
* Release database connections after cleaning: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/122
44
* Provide a 'Changelog' link on Rubygems: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/114
55
* Fix bundling and CONTRIBUTE.md instructions: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/123
6+
* https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/121 by @etagwerker
67
* Fix order of arguments in `truncate_tables` expectation https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/124
78
* Add Docker to make it easier to run tests locally for maintainers and contributors https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/109
9+
* Allow truncation option https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/121 by @etagwerker
810

911
## v2.2.1 2025-05-13
1012

lib/database_cleaner/active_record/truncation.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def initialize(opts={})
2121
def clean
2222
connection.disable_referential_integrity do
2323
if pre_count? && connection.respond_to?(:pre_count_truncate_tables)
24-
connection.pre_count_truncate_tables(tables_to_clean(connection))
24+
connection.pre_count_truncate_tables(tables_to_clean(connection), { truncate_option: @truncate_option })
2525
else
2626
connection.truncate_tables(tables_to_clean(connection), { truncate_option: @truncate_option })
2727
end
@@ -111,8 +111,8 @@ def truncate_tables(tables, opts)
111111
end
112112

113113
module AbstractMysqlAdapter
114-
def pre_count_truncate_tables(tables)
115-
truncate_tables(pre_count_tables(tables))
114+
def pre_count_truncate_tables(tables, opts = {})
115+
truncate_tables(pre_count_tables(tables), opts)
116116
end
117117

118118
def pre_count_tables(tables)
@@ -159,8 +159,8 @@ def truncate_tables(tables, opts)
159159
tables.each { |t| truncate_table(t) }
160160
end
161161

162-
def pre_count_truncate_tables(tables)
163-
truncate_tables(pre_count_tables(tables))
162+
def pre_count_truncate_tables(tables, opts = {})
163+
truncate_tables(pre_count_tables(tables), opts)
164164
end
165165

166166
def pre_count_tables(tables)
@@ -202,8 +202,8 @@ def truncate_tables(table_names, opts)
202202
execute("TRUNCATE TABLE #{table_names.map{|name| quote_table_name(name)}.join(', ')} RESTART IDENTITY #{opts[:truncate_option]};")
203203
end
204204

205-
def pre_count_truncate_tables(tables)
206-
truncate_tables(pre_count_tables(tables))
205+
def pre_count_truncate_tables(tables, opts = {})
206+
truncate_tables(pre_count_tables(tables), opts)
207207
end
208208

209209
def pre_count_tables(tables)

spec/database_cleaner/active_record/truncation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
it "only truncates non-empty tables" do
9696
User.create!
9797

98-
expect(strategy.send(:connection)).to receive(:truncate_tables).with(['users'])
98+
expect(strategy.send(:connection)).to receive(:truncate_tables).with(['users'], {:truncate_option=>:restrict})
9999
strategy.clean
100100
end
101101
end

0 commit comments

Comments
 (0)