Jason Waldrip
2013-Apr-21  21:39 UTC
Rails 3.2 initializers load order causes failures when config.cache_clases == true
Hey all, we are in the midst of upgrading our app from rails 3.0.20 to 
rails 3.2.13. As part of this upgrade we are experiencing an issue in our 
test suite in which when cache classes is turned on our models are loading 
before our initializers. One of our initializers sets up some constants 
that one of our models uses at load time. Has anyone experienced anything 
that seems similar to this and if you could you point me the right 
direction to finding a solution.
example of what is happening:
#config/environments/test.rb
ApiServer::Application.configure do
  # Settings specified here will take precedence over those in 
config/environment.rb
  # The test environment is used exclusively to run your application''s
  # test suite.  You never need to work with it otherwise.  Remember that
  # your test database is "scratch space" for the test suite and is
wiped
  # and recreated between test runs.  Don''t rely on the data there!
  config.cache_classes = true
  # Log error messages when you accidentally call methods on nil.
  config.whiny_nils = true
  # Show full error reports and disable caching
  config.consider_all_requests_local = true
  config.action_controller.perform_caching             = false
  config.consider_all_requests_local                   = true
  # Set host for using url helpers in mailers
  config.action_mailer.default_url_options = { :host =>
"localhost:3000" }
  # Disable request forgery protection in test environment
  config.action_controller.allow_forgery_protection    = false
  config.active_support.deprecation = :log
  # Tell Action Mailer not to deliver emails to the real world.
  # The :test delivery method accumulates sent emails in the
  # ActionMailer::Base.deliveries array.
  config.action_mailer.delivery_method = :test
  # Use SQL instead of Active Record''s schema dumper when creating the
test
database.
  # This is necessary if your schema can''t be completely dumped by the 
schema dumper,
  # like if you have constraints or database-specific column types
  # config.active_record.schema_format = :sql
  config.supports_ssl = false
  config.force_ssl = false
end
#config/initializers/set_adapters.rb
config = YAML.load(Rails.root.join ''config'',
''adapters.yml'')[Rails.env]
config do |k, v|
  const_set "ADAPTER_#{k}", v
end
#models/uses_adapter.rb
class BaseAdapter < ActiveResource::Base
   self.path = ADAPTER_PATH
   # ...
end
# ERROR
$ rails c test
/Users/jwaldrip/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/aws-s3-0.6.3/lib/aws/s3/extensions.rb:212:in
`const_missing_from_s3_library'': uninitialized constant 
BaseAdapter::ADAPTER_PATH (NameError)
...
  
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/2fCX1VkuhSUJ.
For more options, visit https://groups.google.com/groups/opt_out.