allow setting of orm and skip autodetect

This commit is contained in:
Ben Mabey 2009-03-04 14:00:20 -07:00
parent 27e8b337f7
commit 9fa3eb0818
2 changed files with 22 additions and 7 deletions

View File

@ -26,6 +26,10 @@ module DatabaseCleaner
end
end
def orm=(orm_string)
@orm = orm_string
end
def start
strategy.start
end
@ -50,13 +54,15 @@ module DatabaseCleaner
def orm
if defined? ::ActiveRecord
'active_record'
elsif defined? ::DataMapper
'data_mapper'
else
raise NoORMDetected, "No known ORM was detected! Is ActiveRecord or DataMapper loaded?"
end
@orm ||=begin
if defined? ::ActiveRecord
'active_record'
elsif defined? ::DataMapper
'data_mapper'
else
raise NoORMDetected, "No known ORM was detected! Is ActiveRecord or DataMapper loaded?"
end
end
end

View File

@ -7,6 +7,7 @@ describe DatabaseCleaner do
DatabaseCleaner::ActiveRecord::Transaction.stub!(:new).and_return(@strategy = mock('strategy'))
Object.const_set('ActiveRecord', "just mocking out the constant here...") unless defined?(::ActiveRecord)
DatabaseCleaner.strategy = nil
DatabaseCleaner.orm = nil
end
describe ".strategy=" do
@ -16,6 +17,7 @@ describe DatabaseCleaner do
Object.send(:remove_const, 'ActiveRecord')
Object.const_set('DataMapper', "just mocking out the constant here...")
DatabaseCleaner.orm = nil
DatabaseCleaner::DataMapper::Transaction.should_receive(:new).with(no_args)
DatabaseCleaner.strategy = :transaction
@ -28,6 +30,13 @@ describe DatabaseCleaner do
running { DatabaseCleaner.strategy = :transaction }.should raise_error(DatabaseCleaner::NoORMDetected)
end
it "should use the strategy version of the ORM specified with #orm=" do
DatabaseCleaner.orm = 'data_mapper'
DatabaseCleaner::DataMapper::Transaction.should_receive(:new)
DatabaseCleaner.strategy = :transaction
end
it "should raise an error when the specified strategy is not found" do
running { DatabaseCleaner.strategy = :foo }.should raise_error(DatabaseCleaner::UnknownStrategySpecified)
end