diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-08-11 17:54:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-11 17:54:04 -0400 |
commit | b9e0b4f19940fdd7105db3dffc507cbd89ac3705 (patch) | |
tree | 3f24b1728f9bf86c029a7897c91e1fa36d43204d /railties/test/application | |
parent | c8bbeb31dd402bb4a907a9b8ef021bf8e1afe2aa (diff) | |
parent | 0668c22a41e4c88ccb7600fc5b4bfb1a5b76e45d (diff) | |
download | rails-b9e0b4f19940fdd7105db3dffc507cbd89ac3705.tar.gz rails-b9e0b4f19940fdd7105db3dffc507cbd89ac3705.tar.bz2 rails-b9e0b4f19940fdd7105db3dffc507cbd89ac3705.zip |
Merge pull request #29559 from kirs/eager-load-controller-actions
Eager load controller actions to reduce response time of the first request
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/configuration_test.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index c2f6a5a95c..482da98a45 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -238,6 +238,66 @@ module ApplicationTests assert_instance_of Pathname, Rails.public_path end + test "does not eager load controller actions in development" do + app_file "app/controllers/posts_controller.rb", <<-RUBY + class PostsController < ActionController::Base + def index;end + def show;end + end + RUBY + + app "development" + + assert_nil PostsController.instance_variable_get(:@action_methods) + end + + test "eager loads controller actions in production" do + app_file "app/controllers/posts_controller.rb", <<-RUBY + class PostsController < ActionController::Base + def index;end + def show;end + end + RUBY + + add_to_config <<-RUBY + config.eager_load = true + config.cache_classes = true + RUBY + + app "production" + + assert_equal %w(index show).to_set, PostsController.instance_variable_get(:@action_methods) + end + + test "does not eager load mailer actions in development" do + app_file "app/mailers/posts_mailer.rb", <<-RUBY + class PostsMailer < ActionMailer::Base + def noop_email;end + end + RUBY + + app "development" + + assert_nil PostsMailer.instance_variable_get(:@action_methods) + end + + test "eager loads mailer actions in production" do + app_file "app/mailers/posts_mailer.rb", <<-RUBY + class PostsMailer < ActionMailer::Base + def noop_email;end + end + RUBY + + add_to_config <<-RUBY + config.eager_load = true + config.cache_classes = true + RUBY + + app "production" + + assert_equal %w(noop_email).to_set, PostsMailer.instance_variable_get(:@action_methods) + end + test "initialize an eager loaded, cache classes app" do add_to_config <<-RUBY config.eager_load = true |