I ran into a problem using the code mentioned in my spec_helper.rb file.
What happens when your tests depend on using connections to multiple databases? I have two databases that I need to connect to when I run my tests. I did a simple test to check what happens to the database connections that I install.
class ActiveRecord::Base mattr_accessor :shared_connection @@shared_connection = nil def self.connection @@shared_connection || retrieve_connection end end # Forces all threads to share the same connection. This works on # Capybara because it starts the web server in a thread. puts "First Record cxn: #{FirstDatabase::Record.connection}" # => First Record cxn: #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0xe59b524> puts "AR Base cxn: #{ActiveRecord::Base.connection}" # => AR Base cxn: #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0xc52761c> ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection puts "First Record cxn: #{FirstDatabase::Record.connection}" # => First Record cxn: #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0xc52761c> puts "AR Base cxn: #{ActiveRecord::Base.connection}" # => AR Base cxn: #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0xc52761c>
As you can see, before I call the shared connection method, I have two different database connections. After calling the general connection method, I have only one.
Thus, any test that requires a transition to the second database connection to retrieve information will fail.: (
I am going to post this problem and see if anyone has come to a solution.
Mieczysław Daniel Dyba Jul 26 '13 at 18:50 2013-07-26 18:50
source share