diff options
author | José Valim <jose.valim@gmail.com> | 2012-08-01 15:07:01 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-08-21 14:46:12 -0300 |
commit | e6747d87f3a061d153215715d56acbb0be20191f (patch) | |
tree | 7466bf0ceff18642e3e1d154419b05d6414e2be0 /railties/test/application | |
parent | df1a5e492ae178856f6cf92ae70ce620f4cd0613 (diff) | |
download | rails-e6747d87f3a061d153215715d56acbb0be20191f.tar.gz rails-e6747d87f3a061d153215715d56acbb0be20191f.tar.bz2 rails-e6747d87f3a061d153215715d56acbb0be20191f.zip |
Allow users to choose when to eager_load the application or not.
Previously, the eager load behavior was mostly coupled to
config.cache_classes, however this was suboptimal since in
some environments a developer may want to cache classes but
not necessarily load them all on boot (for example, test env).
This pull request also promotes the use of config.eager_load
set to true by default in production. In the majority of the
cases, this is the behavior you want since it will copy most
of your app into memory on boot (which was also the previous
behavior).
Finally, this fix a long standing Rails bug where it was
impossible to access a model in a rake task when Rails was
set as thread safe.
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/rake_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index a450f90dbf..5d7fa7e397 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -55,6 +55,30 @@ module ApplicationTests assert_match "Doing something...", output end + def test_does_not_explode_when_accessing_a_model_with_eager_load + add_to_config <<-RUBY + config.eager_load = true + + rake_tasks do + task :do_nothing => :environment do + Hello.new.world + end + end + RUBY + + app_file "app/models/hello.rb", <<-RUBY + class Hello + def world + puts "Hello world" + end + end + RUBY + + output = Dir.chdir(app_path){ `rake do_nothing` } + puts output + assert_match "Hello world", output + end + def test_code_statistics_sanity assert_match "Code LOC: 5 Test LOC: 0 Code to Test Ratio: 1:0.0", Dir.chdir(app_path){ `rake stats` } |