Reputation: 24399
In my test_helper.rb
file I override one method on one model for testing purposes. Let's call it Foo
.
Suppose I add debug statements as such:
#in app/models/foo.rb
class Foo
puts "loading class Foo from app/models"
...
end
and:
#in test/test_hepler.rb
class Foo
puts "loading class Foo from test/test_hepler"
...
end
In in Rails 3, I see on the console:
>loading class Foo from app/models
>loading class Foo from test/test_hepler
In Rails 4, (even with config.eager_load = true
) I see only:
>loading class Foo from test/test_hepler
Why this difference? Also, what is the preferred fix? Simply require 'Foo'
before I open it for extension?
Upvotes: 2
Views: 64
Reputation: 84114
If you change test_helper to do
Foo.class_eval do
...
end
Then rails is forced to load your Foo model (so that it can call class_eval
on it)
As to why the test initialisation process changed you would have to dig back through the changelogs/commits - there definitely were changes around how/when you app code is preloaded.
Upvotes: 2