Skip to content

Commit

Permalink
Merge pull request #654 from DatabaseCleaner/rename_truncation_to_del…
Browse files Browse the repository at this point in the history
…etion_deprecation

[v1.99] Rename truncation to deletion deprecations
  • Loading branch information
etagwerker committed May 30, 2020
2 parents d622cb6 + a57776b commit 063a43d
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 5 deletions.
2 changes: 2 additions & 0 deletions History.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
== 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
* Deprecate all #orm= setter methods: https://github.com/DatabaseCleaner/database_cleaner/pull/643
* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module DatabaseCleaner
module Mongo
def self.available_strategies
%w[truncation]
%w[truncation deletion]
end
module Base
def db=(desired_db)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'database_cleaner/mongo/truncation'

module DatabaseCleaner
module Mongo
class Deletion < Truncation
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Truncation
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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module DatabaseCleaner
module Mongoid
def self.available_strategies
%w[truncation]
%w[truncation deletion]
end

module Base
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'database_cleaner/mongoid/truncation'

module DatabaseCleaner
module Mongoid
class Deletion < Truncation
end
end
end


Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "database_cleaner/redis/version"
require "database_cleaner"
require "database_cleaner/redis/truncation"
require "database_cleaner/redis/deletion"

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module DatabaseCleaner
module Redis
def self.available_strategies
%w{truncation}
%w{truncation deletion}
end

def self.default_strategy
Expand All @@ -23,7 +23,7 @@ def db
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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'database_cleaner/redis/truncation'

module DatabaseCleaner
module Redis
class Deletion < Truncation
end
end
end

7 changes: 7 additions & 0 deletions lib/database_cleaner/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def db

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?
Expand Down
22 changes: 22 additions & 0 deletions spec/database_cleaner/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,27 @@ module DatabaseCleaner
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

0 comments on commit 063a43d

Please sign in to comment.