Fix MySQL deprecation warnings with Rails 5
When the truncation strategy is used with Rails 5, we see the deprecation message: DEPRECATION WARNING: #tables currently returns both tables and views. This behavior is deprecated and will be changed with Rails 5.1 to only return tables. Use #data_sources instead.
This commit is contained in:
parent
4c2408ffdb
commit
44a173124a
|
@ -27,7 +27,11 @@ module DatabaseCleaner
|
||||||
|
|
||||||
def database_cleaner_table_cache
|
def database_cleaner_table_cache
|
||||||
# the adapters don't do caching (#130) but we make the assumption that the list stays the same in tests
|
# the adapters don't do caching (#130) but we make the assumption that the list stays the same in tests
|
||||||
@database_cleaner_tables ||= ::ActiveRecord::VERSION::MAJOR >= 5 ? data_sources : tables
|
@database_cleaner_tables ||= database_tables
|
||||||
|
end
|
||||||
|
|
||||||
|
def database_tables
|
||||||
|
::ActiveRecord::VERSION::MAJOR >= 5 ? data_sources : tables
|
||||||
end
|
end
|
||||||
|
|
||||||
def truncate_table(table_name)
|
def truncate_table(table_name)
|
||||||
|
@ -243,7 +247,7 @@ module DatabaseCleaner::ActiveRecord
|
||||||
private
|
private
|
||||||
|
|
||||||
def tables_to_truncate(connection)
|
def tables_to_truncate(connection)
|
||||||
tables_in_db = cache_tables? ? connection.database_cleaner_table_cache : connection.tables
|
tables_in_db = cache_tables? ? connection.database_cleaner_table_cache : connection.database_tables
|
||||||
to_reject = (@tables_to_exclude + connection.database_cleaner_view_cache)
|
to_reject = (@tables_to_exclude + connection.database_cleaner_view_cache)
|
||||||
(@only || tables_in_db).reject do |table|
|
(@only || tables_in_db).reject do |table|
|
||||||
if ( m = table.match(/([^.]+)$/) )
|
if ( m = table.match(/([^.]+)$/) )
|
||||||
|
|
Loading…
Reference in New Issue