aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2014-01-04 18:42:34 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2014-01-04 18:42:34 +0000
commit3713e433667ee95caccb53a4062f540405272234 (patch)
tree42307a827be7815213d771eab0b6baf1efef6e34 /railties
parent81066b115817a4c95c83a76553954317f737cd14 (diff)
downloadrails-3713e433667ee95caccb53a4062f540405272234.tar.gz
rails-3713e433667ee95caccb53a4062f540405272234.tar.bz2
rails-3713e433667ee95caccb53a4062f540405272234.zip
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
Diffstat (limited to 'railties')
-rw-r--r--railties/test/application/mailer_previews_test.rb42
1 files changed, 41 insertions, 1 deletions
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 '<li><a href="/rails/mailers/notifier/bar">bar</a></li>', 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 '<h3><a href="/rails/mailers/notifier">Notifier</a></h3>', 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 '<h3><a href="/rails/mailers/notifier">Notifier</a></h3>', last_response.body
+
+ remove_file 'lib/mailer_previews/notifier_preview.rb'
+ sleep(1)
+
+ get "/rails/mailers"
+ assert_no_match '<h3><a href="/rails/mailers/notifier">Notifier</a></h3>', 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)