diff --git a/History.txt b/History.txt index 974678a..8cdd05f 100644 --- a/History.txt +++ b/History.txt @@ -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) diff --git a/README.textile b/README.textile index c149549..f730466 100644 --- a/README.textile +++ b/README.textile @@ -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
diff --git a/lib/database_cleaner/base.rb b/lib/database_cleaner/base.rb index f4b175a..dd6260c 100644 --- a/lib/database_cleaner/base.rb +++ b/lib/database_cleaner/base.rb @@ -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) diff --git a/lib/database_cleaner/configuration.rb b/lib/database_cleaner/configuration.rb index 10137d6..537c2cd 100644 --- a/lib/database_cleaner/configuration.rb +++ b/lib/database_cleaner/configuration.rb @@ -2,7 +2,6 @@ require 'database_cleaner/base' module DatabaseCleaner - class NoStrategySetError < StandardError; end class NoORMDetected < StandardError; end class UnknownStrategySpecified < ArgumentError; end diff --git a/lib/database_cleaner/null_strategy.rb b/lib/database_cleaner/null_strategy.rb new file mode 100644 index 0000000..eb67c97 --- /dev/null +++ b/lib/database_cleaner/null_strategy.rb @@ -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 diff --git a/spec/database_cleaner/base_spec.rb b/spec/database_cleaner/base_spec.rb index 00204f0..ade60f6 100644 --- a/spec/database_cleaner/base_spec.rb +++ b/spec/database_cleaner/base_spec.rb @@ -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