mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
adds null strategy and makes default when no strategy specified
This commit is contained in:
parent
ccaf05ffab
commit
aa099eb477
6 changed files with 27 additions and 9 deletions
|
@ -1,5 +1,8 @@
|
|||
== 0.6.1 (in git)
|
||||
|
||||
=== New Features
|
||||
* Add a NullStrategy which is now the default strategy. (GH-6 Ben Mabey)
|
||||
|
||||
=== Bugfixes
|
||||
* Exclude database views from tables_to_truncate, if the connection adapter
|
||||
supports reading from the ANSI standard information_schema views. (GH-25 Samer Abukhait)
|
||||
|
|
|
@ -20,6 +20,10 @@ The ActiveRecord @:deletion@ strategy is only useful for when the @:truncation@
|
|||
locks (as reported by some Oracle DB users). The @:truncation@ strategy is the preferred option
|
||||
since it is much faster.
|
||||
|
||||
Database Cleaner also includes a @null@ strategy (that does no cleaning at all) which can be used
|
||||
with any ORM library. _This is the default strategy and will be used unless you
|
||||
specify one._ You can also explicitly use it by setting your strategy to @nil@.
|
||||
|
||||
h2. How to use
|
||||
|
||||
<pre>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require 'database_cleaner/null_strategy'
|
||||
module DatabaseCleaner
|
||||
class Base
|
||||
|
||||
|
@ -21,9 +22,6 @@ module DatabaseCleaner
|
|||
elsif desired_db!= :default
|
||||
raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database"
|
||||
end
|
||||
rescue NoStrategySetError
|
||||
#handle NoStrategySetError by doing nothing at all
|
||||
desired_db
|
||||
end
|
||||
|
||||
def db
|
||||
|
@ -59,8 +57,7 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
def strategy
|
||||
return @strategy if @strategy
|
||||
raise NoStrategySetError, "Please set a strategy with DatabaseCleaner.strategy=."
|
||||
@strategy || NullStrategy
|
||||
end
|
||||
|
||||
def orm=(desired_orm)
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'database_cleaner/base'
|
|||
|
||||
module DatabaseCleaner
|
||||
|
||||
class NoStrategySetError < StandardError; end
|
||||
class NoORMDetected < StandardError; end
|
||||
class UnknownStrategySpecified < ArgumentError; end
|
||||
|
||||
|
|
15
lib/database_cleaner/null_strategy.rb
Normal file
15
lib/database_cleaner/null_strategy.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module DatabaseCleaner
|
||||
class NullStrategy
|
||||
def self.start
|
||||
# no-op
|
||||
end
|
||||
|
||||
def self.db=(connection)
|
||||
# no-op
|
||||
end
|
||||
|
||||
def self.clean
|
||||
# no-op
|
||||
end
|
||||
end
|
||||
end
|
|
@ -310,12 +310,12 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
describe "strategy" do
|
||||
it "should raise NoStrategySetError if strategy is nil" do
|
||||
it "returns a null strategy when strategy no set" do
|
||||
subject.instance_values["@strategy"] = nil
|
||||
expect{ subject.strategy }.to raise_error NoStrategySetError
|
||||
subject.strategy.should == DatabaseCleaner::NullStrategy
|
||||
end
|
||||
|
||||
it "should return @strategy if @strategy is present" do
|
||||
it "returns the set strategy" do
|
||||
strategum = mock("strategy")
|
||||
subject.strategy = strategum
|
||||
subject.strategy.should == strategum
|
||||
|
|
Loading…
Reference in a new issue