mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Fix MySqlAdapter superclass bug via class_eval loading of superclasses
This commit is contained in:
parent
3ecd0f5f64
commit
9bf038d5c2
3 changed files with 21 additions and 33 deletions
|
@ -176,56 +176,39 @@ module ActiveRecord
|
||||||
module ConnectionAdapters
|
module ConnectionAdapters
|
||||||
# Activerecord-jdbc-adapter defines class dependencies a bit differently - if it is present, confirm to ArJdbc hierarchy to avoid 'superclass mismatch' errors.
|
# Activerecord-jdbc-adapter defines class dependencies a bit differently - if it is present, confirm to ArJdbc hierarchy to avoid 'superclass mismatch' errors.
|
||||||
USE_ARJDBC_WORKAROUND = defined?(ArJdbc)
|
USE_ARJDBC_WORKAROUND = defined?(ArJdbc)
|
||||||
|
# ActiveRecord 3.1+ support
|
||||||
|
MYSQL_ABSTRACT_ADAPTER = defined?(AbstractMysqlAdapter) ? AbstractMysqlAdapter : AbstractAdapter
|
||||||
|
|
||||||
class AbstractAdapter
|
AbstractAdapter.send(:include, ::DatabaseCleaner::ActiveRecord::AbstractAdapter)
|
||||||
include ::DatabaseCleaner::ActiveRecord::AbstractAdapter
|
|
||||||
end
|
|
||||||
|
|
||||||
unless USE_ARJDBC_WORKAROUND
|
if USE_ARJDBC_WORKAROUND
|
||||||
class SQLiteAdapter < AbstractAdapter
|
MYSQL_ADAPTER_PARENT = JdbcAdapter
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# ActiveRecord 3.1 support
|
|
||||||
if defined?(AbstractMysqlAdapter)
|
|
||||||
MYSQL_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractMysqlAdapter
|
|
||||||
MYSQL2_ADAPTER_PARENT = AbstractMysqlAdapter
|
|
||||||
else
|
else
|
||||||
MYSQL_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
|
MYSQL_ADAPTER_PARENT = MYSQL_ABSTRACT_ADAPTER
|
||||||
MYSQL2_ADAPTER_PARENT = AbstractAdapter
|
class SQLiteAdapter < AbstractAdapter; end
|
||||||
end
|
end
|
||||||
|
MYSQL2_ADAPTER_PARENT = MYSQL_ABSTRACT_ADAPTER
|
||||||
|
|
||||||
if defined?(SQLite3Adapter) && SQLite3Adapter.superclass == ActiveRecord::ConnectionAdapters::AbstractAdapter
|
if defined?(SQLite3Adapter) && SQLite3Adapter.superclass == ActiveRecord::ConnectionAdapters::AbstractAdapter
|
||||||
SQLITE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
|
SQLITE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
|
||||||
else
|
else
|
||||||
SQLITE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : SQLiteAdapter
|
SQLITE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : SQLiteAdapter
|
||||||
end
|
end
|
||||||
POSTGRE_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
|
POSTGRES_ADAPTER_PARENT = USE_ARJDBC_WORKAROUND ? JdbcAdapter : AbstractAdapter
|
||||||
|
|
||||||
class MysqlAdapter < MYSQL_ADAPTER_PARENT
|
MYSQL_ADAPTER_PARENT.class_eval { include ::DatabaseCleaner::ActiveRecord::MysqlAdapter }
|
||||||
include ::DatabaseCleaner::ActiveRecord::MysqlAdapter
|
MYSQL2_ADAPTER_PARENT.class_eval { include ::DatabaseCleaner::ActiveRecord::MysqlAdapter }
|
||||||
end
|
SQLITE_ADAPTER_PARENT.class_eval { include ::DatabaseCleaner::ActiveRecord::SQLiteAdapter }
|
||||||
|
POSTGRES_ADAPTER_PARENT.class_eval { include ::DatabaseCleaner::ActiveRecord::PostgreSQLAdapter }
|
||||||
class Mysql2Adapter < MYSQL2_ADAPTER_PARENT
|
|
||||||
include ::DatabaseCleaner::ActiveRecord::MysqlAdapter
|
|
||||||
end
|
|
||||||
|
|
||||||
class IBM_DBAdapter < AbstractAdapter
|
class IBM_DBAdapter < AbstractAdapter
|
||||||
include ::DatabaseCleaner::ActiveRecord::IBM_DBAdapter
|
include ::DatabaseCleaner::ActiveRecord::IBM_DBAdapter
|
||||||
end
|
end
|
||||||
|
|
||||||
class SQLite3Adapter < SQLITE_ADAPTER_PARENT
|
|
||||||
include ::DatabaseCleaner::ActiveRecord::SQLiteAdapter
|
|
||||||
end
|
|
||||||
|
|
||||||
class JdbcAdapter < AbstractAdapter
|
class JdbcAdapter < AbstractAdapter
|
||||||
include ::DatabaseCleaner::ActiveRecord::TruncateOrDelete
|
include ::DatabaseCleaner::ActiveRecord::TruncateOrDelete
|
||||||
end
|
end
|
||||||
|
|
||||||
class PostgreSQLAdapter < POSTGRE_ADAPTER_PARENT
|
|
||||||
include ::DatabaseCleaner::ActiveRecord::PostgreSQLAdapter
|
|
||||||
end
|
|
||||||
|
|
||||||
class SQLServerAdapter < AbstractAdapter
|
class SQLServerAdapter < AbstractAdapter
|
||||||
include ::DatabaseCleaner::ActiveRecord::TruncateOrDelete
|
include ::DatabaseCleaner::ActiveRecord::TruncateOrDelete
|
||||||
end
|
end
|
||||||
|
@ -233,7 +216,6 @@ module ActiveRecord
|
||||||
class OracleEnhancedAdapter < AbstractAdapter
|
class OracleEnhancedAdapter < AbstractAdapter
|
||||||
include ::DatabaseCleaner::ActiveRecord::OracleEnhancedAdapter
|
include ::DatabaseCleaner::ActiveRecord::OracleEnhancedAdapter
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
require File.dirname(__FILE__) + '/../../spec_helper'
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
||||||
require 'active_record'
|
require 'active_record'
|
||||||
|
require 'active_record/connection_adapters/mysql_adapter'
|
||||||
|
require 'active_record/connection_adapters/mysql2_adapter'
|
||||||
|
require 'active_record/connection_adapters/sqlite3_adapter'
|
||||||
|
require 'active_record/connection_adapters/postgresql_adapter'
|
||||||
|
|
||||||
require 'database_cleaner/active_record/truncation'
|
require 'database_cleaner/active_record/truncation'
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'support/active_record/database_setup'
|
require 'support/active_record/database_setup'
|
||||||
require 'support/active_record/schema_setup'
|
require 'support/active_record/schema_setup'
|
||||||
|
|
||||||
|
|
||||||
module MySQL2Helper
|
module MySQL2Helper
|
||||||
puts "Active Record #{ActiveRecord::VERSION::STRING}, mysql2"
|
puts "Active Record #{ActiveRecord::VERSION::STRING}, mysql2"
|
||||||
|
|
||||||
|
@ -36,3 +37,4 @@ end
|
||||||
RSpec.configure do |c|
|
RSpec.configure do |c|
|
||||||
c.include MySQL2Helper
|
c.include MySQL2Helper
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue