-
-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecation warning on new Rails 3.1 install #169
Comments
http://martinciu.com/2011/07/difference-between-class_inheritable_attribute-and-class_attribute.html Offending method is in if defined?(ActiveRecord::Base)
class ActiveRecord::Base
class_inheritable_accessor :shared_connection
def self.connection
self.shared_connection || retrieve_connection
end
end
Before('@javascript') do
# Forces all threads to share a connection on a per-model basis,
# as connections may vary per model as per establish_connection. This works
# on Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
ActiveRecord::Base.descendants.each do |model|
model.shared_connection = model.connection
end
end
Before('~@javascript') do
# Do not use a shared connection unless we're in a @javascript scenario
ActiveRecord::Base.shared_connection = nil
ActiveRecord::Base.descendants.each do |model|
model.shared_connection = nil
end
end
end I've tried replacing the method with What do you guys think? |
Created a pull request for this: #170 All tests pass before and after. I figured a new test wasn't required for this. |
How will this fly on older versions of Rails? |
|
Looking at this again, I think we actually may need to keep the two The first block I misread the first time through. The values of connection could change on a per-model basis, and The second block would be redundant with the new semantics of I wish I better understood the purpose of |
On 18 Sep 2011, at 18:28, Micah Geisel wrote:
The purpose is to help transactional database cleaning between scenarios to work. There are a few different ways to do it, and this was based on a hack of @josevalim's that @jnickas suggested. I think the idea is to ensure that ActiveRecord uses the same connection object across threads (since Capybara runs the Rails server in a separate thread). I've tried to find a reference to the discussion on the mailing list about this (there have been many) but you might be better off just looking at the history of the code. |
@winnipegtransit do you have any views on this? You provided the fix for #152 so maybe you know whether or not to keep iterating over descendants? |
I think iterating over descendants is necessary. Like @botandrose said, each model could potentially be connected to a different database and thus have a different connection, so we do need to copy them over individually; just copying the topmost connection won't work. I didn't use If you do change the code to use |
@winnipegtransit - thanks for the heads up. Any chance you could run your tests with #170 applied? |
env.rb is giving me this error:
The text was updated successfully, but these errors were encountered: