aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test
diff options
context:
space:
mode:
authorJeroen van Dijk and Josh Kalderimis <jeroen@jeevidee.nl>2010-07-23 14:42:21 +0200
committerJosé Valim <jose.valim@gmail.com>2010-07-24 00:27:25 +0200
commitaffeb51569d291ef7304189fd77b32c6e269af57 (patch)
tree08cfb54e995012e834075f34c352044526bdc0bd /actionmailer/test
parent5ebc1d88d3c80f8773d39b155a4e6f66544ec46b (diff)
downloadrails-affeb51569d291ef7304189fd77b32c6e269af57.tar.gz
rails-affeb51569d291ef7304189fd77b32c6e269af57.tar.bz2
rails-affeb51569d291ef7304189fd77b32c6e269af57.zip
Move config_accessor :asset_host from ActionController::Base to AbstractController which fixes issues with asset_host in ActionMailer
Including: - Moved mailer objects in separate directory - Added two tests for asset_host configuration option
Diffstat (limited to 'actionmailer/test')
-rw-r--r--actionmailer/test/base_test.rb156
-rw-r--r--actionmailer/test/fixtures/asset_mailer/welcome.html.erb1
-rw-r--r--actionmailer/test/mailers/asset_mailer.rb7
-rw-r--r--actionmailer/test/mailers/base_mailer.rb114
-rw-r--r--actionmailer/test/mailers/proc_mailer.rb16
5 files changed, 165 insertions, 129 deletions
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 5bc0491cff..e2b9df5d02 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -2,139 +2,17 @@
require 'abstract_unit'
require 'active_support/time'
+require 'mailers/base_mailer'
+require 'mailers/proc_mailer'
+require 'mailers/asset_mailer'
+
class BaseTest < ActiveSupport::TestCase
# TODO Add some tests for implicity layout render and url helpers
# so we can get rid of old base tests altogether with old base.
- class BaseMailer < ActionMailer::Base
- self.mailer_name = "base_mailer"
-
- default :to => 'system@test.lindsaar.net',
- :from => 'jose@test.plataformatec.com',
- :reply_to => 'mikel@test.lindsaar.net'
-
- def welcome(hash = {})
- headers['X-SPAM'] = "Not SPAM"
- mail({:subject => "The first email on new API!"}.merge!(hash))
- end
-
- def welcome_with_headers(hash = {})
- headers hash
- mail
- end
-
- def welcome_from_another_path(path)
- mail(:template_name => "welcome", :template_path => path)
- end
-
- def html_only(hash = {})
- mail(hash)
- end
-
- def plain_text_only(hash = {})
- mail(hash)
- end
-
- def inline_attachment
- attachments.inline['logo.png'] = "\312\213\254\232"
- mail
- end
-
- def attachment_with_content(hash = {})
- attachments['invoice.pdf'] = 'This is test File content'
- mail(hash)
- end
-
- def attachment_with_hash
- attachments['invoice.jpg'] = { :data => "\312\213\254\232)b",
- :mime_type => "image/x-jpg",
- :transfer_encoding => "base64" }
- mail
- end
-
- def attachment_with_hash_default_encoding
- attachments['invoice.jpg'] = { :data => "\312\213\254\232)b",
- :mime_type => "image/x-jpg" }
- mail
- end
-
- def implicit_multipart(hash = {})
- attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments)
- mail(hash)
- end
-
- def implicit_with_locale(hash = {})
- mail(hash)
- end
-
- def explicit_multipart(hash = {})
- attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments)
- mail(hash) do |format|
- format.text { render :text => "TEXT Explicit Multipart" }
- format.html { render :text => "HTML Explicit Multipart" }
- end
- end
-
- def explicit_multipart_templates(hash = {})
- mail(hash) do |format|
- format.html
- format.text
- end
- end
- def explicit_multipart_with_any(hash = {})
- mail(hash) do |format|
- format.any(:text, :html){ render :text => "Format with any!" }
- end
- end
-
- def explicit_multipart_with_options(include_html = false)
- mail do |format|
- format.text(:content_transfer_encoding => "base64"){ render "welcome" }
- format.html{ render "welcome" } if include_html
- end
- end
-
- def explicit_multipart_with_one_template(hash = {})
- mail(hash) do |format|
- format.html
- format.text
- end
- end
-
- def implicit_different_template(template_name='')
- mail(:template_name => template_name)
- end
-
- def explicit_different_template(template_name='')
- mail do |format|
- format.text { render :template => "#{mailer_name}/#{template_name}" }
- format.html { render :template => "#{mailer_name}/#{template_name}" }
- end
- end
-
- def different_layout(layout_name='')
- mail do |format|
- format.text { render :layout => layout_name }
- format.html { render :layout => layout_name }
- end
- end
- end
-
- class ProcMailer < ActionMailer::Base
- default :to => 'system@test.lindsaar.net',
- 'X-Proc-Method' => Proc.new { Time.now.to_i.to_s },
- :subject => Proc.new { give_a_greeting }
-
- def welcome
- mail
- end
-
- private
-
- def give_a_greeting
- "Thanks for signing up this afternoon"
- end
-
+ def teardown
+ ActionMailer::Base.asset_host = nil
+ ActionMailer::Base.assets_dir = nil
end
test "method call to mail does not raise error" do
@@ -570,6 +448,26 @@ class BaseTest < ActiveSupport::TestCase
assert_equal("Welcome from another path", mail.body.encoded)
end
+ test "assets tags should use ActionMailer's asset_host settings" do
+ ActionMailer::Base.config.asset_host = "http://global.com"
+ ActionMailer::Base.config.assets_dir = "global/"
+
+ mail = AssetMailer.welcome
+
+ assert_equal(%{<img alt="Dummy" src="http://global.com/images/dummy.png" />}, mail.body.to_s.strip)
+ end
+
+ test "assets tags should use a Mailer's asset_host settings when available" do
+ ActionMailer::Base.config.asset_host = "global.com"
+ ActionMailer::Base.config.assets_dir = "global/"
+
+ AssetMailer.asset_host = "http://local.com"
+
+ mail = AssetMailer.welcome
+
+ assert_equal(%{<img alt="Dummy" src="http://local.com/images/dummy.png" />}, mail.body.to_s.strip)
+ end
+
# Before and After hooks
class MyObserver
diff --git a/actionmailer/test/fixtures/asset_mailer/welcome.html.erb b/actionmailer/test/fixtures/asset_mailer/welcome.html.erb
new file mode 100644
index 0000000000..90d26130d9
--- /dev/null
+++ b/actionmailer/test/fixtures/asset_mailer/welcome.html.erb
@@ -0,0 +1 @@
+<%= image_tag "dummy.png" %> \ No newline at end of file
diff --git a/actionmailer/test/mailers/asset_mailer.rb b/actionmailer/test/mailers/asset_mailer.rb
new file mode 100644
index 0000000000..f54a50d00d
--- /dev/null
+++ b/actionmailer/test/mailers/asset_mailer.rb
@@ -0,0 +1,7 @@
+class AssetMailer < ActionMailer::Base
+ self.mailer_name = "asset_mailer"
+
+ def welcome
+ mail
+ end
+end
diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb
new file mode 100644
index 0000000000..2c6de36ccf
--- /dev/null
+++ b/actionmailer/test/mailers/base_mailer.rb
@@ -0,0 +1,114 @@
+class BaseMailer < ActionMailer::Base
+ self.mailer_name = "base_mailer"
+
+ default :to => 'system@test.lindsaar.net',
+ :from => 'jose@test.plataformatec.com',
+ :reply_to => 'mikel@test.lindsaar.net'
+
+ def welcome(hash = {})
+ headers['X-SPAM'] = "Not SPAM"
+ mail({:subject => "The first email on new API!"}.merge!(hash))
+ end
+
+ def welcome_with_headers(hash = {})
+ headers hash
+ mail
+ end
+
+ def welcome_from_another_path(path)
+ mail(:template_name => "welcome", :template_path => path)
+ end
+
+ def html_only(hash = {})
+ mail(hash)
+ end
+
+ def plain_text_only(hash = {})
+ mail(hash)
+ end
+
+ def inline_attachment
+ attachments.inline['logo.png'] = "\312\213\254\232"
+ mail
+ end
+
+ def attachment_with_content(hash = {})
+ attachments['invoice.pdf'] = 'This is test File content'
+ mail(hash)
+ end
+
+ def attachment_with_hash
+ attachments['invoice.jpg'] = { :data => "\312\213\254\232)b",
+ :mime_type => "image/x-jpg",
+ :transfer_encoding => "base64" }
+ mail
+ end
+
+ def attachment_with_hash_default_encoding
+ attachments['invoice.jpg'] = { :data => "\312\213\254\232)b",
+ :mime_type => "image/x-jpg" }
+ mail
+ end
+
+ def implicit_multipart(hash = {})
+ attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments)
+ mail(hash)
+ end
+
+ def implicit_with_locale(hash = {})
+ mail(hash)
+ end
+
+ def explicit_multipart(hash = {})
+ attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments)
+ mail(hash) do |format|
+ format.text { render :text => "TEXT Explicit Multipart" }
+ format.html { render :text => "HTML Explicit Multipart" }
+ end
+ end
+
+ def explicit_multipart_templates(hash = {})
+ mail(hash) do |format|
+ format.html
+ format.text
+ end
+ end
+
+ def explicit_multipart_with_any(hash = {})
+ mail(hash) do |format|
+ format.any(:text, :html){ render :text => "Format with any!" }
+ end
+ end
+
+ def explicit_multipart_with_options(include_html = false)
+ mail do |format|
+ format.text(:content_transfer_encoding => "base64"){ render "welcome" }
+ format.html{ render "welcome" } if include_html
+ end
+ end
+
+ def explicit_multipart_with_one_template(hash = {})
+ mail(hash) do |format|
+ format.html
+ format.text
+ end
+ end
+
+ def implicit_different_template(template_name='')
+ mail(:template_name => template_name)
+ end
+
+ def explicit_different_template(template_name='')
+ mail do |format|
+ format.text { render :template => "#{mailer_name}/#{template_name}" }
+ format.html { render :template => "#{mailer_name}/#{template_name}" }
+ end
+ end
+
+ def different_layout(layout_name='')
+ mail do |format|
+ format.text { render :layout => layout_name }
+ format.html { render :layout => layout_name }
+ end
+ end
+end
diff --git a/actionmailer/test/mailers/proc_mailer.rb b/actionmailer/test/mailers/proc_mailer.rb
new file mode 100644
index 0000000000..6a79cd71fc
--- /dev/null
+++ b/actionmailer/test/mailers/proc_mailer.rb
@@ -0,0 +1,16 @@
+class ProcMailer < ActionMailer::Base
+ default :to => 'system@test.lindsaar.net',
+ 'X-Proc-Method' => Proc.new { Time.now.to_i.to_s },
+ :subject => Proc.new { give_a_greeting }
+
+ def welcome
+ mail
+ end
+
+ private
+
+ def give_a_greeting
+ "Thanks for signing up this afternoon"
+ end
+
+end