Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mailer preview now uses url_for to fix links to emails for apps runnin... #19093

Merged
merged 1 commit into from
May 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions actionmailer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Mailer preview now uses `url_for` to fix links to emails for apps running on
a subdirectory.

*Remo Mueller*

* Mailer previews no longer crash when the `mail` method wasn't called
(`NullMail`).

Expand Down
4 changes: 2 additions & 2 deletions railties/lib/rails/templates/rails/mailers/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% @previews.each do |preview| %>
<h3><%= link_to preview.preview_name.titleize, "/rails/mailers/#{preview.preview_name}" %></h3>
<h3><%= link_to preview.preview_name.titleize, url_for(controller: "rails/mailers", action: "preview", path: preview.preview_name) %></h3>
<ul>
<% preview.emails.each do |email| %>
<li><%= link_to email, "/rails/mailers/#{preview.preview_name}/#{email}" %></li>
<li><%= link_to email, url_for(controller: "rails/mailers", action: "preview", path: "#{preview.preview_name}/#{email}") %></li>
<% end %>
</ul>
<% end %>
2 changes: 1 addition & 1 deletion railties/lib/rails/templates/rails/mailers/mailer.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h3><%= @preview.preview_name.titleize %></h3>
<ul>
<% @preview.emails.each do |email| %>
<li><%= link_to email, "/rails/mailers/#{@preview.preview_name}/#{email}" %></li>
<li><%= link_to email, url_for(controller: "rails/mailers", action: "preview", path: "#{@preview.preview_name}/#{email}") %></li>
<% end %>
</ul>
30 changes: 30 additions & 0 deletions railties/test/application/mailer_previews_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,36 @@ def foo
assert_match '<option selected value="?part=text%2Fplain">View as plain-text email</option>', last_response.body
end

test "mailer previews create correct links when loaded on a subdirectory" do
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

mailer_preview 'notifier', <<-RUBY
class NotifierPreview < ActionMailer::Preview
def foo
Notifier.foo
end
end
RUBY

app('development')

get "/rails/mailers", {}, 'SCRIPT_NAME' => '/my_app'
assert_match '<h3><a href="/my_app/rails/mailers/notifier">Notifier</a></h3>', last_response.body
assert_match '<li><a href="/my_app/rails/mailers/notifier/foo">foo</a></li>', last_response.body
end

private
def build_app
super
Expand Down