Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Transaction strategy works with ActiveRecord and multiple databases #107

Merged
merged 1 commit into from

3 participants

@kazjote

It works with rails 3 and should not crash rails 2.3.

I would love to test it but could not setup testing environment correctly. I tried with the environment from .rvmrc but it does not work as project uses ruby 1.9 hashes syntax at lib/database_cleaner/sequel/transaction.rb.

With ruby 1.9 I could not install whole bundle as it depends on a gem not ready for ruby 1.9.

Please, let me know how to run testcase. I am probably missing something...

@johnf

This just solved my hours of soul searching getting multiple databases working. For truncation in my case. Maybe this is a rails 3.2 thing?

@johnf

This just solved my hours of soul searching getting multiple databases working. For truncation in my case. Maybe this is a rails 3.2 thing, since I'm sure I've had this working wth < 3.2.

@kazjote

We use it currently with rails 3.2.2

If you change strategy, you have to set strategy separately for each database.

If you have 3 databases (your test, test_sps, test_ids) you have to do following:

  DatabaseCleaner.strategy = strategy
  DatabaseCleaner[:active_record, {:connection => :test_sps}].strategy = strategy
  DatabaseCleaner[:active_record, {:connection => :test_ids}].strategy = strategy
@bmabey bmabey merged commit a469347 into DatabaseCleaner:master
@bmabey
Owner

Merged in, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 0 deletions.
  1. +8 −0 lib/database_cleaner/active_record/base.rb
View
8 lib/database_cleaner/active_record/base.rb
@@ -44,6 +44,14 @@ def create_connection_klass
def connection_klass
return ::ActiveRecord::Base unless connection_hash
+
+ if ::ActiveRecord::Base.respond_to?(:descendants)
+ database_name = connection_hash["database"]
+ models = ::ActiveRecord::Base.descendants
+ klass = models.detect {|m| m.connection_pool.spec.config[:database] == database_name}
+ return klass if klass
+ end
+
klass = create_connection_klass
klass.send :establish_connection, connection_hash
klass
Something went wrong with that request. Please try again.