changes key of passing in AR model to :model and documents it

This commit is contained in:
Ben Mabey 2012-08-25 12:21:43 -06:00
parent c209f17052
commit d23c17c05a
3 changed files with 7 additions and 4 deletions

View file

@ -188,6 +188,9 @@ Sometimes you need to use multiple ORMs in your application. You can use Databas
#How to specify particular connections
DatabaseCleaner[:active_record,{:connection => :two}]
# You may also pass in the model directly:
DatabaseCleaner[:active_record,{:model => ModelWithDifferentConnection}]
</pre>
Usage beyond that remains the same with DatabaseCleaner.start calling any setup on the different configured connections, and DatabaseCleaner.clean executing afterwards.
@ -196,7 +199,7 @@ Configuration options
|_. ORM |_. How to access |_. Notes |
| Active Record | DatabaseCleaner[:active_record] | Connection specified as :symbol keys, loaded from config/database.yml |
| Active Record | DatabaseCleaner[:active_record] | Connection specified as :symbol keys, loaded from config/database.yml. You may also pass in the ActiveRecord model under the @:model@ key. |
| Data Mapper | DatabaseCleaner[:data_mapper] | Connection specified as :symbol keys, loaded via Datamapper repositories |
| Mongo Mapper | DatabaseCleaner[:mongo_mapper] | Multiple connections not yet supported |
| Mongoid | DatabaseCleaner[:mongoid] | Multiple connections not yet supported |

View file

@ -47,8 +47,8 @@ if orm && strategy
DatabaseCleaner[ orm_sym, {:connection => 'database_cleaner_test_one'} ].strategy = strategy.to_sym
DatabaseCleaner[ orm_sym, {:connection => 'database_cleaner_test_two'} ].strategy = strategy.to_sym
when :active_record
DatabaseCleaner[:active_record, {:connection => ActiveRecordWidgetUsingDatabaseOne} ].strategy = strategy.to_sym
DatabaseCleaner[:active_record, {:connection => ActiveRecordWidgetUsingDatabaseTwo} ].strategy = strategy.to_sym
DatabaseCleaner[:active_record, {:model => ActiveRecordWidgetUsingDatabaseOne} ].strategy = strategy.to_sym
DatabaseCleaner[:active_record, {:model => ActiveRecordWidgetUsingDatabaseTwo} ].strategy = strategy.to_sym
else
DatabaseCleaner[ orm_sym, {:connection => :one} ].strategy = strategy.to_sym
DatabaseCleaner[ orm_sym, {:connection => :two} ].strategy = strategy.to_sym

View file

@ -8,7 +8,7 @@ module DatabaseCleaner
else
self.orm = desired_orm
end
self.db = opts[:connection] || opts[:db] if opts.has_key?(:connection) || opts.has_key?(:db)
self.db = opts[:connection] || opts[:model] if opts.has_key?(:connection) || opts.has_key?(:model)
set_default_orm_strategy
end