collectiveidea/delayed_job_active_record — Issue #10: clean rails3 app raises ActiveRecord::ConnectionNotEstablished
Author: nessence
Created: 2012-01-13 20:25:49+00:00
State: open

to reproduce:

$ rails new railsfail
$ echo "gem 'delayed_job_active_record'" >> Gemfile
$ bundle install

$ bundle exec rake -T
rake aborted!
ActiveRecord::ConnectionNotEstablished

$ bundle exec rails g delayed_job:active_record
/Users/nessence/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:318:in `retrieve_connection': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
...
from /Users/nessence/.rvm/gems/ruby-1.9.2-p290/gems/delayed_job_active_record-0.3.1/lib/delayed/backend/active_record.rb:25:in `'
...

Also caused by simple command-line use:
$ irb
1.9.2-p290 :001 > require 'rubygems'
=> false
1.9.2-p290 :002 > require 'delayed_job_active_record'
ActiveRecord::ConnectionNotEstablished: ActiveRecord::ConnectionNotEstablished

This is from a fresh install of ruby via 'rvm install 1.9.2' and is triggered by the call to scope in active_record.rb (see trace).

What's the best way around this bug and/or to [safely] establish a connection for DJ before the ActiveRecord model is evaluated? [w/o upgrading rails]

For reference
$ bundle list
Gems included by the bundle:
* [standard rails3, rack, etc. gems]
* bundler (1.0.21)
* delayed_job (3.0.0)
* delayed_job_active_record (0.3.1)
* rake (0.9.2)