From 3713e433667ee95caccb53a4062f540405272234 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sat, 4 Jan 2014 18:42:34 +0000 Subject: Add preview_path to autoload_paths in after_initialize Only config.autoload_paths is frozen, so add the preview_path to ActiveSupport::Dependencies.autoload_paths directly in an after_initialize block. Also protect against a blank preview_path being added to autoload_paths which can cause a serious slowdown as Dir[] tries to load all *_preview.rb files under / Fixes #13372 --- railties/test/application/mailer_previews_test.rb | 42 ++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/mailer_previews_test.rb b/railties/test/application/mailer_previews_test.rb index 14abb33cc6..c588fd7012 100644 --- a/railties/test/application/mailer_previews_test.rb +++ b/railties/test/application/mailer_previews_test.rb @@ -225,6 +225,46 @@ module ApplicationTests assert_no_match '
  • bar
  • ', last_response.body end + test "mailer previews are reloaded from a custom preview_path" do + add_to_config "config.action_mailer.preview_path = '#{app_path}/lib/mailer_previews'" + + app('development') + + get "/rails/mailers" + assert_no_match '

    Notifier

    ', last_response.body + + mailer 'notifier', <<-RUBY + class Notifier < ActionMailer::Base + default from: "from@example.com" + + def foo + mail to: "to@example.org" + end + end + RUBY + + text_template 'notifier/foo', <<-RUBY + Hello, World! + RUBY + + app_file 'lib/mailer_previews/notifier_preview.rb', <<-RUBY + class NotifierPreview < ActionMailer::Preview + def foo + Notifier.foo + end + end + RUBY + + get "/rails/mailers" + assert_match '

    Notifier

    ', last_response.body + + remove_file 'lib/mailer_previews/notifier_preview.rb' + sleep(1) + + get "/rails/mailers" + assert_no_match '

    Notifier

    ', last_response.body + end + test "mailer preview not found" do app('development') get "/rails/mailers/notifier" @@ -366,7 +406,7 @@ module ApplicationTests private def build_app super - app_file 'config/routes.rb', "Rails.application.routes.draw do; end" + app_file "config/routes.rb", "Rails.application.routes.draw do; end" end def mailer(name, contents) -- cgit v1.2.3