Skip to content
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
* Release database connections after cleaning: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/122
* Provide a 'Changelog' link on Rubygems: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/114
* Fix bundling and CONTRIBUTE.md instructions: https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/123
* https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/121 by @etagwerker
* Fix order of arguments in `truncate_tables` expectation https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/124
* Add Docker to make it easier to run tests locally for maintainers and contributors https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/109
* Allow truncation option https://github.com/DatabaseCleaner/database_cleaner-active_record/pull/121 by @etagwerker

## v2.2.1 2025-05-13

Expand Down
14 changes: 7 additions & 7 deletions lib/database_cleaner/active_record/truncation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(opts={})
def clean
connection.disable_referential_integrity do
if pre_count? && connection.respond_to?(:pre_count_truncate_tables)
connection.pre_count_truncate_tables(tables_to_clean(connection))
connection.pre_count_truncate_tables(tables_to_clean(connection), { truncate_option: @truncate_option })
else
connection.truncate_tables(tables_to_clean(connection), { truncate_option: @truncate_option })
end
Expand Down Expand Up @@ -111,8 +111,8 @@ def truncate_tables(tables, opts)
end

module AbstractMysqlAdapter
def pre_count_truncate_tables(tables)
truncate_tables(pre_count_tables(tables))
def pre_count_truncate_tables(tables, opts = {})
truncate_tables(pre_count_tables(tables), opts)
end

def pre_count_tables(tables)
Expand Down Expand Up @@ -159,8 +159,8 @@ def truncate_tables(tables, opts)
tables.each { |t| truncate_table(t) }
end

def pre_count_truncate_tables(tables)
truncate_tables(pre_count_tables(tables))
def pre_count_truncate_tables(tables, opts = {})
truncate_tables(pre_count_tables(tables), opts)
end

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

def pre_count_truncate_tables(tables)
truncate_tables(pre_count_tables(tables))
def pre_count_truncate_tables(tables, opts = {})
truncate_tables(pre_count_tables(tables), opts)
end

def pre_count_tables(tables)
Expand Down
2 changes: 1 addition & 1 deletion spec/database_cleaner/active_record/truncation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
it "only truncates non-empty tables" do
User.create!

expect(strategy.send(:connection)).to receive(:truncate_tables).with(['users'])
expect(strategy.send(:connection)).to receive(:truncate_tables).with(['users'], {:truncate_option=>:restrict})
strategy.clean
end
end
Expand Down