mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
allow setting of orm and skip autodetect
This commit is contained in:
parent
27e8b337f7
commit
9fa3eb0818
2 changed files with 22 additions and 7 deletions
|
@ -26,6 +26,10 @@ module DatabaseCleaner
|
|||
end
|
||||
end
|
||||
|
||||
def orm=(orm_string)
|
||||
@orm = orm_string
|
||||
end
|
||||
|
||||
def start
|
||||
strategy.start
|
||||
end
|
||||
|
@ -50,6 +54,7 @@ module DatabaseCleaner
|
|||
|
||||
|
||||
def orm
|
||||
@orm ||=begin
|
||||
if defined? ::ActiveRecord
|
||||
'active_record'
|
||||
elsif defined? ::DataMapper
|
||||
|
@ -58,6 +63,7 @@ module DatabaseCleaner
|
|||
raise NoORMDetected, "No known ORM was detected! Is ActiveRecord or DataMapper loaded?"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def orm_module
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue