Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.2 models loading before initializers in the test environment

I am upgrading a rails app from 3.0.20 to 3.2.13. It seems that when my test environment has cache_classes set to true the models are getting loaded before the initializers. This is causing some errors since my initializers have some setup code for some of the models. What is also strange is that in production with cache_classes=true, I do not experience the same issue. Could anyone point me in the right direction here.

like image 635
Jason Waldrip Avatar asked Dec 17 '25 04:12

Jason Waldrip


1 Answers

Try adding this to your config/environments/test.rb file. It will load your intializers before the classes are cached:

  # Load initializers before models get cached
  config.before_eager_load do
    Dir[File.expand_path "../../initializers/*", __FILE__].each { |file| require file }
  end

Alternatively, you might check to make sure that you don't have a gem that is loading the models before the initializers are being called.

like image 174
Tom Chapin Avatar answered Dec 20 '25 01:12

Tom Chapin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!