Skip to content

Commit

Permalink
deprecate mongo, mongoid, and redis truncation strategies in favor of…
Browse files Browse the repository at this point in the history
… deletion.
  • Loading branch information
botandrose-machine committed May 24, 2020
1 parent dcd1599 commit a694901
Show file tree
Hide file tree
Showing 12 changed files with 43 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,12 +3,14 @@
== 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

== 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

== 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

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

def strategy=(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, *strategy_args = args
@strategy = if strategy.is_a?(Symbol)
create_strategy(*args)
Expand Down

0 comments on commit a694901

Please sign in to comment.