DatabaseCleaner / database_cleaner-active_record

Strategies for cleaning databases using ActiveRecord. Can be used to ensure a clean state for testing.
MIT License
62 stars 64 forks source link

When multiple Database backends are used in ActiveRecord, DatabaseCleaner fails to truncate tables #27

Open DFrenkel opened 11 years ago

DFrenkel commented 11 years ago

When both MySQL and Postgres ActiveRecord models are used, and when testing MySQL-backed code, Truncation strategy includes BOTH ::DatabaseCleaner::ActiveRecord::MysqlAdapter and ::DatabaseCleaner::ActiveRecord::PostgreSQLAdapter into ::DatabaseCleaner::ActiveRecord::AbstractAdapter, which, in turn, gets included into ActiveRecord::AbstractAdapter.

Since PostgreSQLAdapter gets included last, even when ActiveRecord::Base.connection is a MySQL connection, DatabaseCleaner attempts to execute Postgres-specific truncations, resulting in errors:

NameError: undefined local variable or method `postgresql_version' for #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0x0000000692feb8>
  occurred at /usr/local/rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-1.1.1/lib/database_cleaner/active_record/truncation.rb:123:in `db_version'
bry4n commented 11 years ago

I am getting same issue here. it seems like postgresql_version method isn't existed anywhere.

bry4n commented 11 years ago

Downgraded to 1.0.1 fixed the problem. -- https://github.com/bmabey/database_cleaner/issues/224#issuecomment-22031253

sockmonk commented 11 years ago

I saw the same error, but instead I was using the OracleEnhanced adapter only. When it called truncate_tables, it used the PostgreSQLAdapter version as that method doesn't exist in the OracleEnhnacedAdapter, which led to the same error regarding an undefined postgresql_version method.

Downgrading to 1.0.1 fixed the problem for me as well.

fredwu commented 11 years ago

9bf038d5c287cca98612fb0a76e58147d3694868 is the culprit, cc @bmabey @tommeier

tommeier commented 11 years ago

Awaiting testers on https://github.com/bmabey/database_cleaner/pull/221

fabiokr commented 10 years ago

Was this fixed by DatabaseCleaner/database_cleaner#241?

Tab10id commented 8 years ago

Problem there:

class Deletion < Truncation
    if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
      include SelectiveTruncation
    end
    ...
end