Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Shared db connection #56

Open
ristovskiv opened this issue Apr 17, 2015 · 0 comments
Open

Shared db connection #56

ristovskiv opened this issue Apr 17, 2015 · 0 comments

Comments

@ristovskiv
Copy link

I'm using rails 4.2 with pg database in a new project and used the rspec setup from the book, expect I've upgraded selenium-webdriver to the last ~> 2.45.0. But there is a problem with the shared db connection code.

 class ActiveRecord::Base
   mattr_accessor :shared_connection
   @@shared_connection = nil

   def self.connection
      @@shared_connection || retrieve_connection
   end
 end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

This gives me a PG connection error:

 PG::ConnectionBad: connection is closed:  (ActiveRecord::StatementInvalid)              
         SELECT COUNT(*)       
          FROM pg_class c
          LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
          WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view
          AND c.relname = 'schema_migrations'
          AND n.nspname = ANY (current_schemas(false))

Now I partially understand why this shared connection is done(correct me if I'm wrong, capybara with js driver and the app are in different threads so they are not sharing the same db connection). Now if I remove the last line from the shared_db_connection file and put it in a background block like this

   background do
       ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
   end

or put this line in rails_helper.rb the tests run without error. Now I wanna ask if this has the same effect as the one in the tutorial and what may be the reasons for this error?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant