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)
|
== 0.6.1 (in git)
|
||||||
|
|
||||||
|
=== New Features
|
||||||
|
* Add a NullStrategy which is now the default strategy. (GH-6 Ben Mabey)
|
||||||
|
|
||||||
=== Bugfixes
|
=== Bugfixes
|
||||||
* Exclude database views from tables_to_truncate, if the connection adapter
|
* Exclude database views from tables_to_truncate, if the connection adapter
|
||||||
supports reading from the ANSI standard information_schema views. (GH-25 Samer Abukhait)
|
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
|
locks (as reported by some Oracle DB users). The @:truncation@ strategy is the preferred option
|
||||||
since it is much faster.
|
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
|
h2. How to use
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
require 'database_cleaner/null_strategy'
|
||||||
module DatabaseCleaner
|
module DatabaseCleaner
|
||||||
class Base
|
class Base
|
||||||
|
|
||||||
|
@ -21,9 +22,6 @@ module DatabaseCleaner
|
||||||
elsif desired_db!= :default
|
elsif desired_db!= :default
|
||||||
raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database"
|
raise ArgumentError, "You must provide a strategy object that supports non default databases when you specify a database"
|
||||||
end
|
end
|
||||||
rescue NoStrategySetError
|
|
||||||
#handle NoStrategySetError by doing nothing at all
|
|
||||||
desired_db
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def db
|
def db
|
||||||
|
@ -59,8 +57,7 @@ module DatabaseCleaner
|
||||||
end
|
end
|
||||||
|
|
||||||
def strategy
|
def strategy
|
||||||
return @strategy if @strategy
|
@strategy || NullStrategy
|
||||||
raise NoStrategySetError, "Please set a strategy with DatabaseCleaner.strategy=."
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def orm=(desired_orm)
|
def orm=(desired_orm)
|
||||||
|
|
|
@ -2,7 +2,6 @@ require 'database_cleaner/base'
|
||||||
|
|
||||||
module DatabaseCleaner
|
module DatabaseCleaner
|
||||||
|
|
||||||
class NoStrategySetError < StandardError; end
|
|
||||||
class NoORMDetected < StandardError; end
|
class NoORMDetected < StandardError; end
|
||||||
class UnknownStrategySpecified < ArgumentError; 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
|
end
|
||||||
|
|
||||||
describe "strategy" do
|
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
|
subject.instance_values["@strategy"] = nil
|
||||||
expect{ subject.strategy }.to raise_error NoStrategySetError
|
subject.strategy.should == DatabaseCleaner::NullStrategy
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return @strategy if @strategy is present" do
|
it "returns the set strategy" do
|
||||||
strategum = mock("strategy")
|
strategum = mock("strategy")
|
||||||
subject.strategy = strategum
|
subject.strategy = strategum
|
||||||
subject.strategy.should == strategum
|
subject.strategy.should == strategum
|
||||||
|
|
Loading…
Add table
Reference in a new issue