Permalink
Browse files

Add some view paths tests.

  • Loading branch information...
1 parent 90e9e46 commit 48faf53be19c569e85f43a4dbfa63fe81618b09f Jos�� Valim and Mikel Lindsaar committed Jan 24, 2010
Showing with 43 additions and 23 deletions.
  1. +42 −23 actionmailer/test/base_test.rb
  2. +1 −0 actionmailer/test/fixtures/another.path/base_mailer/welcome.erb
@@ -238,6 +238,48 @@ def explicit_multipart_with_any(hash = {})
end
end
+ test "implicit multipart with default locale" do
+ email = BaseMailer.implicit_with_locale.deliver
+ assert_equal(2, email.parts.size)
+ assert_equal("multipart/alternate", email.mime_type)
+ assert_equal("text/plain", email.parts[0].mime_type)
+ assert_equal("Implicit with locale TEXT", email.parts[0].body.encoded)
+ assert_equal("text/html", email.parts[1].mime_type)
+ assert_equal("Implicit with locale EN HTML", email.parts[1].body.encoded)
+ end
+
+ test "implicit multipart with other locale" do
+ swap I18n, :locale => :pl do
+ email = BaseMailer.implicit_with_locale.deliver
+ assert_equal(2, email.parts.size)
+ assert_equal("multipart/alternate", email.mime_type)
+ assert_equal("text/plain", email.parts[0].mime_type)
+ assert_equal("Implicit with locale PL TEXT", email.parts[0].body.encoded)
+ assert_equal("text/html", email.parts[1].mime_type)
+ assert_equal("Implicit with locale HTML", email.parts[1].body.encoded)
+ end
+ end
+
+ test "implicit multipart with several view paths uses the first one with template" do
+ begin
+ BaseMailer.view_paths.unshift(File.join(FIXTURE_LOAD_PATH, "another.path"))
+ email = BaseMailer.welcome.deliver
+ assert_equal("Welcome from another path", email.body.encoded)
+ ensure
+ BaseMailer.view_paths.shift
+ end
+ end
+
+ test "implicit multipart with inexistent templates uses the next view path" do
+ begin
+ BaseMailer.view_paths.unshift(File.join(FIXTURE_LOAD_PATH, "unknown"))
+ email = BaseMailer.welcome.deliver
+ assert_equal("Welcome", email.body.encoded)
+ ensure
+ BaseMailer.view_paths.shift
+ end
+ end
+
# Explicit multipart
test "explicit multipart" do
email = BaseMailer.explicit_multipart.deliver
@@ -314,29 +356,6 @@ def explicit_multipart_with_any(hash = {})
assert_equal(1, BaseMailer.deliveries.length)
end
- test "implicit multipart with default locale" do
- email = BaseMailer.implicit_with_locale.deliver
- assert_equal(2, email.parts.size)
- assert_equal("multipart/alternate", email.mime_type)
- assert_equal("text/plain", email.parts[0].mime_type)
- assert_equal("Implicit with locale TEXT", email.parts[0].body.encoded)
- assert_equal("text/html", email.parts[1].mime_type)
- assert_equal("Implicit with locale EN HTML", email.parts[1].body.encoded)
- end
-
- test "implicit multipart with other locale" do
- swap I18n, :locale => :pl do
- email = BaseMailer.implicit_with_locale.deliver
- assert_equal(2, email.parts.size)
- assert_equal("multipart/alternate", email.mime_type)
- assert_equal("text/plain", email.parts[0].mime_type)
- assert_equal("Implicit with locale PL TEXT", email.parts[0].body.encoded)
- assert_equal("text/html", email.parts[1].mime_type)
- assert_equal("Implicit with locale HTML", email.parts[1].body.encoded)
- end
- end
-
-
protected
# Execute the block setting the given values and restoring old values after
@@ -0,0 +1 @@
+Welcome from another path

0 comments on commit 48faf53

Please sign in to comment.