Merge pull request #654 from DatabaseCleaner/rename_truncation_to_deletion_deprecation

[v1.99] Rename truncation to deletion deprecations
This commit is contained in:
Ernesto Tagwerker 2020-05-30 11:09:11 -04:00 committed by GitHub
commit 063a43db3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 66 additions and 5 deletions

View file

@ -3,6 +3,7 @@
== Changes
* Remove unnecessary dependency on database_cleaner-mongo from database_cleaner-mongoid: @botandrose
* Enable the :cache_tables option for the mongo truncation strategy, and default to true: https://github.com/DatabaseCleaner/database_cleaner/pull/646"
* Introduce deletion aliases for truncation strategies for mongo, mongoid, and redis adapters. https://github.com/DatabaseCleaner/database_cleaner/pull/654
* Add new :db orm configuration key, for consistency with #db and #db=. https://github.com/DatabaseCleaner/database_cleaner/pull/649
== Deprecations
@ -10,6 +11,7 @@
* Deprecate non-functional :reset_ids option in ActiveRecord truncation strategy: https://github.com/DatabaseCleaner/database_cleaner/issues/559
* Deprecate mongo truncation's `:cache_tables => true` option in favor of `false`, to prep for caching removal in v2.0: https://github.com/DatabaseCleaner/database_cleaner/pull/646"
* Deprecate redis truncation's #url method in favor of #db: @botandrose
* Deprecate mongo, mongoid, and redis truncation strategies in favor of deletion. https://github.com/DatabaseCleaner/database_cleaner/pull/654
* Deprecate :connection and :model configuration options in favor of :db for consistency: https://github.com/DatabaseCleaner/database_cleaner/pull/650
== Bugfixes

View file

@ -1,6 +1,7 @@
require 'database_cleaner/mongo/version'
require 'database_cleaner'
require 'database_cleaner/mongo/truncation'
require 'database_cleaner/mongo/deletion'
module DatabaseCleaner::Mongo
def self.default_strategy

View file

@ -1,7 +1,7 @@
module DatabaseCleaner
module Mongo
def self.available_strategies
%w[truncation]
%w[truncation deletion]
end
module Base
def db=(desired_db)

View file

@ -0,0 +1,8 @@
require 'database_cleaner/mongo/truncation'
module DatabaseCleaner
module Mongo
class Deletion < Truncation
end
end
end

View file

@ -15,7 +15,7 @@ module DatabaseCleaner
def initialize(opts={})
super
if !opts.has_key?(:cache_tables) || opts[:cache_tables]
DatabaseCleaner.deprecate "The mongo adapter caches collection names between cleanings. However, this behavior can introduce test-order-dependency issues, because the collections that exist after the first test has executed are saved and used for the remainder of the suite. This means that any collection created during the subsequent tests are not cleaned! This is fixed in database_cleaner-mongo 2.0 by removing this collection caching functionality altogether. To ease the transition into this new behavior, it can be opted into by specifying the `:cache_tables` option to false: `DatabaseCleaner[:mongo].strategy = :truncation, cache_tables: false`. For more information, see https://github.com/DatabaseCleaner/database_cleaner/pull/646"
DatabaseCleaner.deprecate "The mongo adapter caches collection names between cleanings. However, this behavior can introduce test-order-dependency issues, because the collections that exist after the first test has executed are saved and used for the remainder of the suite. This means that any collection created during the subsequent tests are not cleaned! This is fixed in database_cleaner-mongo 2.0 by removing this collection caching functionality altogether. To ease the transition into this new behavior, it can be opted into by specifying the `:cache_tables` option to false: `DatabaseCleaner[:mongo].strategy = :deletion, cache_tables: false`. For more information, see https://github.com/DatabaseCleaner/database_cleaner/pull/646"
end
end

View file

@ -1,6 +1,7 @@
require "database_cleaner/mongoid/version"
require "database_cleaner"
require "database_cleaner/mongoid/truncation"
require "database_cleaner/mongoid/deletion"
module DatabaseCleaner::Mongoid
def self.default_strategy

View file

@ -2,7 +2,7 @@ require 'database_cleaner/generic/base'
module DatabaseCleaner
module Mongoid
def self.available_strategies
%w[truncation]
%w[truncation deletion]
end
module Base

View file

@ -0,0 +1,10 @@
require 'database_cleaner/mongoid/truncation'
module DatabaseCleaner
module Mongoid
class Deletion < Truncation
end
end
end

View file

@ -1,4 +1,5 @@
require "database_cleaner/redis/version"
require "database_cleaner"
require "database_cleaner/redis/truncation"
require "database_cleaner/redis/deletion"

View file

@ -4,7 +4,7 @@ require 'database_cleaner/deprecation'
module DatabaseCleaner
module Redis
def self.available_strategies
%w{truncation}
%w{truncation deletion}
end
def self.default_strategy
@ -23,7 +23,7 @@ module DatabaseCleaner
end
def url
DatabaseCleaner.deprecate "The redis truncation strategy's #url method is deprecated. It will be removed in database_cleaner-redis 2.0 in favor of #db."
DatabaseCleaner.deprecate "The redis deletion strategy's #url method is deprecated. It will be removed in database_cleaner-redis 2.0 in favor of #db."
db
end

View file

@ -0,0 +1,9 @@
require 'database_cleaner/redis/truncation'
module DatabaseCleaner
module Redis
class Deletion < Truncation
end
end
end

View file

@ -36,6 +36,13 @@ module DatabaseCleaner
def strategy=(args)
strategy, *strategy_args = args
if DatabaseCleaner.called_externally?(__FILE__, caller) \
&& [:redis, :mongo, :mongoid].include?(orm) \
&& strategy == :truncation
DatabaseCleaner.deprecate "The #{orm} adapter's :truncation strategy will be renamed to :deletion in database_cleaner-#{orm} 2.0. Please specify the :deletion adapter to resolve this deprecation notice."
end
@strategy = if strategy.is_a?(Symbol)
create_strategy(*args)
elsif strategy_args.empty?

View file

@ -458,5 +458,27 @@ No known ORM was detected! Is ActiveRecord, DataMapper, MongoMapper, Mongoid, M
cleaner.orm = :mongoid
end
end
describe "deprecations regarding renaming truncation to deletion" do
it "shows a deprecation warning if truncation strategy is explicitly specified" do
expect(DatabaseCleaner).to receive(:deprecate)
cleaner = DatabaseCleaner::Base.new(:mongoid)
cleaner.strategy = :truncation
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::Mongoid::Truncation
end
it "defaults to truncation without a deprecation warning strategy is not specified" do
expect(DatabaseCleaner).to_not receive(:deprecate)
cleaner = DatabaseCleaner::Base.new(:mongoid)
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::Mongoid::Truncation
end
it "accepts new deletion strategy without a deprecation warning" do
expect(DatabaseCleaner).to_not receive(:deprecate)
cleaner = DatabaseCleaner::Base.new(:mongoid)
cleaner.strategy = :deletion
expect(cleaner.strategy).to be_instance_of DatabaseCleaner::Mongoid::Deletion
end
end
end
end