aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Curtin <colin@procore.com>2008-11-20 13:39:34 -0800
committerPratik Naik <pratiknaik@gmail.com>2008-11-21 04:09:14 +0530
commit1d4554d766dbf8391689d91b4b88766757051c68 (patch)
treea71176f9a7bbf213d5902c7d77783959ede852ba
parent84583657f40e5554c496fb24dfbc1921f11b0498 (diff)
downloadrails-1d4554d766dbf8391689d91b4b88766757051c68.tar.gz
rails-1d4554d766dbf8391689d91b4b88766757051c68.tar.bz2
rails-1d4554d766dbf8391689d91b4b88766757051c68.zip
ActionMailer should respect content type when choosing layouts
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
-rw-r--r--actionmailer/lib/action_mailer/base.rb15
-rw-r--r--actionmailer/test/fixtures/auto_layout_mailer/multipart.text.html.erb1
-rw-r--r--actionmailer/test/fixtures/auto_layout_mailer/multipart.text.plain.erb1
-rw-r--r--actionmailer/test/fixtures/layouts/auto_layout_mailer.text.erb1
-rw-r--r--actionmailer/test/mail_layout_test.rb17
5 files changed, 33 insertions, 2 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 19ce77ea5a..e41c88d81b 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -549,7 +549,12 @@ module ActionMailer #:nodoc:
end
def render_message(method_name, body)
+ if method_name.respond_to?(:content_type)
+ @current_template_content_type = method_name.content_type
+ end
render :file => method_name, :body => body
+ ensure
+ @current_template_content_type = nil
end
def render(opts)
@@ -568,7 +573,11 @@ module ActionMailer #:nodoc:
end
def default_template_format
- :html
+ if @current_template_content_type
+ Mime::Type.lookup(@current_template_content_type).to_sym
+ else
+ :html
+ end
end
def candidate_for_layout?(options)
@@ -588,7 +597,9 @@ module ActionMailer #:nodoc:
end
def initialize_template_class(assigns)
- ActionView::Base.new(view_paths, assigns, self)
+ template = ActionView::Base.new(view_paths, assigns, self)
+ template.template_format = default_template_format
+ template
end
def sort_parts(parts, order = [])
diff --git a/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.html.erb b/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.html.erb
new file mode 100644
index 0000000000..6d73f199c4
--- /dev/null
+++ b/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.html.erb
@@ -0,0 +1 @@
+text/html multipart \ No newline at end of file
diff --git a/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.plain.erb b/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.plain.erb
new file mode 100644
index 0000000000..f4b91e4031
--- /dev/null
+++ b/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.plain.erb
@@ -0,0 +1 @@
+text/plain multipart \ No newline at end of file
diff --git a/actionmailer/test/fixtures/layouts/auto_layout_mailer.text.erb b/actionmailer/test/fixtures/layouts/auto_layout_mailer.text.erb
new file mode 100644
index 0000000000..111576b672
--- /dev/null
+++ b/actionmailer/test/fixtures/layouts/auto_layout_mailer.text.erb
@@ -0,0 +1 @@
+text/plain layout - <%= yield %> \ No newline at end of file
diff --git a/actionmailer/test/mail_layout_test.rb b/actionmailer/test/mail_layout_test.rb
index ffba9a16bd..c185bd5acd 100644
--- a/actionmailer/test/mail_layout_test.rb
+++ b/actionmailer/test/mail_layout_test.rb
@@ -20,6 +20,12 @@ class AutoLayoutMailer < ActionMailer::Base
from "tester@example.com"
body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" })
end
+
+ def multipart(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ end
end
class ExplicitLayoutMailer < ActionMailer::Base
@@ -56,6 +62,17 @@ class LayoutMailerTest < Test::Unit::TestCase
assert_equal "Hello from layout Inside", mail.body.strip
end
+ def test_should_pickup_multipart_layout
+ mail = AutoLayoutMailer.create_multipart(@recipient)
+ assert_equal 2, mail.parts.size
+
+ assert_equal 'text/plain', mail.parts.first.content_type
+ assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
+
+ assert_equal 'text/html', mail.parts.last.content_type
+ assert_equal "Hello from layout text/html multipart", mail.parts.last.body
+ end
+
def test_should_pickup_layout_given_to_render
mail = AutoLayoutMailer.create_spam(@recipient)
assert_equal "Spammer layout Hello, Earth", mail.body.strip