aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-08-31 19:11:15 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-08-31 19:17:42 +0100
commite9a8e0053be3b293ab89fb584f1d660063f107aa (patch)
tree045661abc41c4cc5123735702d57f6897a3787c1 /actionmailer/test
parent7ce03db77884e21256ba8f1615ad8dd841b76b86 (diff)
downloadrails-e9a8e0053be3b293ab89fb584f1d660063f107aa.tar.gz
rails-e9a8e0053be3b293ab89fb584f1d660063f107aa.tar.bz2
rails-e9a8e0053be3b293ab89fb584f1d660063f107aa.zip
Add layout functionality to mailers.
Mailer layouts behaves just like controller layouts, except layout names need to have '_mailer' postfix for them to be automatically picked up.
Diffstat (limited to 'actionmailer/test')
-rw-r--r--actionmailer/test/fixtures/auto_layout_mailer/hello.html.erb1
-rw-r--r--actionmailer/test/fixtures/explicit_layout_mailer/logout.html.erb1
-rw-r--r--actionmailer/test/fixtures/explicit_layout_mailer/signup.html.erb1
-rw-r--r--actionmailer/test/fixtures/layouts/auto_layout_mailer.html.erb1
-rw-r--r--actionmailer/test/fixtures/layouts/spam.html.erb1
-rw-r--r--actionmailer/test/mail_layout_test.rb78
6 files changed, 83 insertions, 0 deletions
diff --git a/actionmailer/test/fixtures/auto_layout_mailer/hello.html.erb b/actionmailer/test/fixtures/auto_layout_mailer/hello.html.erb
new file mode 100644
index 0000000000..54950788f7
--- /dev/null
+++ b/actionmailer/test/fixtures/auto_layout_mailer/hello.html.erb
@@ -0,0 +1 @@
+Inside \ No newline at end of file
diff --git a/actionmailer/test/fixtures/explicit_layout_mailer/logout.html.erb b/actionmailer/test/fixtures/explicit_layout_mailer/logout.html.erb
new file mode 100644
index 0000000000..0533a3b2fe
--- /dev/null
+++ b/actionmailer/test/fixtures/explicit_layout_mailer/logout.html.erb
@@ -0,0 +1 @@
+You logged out \ No newline at end of file
diff --git a/actionmailer/test/fixtures/explicit_layout_mailer/signup.html.erb b/actionmailer/test/fixtures/explicit_layout_mailer/signup.html.erb
new file mode 100644
index 0000000000..4789e888c6
--- /dev/null
+++ b/actionmailer/test/fixtures/explicit_layout_mailer/signup.html.erb
@@ -0,0 +1 @@
+We do not spam \ No newline at end of file
diff --git a/actionmailer/test/fixtures/layouts/auto_layout_mailer.html.erb b/actionmailer/test/fixtures/layouts/auto_layout_mailer.html.erb
new file mode 100644
index 0000000000..932271450c
--- /dev/null
+++ b/actionmailer/test/fixtures/layouts/auto_layout_mailer.html.erb
@@ -0,0 +1 @@
+Hello from layout <%= yield %> \ No newline at end of file
diff --git a/actionmailer/test/fixtures/layouts/spam.html.erb b/actionmailer/test/fixtures/layouts/spam.html.erb
new file mode 100644
index 0000000000..619d6b16b4
--- /dev/null
+++ b/actionmailer/test/fixtures/layouts/spam.html.erb
@@ -0,0 +1 @@
+Spammer layout <%= yield %> \ No newline at end of file
diff --git a/actionmailer/test/mail_layout_test.rb b/actionmailer/test/mail_layout_test.rb
new file mode 100644
index 0000000000..ffba9a16bd
--- /dev/null
+++ b/actionmailer/test/mail_layout_test.rb
@@ -0,0 +1,78 @@
+require 'abstract_unit'
+
+class AutoLayoutMailer < ActionMailer::Base
+ def hello(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ end
+
+ def spam(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ body render(:inline => "Hello, <%= @world %>", :layout => 'spam', :body => { :world => "Earth" })
+ end
+
+ def nolayout(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" })
+ end
+end
+
+class ExplicitLayoutMailer < ActionMailer::Base
+ layout 'spam', :except => [:logout]
+
+ def signup(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ end
+
+ def logout(recipient)
+ recipients recipient
+ subject "You have a mail"
+ from "tester@example.com"
+ end
+end
+
+class LayoutMailerTest < Test::Unit::TestCase
+ def setup
+ set_delivery_method :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries = []
+
+ @recipient = 'test@localhost'
+ end
+
+ def teardown
+ restore_delivery_method
+ end
+
+ def test_should_pickup_default_layout
+ mail = AutoLayoutMailer.create_hello(@recipient)
+ assert_equal "Hello from layout Inside", mail.body.strip
+ end
+
+ def test_should_pickup_layout_given_to_render
+ mail = AutoLayoutMailer.create_spam(@recipient)
+ assert_equal "Spammer layout Hello, Earth", mail.body.strip
+ end
+
+ def test_should_respect_layout_false
+ mail = AutoLayoutMailer.create_nolayout(@recipient)
+ assert_equal "Hello, Earth", mail.body.strip
+ end
+
+ def test_explicit_class_layout
+ mail = ExplicitLayoutMailer.create_signup(@recipient)
+ assert_equal "Spammer layout We do not spam", mail.body.strip
+ end
+
+ def test_explicit_layout_exceptions
+ mail = ExplicitLayoutMailer.create_logout(@recipient)
+ assert_equal "You logged out", mail.body.strip
+ end
+end