legacy_mailers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +29 -0
- data/lib/action_mailer/adv_attr_accessor.rb +28 -0
- data/lib/action_mailer/deprecated_api.rb +152 -0
- data/lib/action_mailer/old_api.rb +258 -0
- data/lib/legacy_mailers.rb +10 -0
- data/lib/legacy_mailers/version.rb +3 -0
- data/test/abstract_unit.rb +70 -0
- data/test/adv_attr_test.rb +36 -0
- data/test/asset_host_test.rb +56 -0
- data/test/fixtures/another.path/base_mailer/welcome.erb +1 -0
- data/test/fixtures/asset_host_mailer/email_with_asset.html.erb +1 -0
- data/test/fixtures/asset_mailer/welcome.html.erb +1 -0
- data/test/fixtures/attachments/foo.jpg +0 -0
- data/test/fixtures/attachments/test.jpg +0 -0
- data/test/fixtures/auto_layout_mailer/hello.html.erb +1 -0
- data/test/fixtures/auto_layout_mailer/multipart.html.erb +1 -0
- data/test/fixtures/auto_layout_mailer/multipart.text.erb +1 -0
- data/test/fixtures/base_mailer/attachment_with_content.erb +1 -0
- data/test/fixtures/base_mailer/different_layout.html.erb +1 -0
- data/test/fixtures/base_mailer/different_layout.text.erb +1 -0
- data/test/fixtures/base_mailer/email_custom_layout.text.html.erb +1 -0
- data/test/fixtures/base_mailer/email_with_translations.html.erb +1 -0
- data/test/fixtures/base_mailer/explicit_multipart_templates.html.erb +1 -0
- data/test/fixtures/base_mailer/explicit_multipart_templates.text.erb +1 -0
- data/test/fixtures/base_mailer/explicit_multipart_with_one_template.erb +1 -0
- data/test/fixtures/base_mailer/html_only.html.erb +1 -0
- data/test/fixtures/base_mailer/implicit_multipart.html.erb +1 -0
- data/test/fixtures/base_mailer/implicit_multipart.text.erb +1 -0
- data/test/fixtures/base_mailer/implicit_with_locale.en.html.erb +1 -0
- data/test/fixtures/base_mailer/implicit_with_locale.html.erb +1 -0
- data/test/fixtures/base_mailer/implicit_with_locale.pl.text.erb +1 -0
- data/test/fixtures/base_mailer/implicit_with_locale.text.erb +1 -0
- data/test/fixtures/base_mailer/inline_attachment.html.erb +5 -0
- data/test/fixtures/base_mailer/inline_attachment.text.erb +4 -0
- data/test/fixtures/base_mailer/plain_text_only.text.erb +1 -0
- data/test/fixtures/base_mailer/welcome.erb +1 -0
- data/test/fixtures/explicit_layout_mailer/logout.html.erb +1 -0
- data/test/fixtures/explicit_layout_mailer/signup.html.erb +1 -0
- data/test/fixtures/first_mailer/share.erb +1 -0
- data/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb +4 -0
- data/test/fixtures/layouts/auto_layout_mailer.html.erb +1 -0
- data/test/fixtures/layouts/auto_layout_mailer.text.erb +1 -0
- data/test/fixtures/layouts/different_layout.html.erb +1 -0
- data/test/fixtures/layouts/different_layout.text.erb +1 -0
- data/test/fixtures/layouts/spam.html.erb +1 -0
- data/test/fixtures/nested_layout_mailer/signup.html.erb +1 -0
- data/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb +1 -0
- data/test/fixtures/raw_email +14 -0
- data/test/fixtures/raw_email10 +20 -0
- data/test/fixtures/raw_email12 +32 -0
- data/test/fixtures/raw_email13 +29 -0
- data/test/fixtures/raw_email2 +114 -0
- data/test/fixtures/raw_email3 +70 -0
- data/test/fixtures/raw_email4 +59 -0
- data/test/fixtures/raw_email5 +19 -0
- data/test/fixtures/raw_email6 +20 -0
- data/test/fixtures/raw_email7 +66 -0
- data/test/fixtures/raw_email8 +47 -0
- data/test/fixtures/raw_email9 +28 -0
- data/test/fixtures/raw_email_quoted_with_0d0a +14 -0
- data/test/fixtures/raw_email_with_invalid_characters_in_content_type +104 -0
- data/test/fixtures/raw_email_with_nested_attachment +100 -0
- data/test/fixtures/raw_email_with_partially_quoted_subject +14 -0
- data/test/fixtures/second_mailer/share.erb +1 -0
- data/test/fixtures/templates/signed_up.erb +3 -0
- data/test/fixtures/test_mailer/_subtemplate.text.erb +1 -0
- data/test/fixtures/test_mailer/custom_templating_extension.html.haml +6 -0
- data/test/fixtures/test_mailer/custom_templating_extension.text.haml +6 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.html.erb +10 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.html.erb~ +10 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.ignored.erb +1 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.rhtml.bak +1 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.text.erb +2 -0
- data/test/fixtures/test_mailer/implicitly_multipart_example.yaml.erb +1 -0
- data/test/fixtures/test_mailer/included_subtemplate.text.erb +1 -0
- data/test/fixtures/test_mailer/multipart_alternative.html.erb +1 -0
- data/test/fixtures/test_mailer/multipart_alternative.plain.erb +1 -0
- data/test/fixtures/test_mailer/rxml_template.rxml +2 -0
- data/test/fixtures/test_mailer/signed_up.html.erb +3 -0
- data/test/fixtures/url_test_mailer/signed_up_with_url.erb +5 -0
- data/test/mail_layout_test.rb +126 -0
- data/test/mail_render_test.rb +162 -0
- data/test/mail_service_test.rb +1214 -0
- metadata +308 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
From jamis@37signals.com Mon May 2 16:07:05 2005
|
2
|
+
Mime-Version: 1.0 (Apple Message framework v622)
|
3
|
+
Content-Transfer-Encoding: base64
|
4
|
+
Message-Id: <d3b8cf8e49f04480850c28713a1f473e@37signals.com>
|
5
|
+
Content-Type: text/plain;
|
6
|
+
charset=EUC-KR;
|
7
|
+
format=flowed
|
8
|
+
To: jamis@37signals.com
|
9
|
+
From: Jamis Buck <jamis@37signals.com>
|
10
|
+
Subject: Re: Test: =?UTF-8?B?Iua8ouWtlyI=?= mid =?UTF-8?B?Iua8ouWtlyI=?= tail
|
11
|
+
Date: Mon, 2 May 2005 16:07:05 -0600
|
12
|
+
|
13
|
+
tOu6zrrQwMcguLbC+bChwfa3ziwgv+y4rrTCIMfPs6q01MC7ILnPvcC0z7TZLg0KDQrBpiDAzLin
|
14
|
+
wLogSmFtaXPA1LTPtNku
|
@@ -0,0 +1 @@
|
|
1
|
+
second mail
|
@@ -0,0 +1 @@
|
|
1
|
+
let's go!
|
@@ -0,0 +1 @@
|
|
1
|
+
Ignored when searching for implicitly multipart parts.
|
@@ -0,0 +1 @@
|
|
1
|
+
Ignored when searching for implicitly multipart parts.
|
@@ -0,0 +1 @@
|
|
1
|
+
yaml to: <%= @recipient %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Hey Ho, <%= render :partial => "subtemplate" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<strong>foo</strong> <%= @foo %>
|
@@ -0,0 +1 @@
|
|
1
|
+
foo: <%= @foo %>
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class AutoLayoutMailer < ActionMailer::Base
|
4
|
+
|
5
|
+
def hello
|
6
|
+
recipients 'test@localhost'
|
7
|
+
subject "You have a mail"
|
8
|
+
from "tester@example.com"
|
9
|
+
end
|
10
|
+
|
11
|
+
def spam
|
12
|
+
recipients 'test@localhost'
|
13
|
+
subject "You have a mail"
|
14
|
+
from "tester@example.com"
|
15
|
+
|
16
|
+
@world = "Earth"
|
17
|
+
body render(:inline => "Hello, <%= @world %>", :layout => 'spam')
|
18
|
+
end
|
19
|
+
|
20
|
+
def nolayout
|
21
|
+
recipients 'test@localhost'
|
22
|
+
subject "You have a mail"
|
23
|
+
from "tester@example.com"
|
24
|
+
|
25
|
+
@world = "Earth"
|
26
|
+
body render(:inline => "Hello, <%= @world %>", :layout => false)
|
27
|
+
end
|
28
|
+
|
29
|
+
def multipart(type = nil)
|
30
|
+
recipients 'test@localhost'
|
31
|
+
subject "You have a mail"
|
32
|
+
from "tester@example.com"
|
33
|
+
|
34
|
+
content_type(type) if type
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class ExplicitLayoutMailer < ActionMailer::Base
|
39
|
+
layout 'spam', :except => [:logout]
|
40
|
+
|
41
|
+
def signup
|
42
|
+
recipients 'test@localhost'
|
43
|
+
subject "You have a mail"
|
44
|
+
from "tester@example.com"
|
45
|
+
end
|
46
|
+
|
47
|
+
def logout
|
48
|
+
recipients 'test@localhost'
|
49
|
+
subject "You have a mail"
|
50
|
+
from "tester@example.com"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class LayoutMailerTest < Test::Unit::TestCase
|
55
|
+
def setup
|
56
|
+
set_delivery_method :test
|
57
|
+
ActionMailer::Base.perform_deliveries = true
|
58
|
+
ActionMailer::Base.deliveries.clear
|
59
|
+
end
|
60
|
+
|
61
|
+
def teardown
|
62
|
+
restore_delivery_method
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_should_pickup_default_layout
|
66
|
+
mail = AutoLayoutMailer.hello
|
67
|
+
assert_equal "Hello from layout Inside", mail.body.to_s.strip
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_should_pickup_multipart_layout
|
71
|
+
mail = AutoLayoutMailer.multipart
|
72
|
+
assert_equal "multipart/alternative", mail.mime_type
|
73
|
+
assert_equal 2, mail.parts.size
|
74
|
+
|
75
|
+
assert_equal 'text/plain', mail.parts.first.mime_type
|
76
|
+
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
|
77
|
+
|
78
|
+
assert_equal 'text/html', mail.parts.last.mime_type
|
79
|
+
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_should_pickup_multipartmixed_layout
|
83
|
+
mail = AutoLayoutMailer.multipart("multipart/mixed")
|
84
|
+
assert_equal "multipart/mixed", mail.mime_type
|
85
|
+
assert_equal 2, mail.parts.size
|
86
|
+
|
87
|
+
assert_equal 'text/plain', mail.parts.first.mime_type
|
88
|
+
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
|
89
|
+
|
90
|
+
assert_equal 'text/html', mail.parts.last.mime_type
|
91
|
+
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_should_fix_multipart_layout
|
95
|
+
mail = AutoLayoutMailer.multipart("text/plain")
|
96
|
+
assert_equal "multipart/alternative", mail.mime_type
|
97
|
+
assert_equal 2, mail.parts.size
|
98
|
+
|
99
|
+
assert_equal 'text/plain', mail.parts.first.mime_type
|
100
|
+
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
|
101
|
+
|
102
|
+
assert_equal 'text/html', mail.parts.last.mime_type
|
103
|
+
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def test_should_pickup_layout_given_to_render
|
108
|
+
mail = AutoLayoutMailer.spam
|
109
|
+
assert_equal "Spammer layout Hello, Earth", mail.body.to_s.strip
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_should_respect_layout_false
|
113
|
+
mail = AutoLayoutMailer.nolayout
|
114
|
+
assert_equal "Hello, Earth", mail.body.to_s.strip
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_explicit_class_layout
|
118
|
+
mail = ExplicitLayoutMailer.signup
|
119
|
+
assert_equal "Spammer layout We do not spam", mail.body.to_s.strip
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_explicit_layout_exceptions
|
123
|
+
mail = ExplicitLayoutMailer.logout
|
124
|
+
assert_equal "You logged out", mail.body.to_s.strip
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class RenderMailer < ActionMailer::Base
|
4
|
+
def inline_template
|
5
|
+
recipients 'test@localhost'
|
6
|
+
subject "using helpers"
|
7
|
+
from "tester@example.com"
|
8
|
+
|
9
|
+
@world = "Earth"
|
10
|
+
body render(:inline => "Hello, <%= @world %>")
|
11
|
+
end
|
12
|
+
|
13
|
+
def file_template
|
14
|
+
recipients 'test@localhost'
|
15
|
+
subject "using helpers"
|
16
|
+
from "tester@example.com"
|
17
|
+
|
18
|
+
@recipient = 'test@localhost'
|
19
|
+
body render(:file => "templates/signed_up")
|
20
|
+
end
|
21
|
+
|
22
|
+
def rxml_template
|
23
|
+
recipients 'test@localhost'
|
24
|
+
subject "rendering rxml template"
|
25
|
+
from "tester@example.com"
|
26
|
+
end
|
27
|
+
|
28
|
+
def included_subtemplate
|
29
|
+
recipients 'test@localhost'
|
30
|
+
subject "Including another template in the one being rendered"
|
31
|
+
from "tester@example.com"
|
32
|
+
end
|
33
|
+
|
34
|
+
def no_instance_variable
|
35
|
+
recipients 'test@localhost'
|
36
|
+
subject "No Instance Variable"
|
37
|
+
from "tester@example.com"
|
38
|
+
|
39
|
+
silence_warnings do
|
40
|
+
body render(:inline => "Look, subject.nil? is <%= @subject.nil? %>!")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize_defaults(method_name)
|
45
|
+
super
|
46
|
+
self.class.mailer_name = "test_mailer"
|
47
|
+
end
|
48
|
+
|
49
|
+
def multipart_alternative
|
50
|
+
recipients 'test@localhost'
|
51
|
+
subject 'multipart/alternative'
|
52
|
+
from 'tester@example.com'
|
53
|
+
|
54
|
+
build_multipart_message(:foo => "bar")
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def build_multipart_message(assigns = {})
|
59
|
+
content_type "multipart/alternative"
|
60
|
+
|
61
|
+
part "text/plain" do |p|
|
62
|
+
p.body = build_body_part('plain', assigns, :layout => false)
|
63
|
+
end
|
64
|
+
|
65
|
+
part "text/html" do |p|
|
66
|
+
p.body = build_body_part('html', assigns)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def build_body_part(content_type, assigns, options = {})
|
71
|
+
ActiveSupport::Deprecation.silence do
|
72
|
+
render "#{template}.#{content_type}", :body => assigns
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class FirstMailer < ActionMailer::Base
|
78
|
+
def share
|
79
|
+
recipients 'test@localhost'
|
80
|
+
subject "using helpers"
|
81
|
+
from "tester@example.com"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class SecondMailer < ActionMailer::Base
|
86
|
+
def share
|
87
|
+
recipients 'test@localhost'
|
88
|
+
subject "using helpers"
|
89
|
+
from "tester@example.com"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# CHANGED: Those tests were changed because body returns an object now
|
94
|
+
# Instead of mail.body.strip, we should mail.body.to_s.strip
|
95
|
+
class RenderHelperTest < Test::Unit::TestCase
|
96
|
+
def setup
|
97
|
+
set_delivery_method :test
|
98
|
+
ActionMailer::Base.perform_deliveries = true
|
99
|
+
ActionMailer::Base.deliveries.clear
|
100
|
+
|
101
|
+
@recipient = 'test@localhost'
|
102
|
+
end
|
103
|
+
|
104
|
+
def teardown
|
105
|
+
restore_delivery_method
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_inline_template
|
109
|
+
mail = RenderMailer.inline_template
|
110
|
+
assert_equal "Hello, Earth", mail.body.to_s.strip
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_file_template
|
114
|
+
mail = RenderMailer.file_template
|
115
|
+
assert_equal "Hello there,\n\nMr. test@localhost", mail.body.to_s.strip
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_included_subtemplate
|
119
|
+
mail = RenderMailer.included_subtemplate.deliver
|
120
|
+
assert_equal "Hey Ho, let's go!", mail.body.to_s.strip
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_no_instance_variable
|
124
|
+
mail = RenderMailer.no_instance_variable.deliver
|
125
|
+
assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_legacy_multipart_alternative
|
129
|
+
mail = RenderMailer.multipart_alternative.deliver
|
130
|
+
assert_equal(2, mail.parts.size)
|
131
|
+
assert_equal("multipart/alternative", mail.mime_type)
|
132
|
+
assert_equal("text/plain", mail.parts[0].mime_type)
|
133
|
+
assert_equal("foo: bar", mail.parts[0].body.encoded)
|
134
|
+
assert_equal("text/html", mail.parts[1].mime_type)
|
135
|
+
assert_equal("<strong>foo</strong> bar", mail.parts[1].body.encoded)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class FirstSecondHelperTest < Test::Unit::TestCase
|
140
|
+
def setup
|
141
|
+
set_delivery_method :test
|
142
|
+
ActionMailer::Base.perform_deliveries = true
|
143
|
+
ActionMailer::Base.deliveries.clear
|
144
|
+
|
145
|
+
@recipient = 'test@localhost'
|
146
|
+
end
|
147
|
+
|
148
|
+
def teardown
|
149
|
+
restore_delivery_method
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_ordering
|
153
|
+
mail = FirstMailer.share
|
154
|
+
assert_equal "first mail", mail.body.to_s.strip
|
155
|
+
mail = SecondMailer.share
|
156
|
+
assert_equal "second mail", mail.body.to_s.strip
|
157
|
+
mail = FirstMailer.share
|
158
|
+
assert_equal "first mail", mail.body.to_s.strip
|
159
|
+
mail = SecondMailer.share
|
160
|
+
assert_equal "second mail", mail.body.to_s.strip
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,1214 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'abstract_unit'
|
3
|
+
|
4
|
+
class FunkyPathMailer < ActionMailer::Base
|
5
|
+
self.view_paths = "#{File.dirname(__FILE__)}/fixtures/path.with.dots"
|
6
|
+
|
7
|
+
def multipart_with_template_path_with_dots(recipient)
|
8
|
+
recipients recipient
|
9
|
+
subject "This path has dots"
|
10
|
+
from "Chad Fowler <chad@chadfowler.com>"
|
11
|
+
attachment :content_type => "text/plain",
|
12
|
+
:data => "dots dots dots..."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TestMailer < ActionMailer::Base
|
17
|
+
def signed_up(recipient)
|
18
|
+
recipients recipient
|
19
|
+
subject "[Signed up] Welcome #{recipient}"
|
20
|
+
from "system@loudthinking.com"
|
21
|
+
|
22
|
+
@recipient = recipient
|
23
|
+
end
|
24
|
+
|
25
|
+
def cancelled_account(recipient)
|
26
|
+
recipients recipient
|
27
|
+
subject "[Cancelled] Goodbye #{recipient}"
|
28
|
+
from "system@loudthinking.com"
|
29
|
+
sent_on Time.local(2004, 12, 12)
|
30
|
+
body "Goodbye, Mr. #{recipient}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def from_with_name
|
34
|
+
from "System <system@loudthinking.com>"
|
35
|
+
recipients "root@loudthinking.com"
|
36
|
+
body "Nothing to see here."
|
37
|
+
end
|
38
|
+
|
39
|
+
def from_without_name
|
40
|
+
from "system@loudthinking.com"
|
41
|
+
recipients "root@loudthinking.com"
|
42
|
+
body "Nothing to see here."
|
43
|
+
end
|
44
|
+
|
45
|
+
def cc_bcc(recipient)
|
46
|
+
recipients recipient
|
47
|
+
subject "testing bcc/cc"
|
48
|
+
from "system@loudthinking.com"
|
49
|
+
sent_on Time.local(2004, 12, 12)
|
50
|
+
cc "nobody@loudthinking.com"
|
51
|
+
bcc "root@loudthinking.com"
|
52
|
+
|
53
|
+
body "Nothing to see here."
|
54
|
+
end
|
55
|
+
|
56
|
+
def different_reply_to(recipient)
|
57
|
+
recipients recipient
|
58
|
+
subject "testing reply_to"
|
59
|
+
from "system@loudthinking.com"
|
60
|
+
sent_on Time.local(2008, 5, 23)
|
61
|
+
reply_to "atraver@gmail.com"
|
62
|
+
|
63
|
+
body "Nothing to see here."
|
64
|
+
end
|
65
|
+
|
66
|
+
def iso_charset(recipient)
|
67
|
+
recipients recipient
|
68
|
+
subject "testing isø charsets"
|
69
|
+
from "system@loudthinking.com"
|
70
|
+
sent_on Time.local(2004, 12, 12)
|
71
|
+
cc "nobody@loudthinking.com"
|
72
|
+
bcc "root@loudthinking.com"
|
73
|
+
charset "iso-8859-1"
|
74
|
+
|
75
|
+
body "Nothing to see here."
|
76
|
+
end
|
77
|
+
|
78
|
+
def unencoded_subject(recipient)
|
79
|
+
recipients recipient
|
80
|
+
subject "testing unencoded subject"
|
81
|
+
from "system@loudthinking.com"
|
82
|
+
sent_on Time.local(2004, 12, 12)
|
83
|
+
cc "nobody@loudthinking.com"
|
84
|
+
bcc "root@loudthinking.com"
|
85
|
+
|
86
|
+
body "Nothing to see here."
|
87
|
+
end
|
88
|
+
|
89
|
+
def extended_headers(recipient)
|
90
|
+
recipients recipient
|
91
|
+
subject "testing extended headers"
|
92
|
+
from "Grytøyr <stian1@example.net>"
|
93
|
+
sent_on Time.local(2004, 12, 12)
|
94
|
+
cc "Grytøyr <stian2@example.net>"
|
95
|
+
bcc "Grytøyr <stian3@example.net>"
|
96
|
+
charset "iso-8859-1"
|
97
|
+
|
98
|
+
body "Nothing to see here."
|
99
|
+
end
|
100
|
+
|
101
|
+
def utf8_body(recipient)
|
102
|
+
recipients recipient
|
103
|
+
subject "testing utf-8 body"
|
104
|
+
from "Foo áëô îü <extended@example.net>"
|
105
|
+
sent_on Time.local(2004, 12, 12)
|
106
|
+
cc "Foo áëô îü <extended@example.net>"
|
107
|
+
bcc "Foo áëô îü <extended@example.net>"
|
108
|
+
charset "UTF-8"
|
109
|
+
|
110
|
+
body "åœö blah"
|
111
|
+
end
|
112
|
+
|
113
|
+
def multipart_with_mime_version(recipient)
|
114
|
+
recipients recipient
|
115
|
+
subject "multipart with mime_version"
|
116
|
+
from "test@example.com"
|
117
|
+
sent_on Time.local(2004, 12, 12)
|
118
|
+
mime_version "1.1"
|
119
|
+
content_type "multipart/alternative"
|
120
|
+
|
121
|
+
part "text/plain" do |p|
|
122
|
+
p.body = render(:text => "blah")
|
123
|
+
end
|
124
|
+
|
125
|
+
part "text/html" do |p|
|
126
|
+
p.body = render(:inline => "<%= content_tag(:b, 'blah') %>")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def multipart_with_utf8_subject(recipient)
|
131
|
+
recipients recipient
|
132
|
+
subject "Foo áëô îü"
|
133
|
+
from "test@example.com"
|
134
|
+
charset "UTF-8"
|
135
|
+
|
136
|
+
part "text/plain" do |p|
|
137
|
+
p.body = "blah"
|
138
|
+
end
|
139
|
+
|
140
|
+
part "text/html" do |p|
|
141
|
+
p.body = "<b>blah</b>"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def explicitly_multipart_example(recipient, ct=nil)
|
146
|
+
recipients recipient
|
147
|
+
subject "multipart example"
|
148
|
+
from "test@example.com"
|
149
|
+
sent_on Time.local(2004, 12, 12)
|
150
|
+
content_type ct if ct
|
151
|
+
|
152
|
+
part "text/html" do |p|
|
153
|
+
p.charset = "iso-8859-1"
|
154
|
+
p.body = "blah"
|
155
|
+
end
|
156
|
+
|
157
|
+
attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "foo.jpg"),
|
158
|
+
:data => "123456789"
|
159
|
+
|
160
|
+
body "plain text default"
|
161
|
+
end
|
162
|
+
|
163
|
+
def implicitly_multipart_example(recipient, cs = nil, order = nil)
|
164
|
+
recipients recipient
|
165
|
+
subject "multipart example"
|
166
|
+
from "test@example.com"
|
167
|
+
sent_on Time.local(2004, 12, 12)
|
168
|
+
|
169
|
+
@charset = cs if cs
|
170
|
+
@recipient = recipient
|
171
|
+
@implicit_parts_order = order if order
|
172
|
+
end
|
173
|
+
|
174
|
+
def implicitly_multipart_with_utf8
|
175
|
+
recipients "no.one@nowhere.test"
|
176
|
+
subject "Foo áëô îü"
|
177
|
+
from "some.one@somewhere.test"
|
178
|
+
template "implicitly_multipart_example"
|
179
|
+
|
180
|
+
@recipient = "no.one@nowhere.test"
|
181
|
+
end
|
182
|
+
|
183
|
+
def html_mail(recipient)
|
184
|
+
recipients recipient
|
185
|
+
subject "html mail"
|
186
|
+
from "test@example.com"
|
187
|
+
content_type "text/html"
|
188
|
+
|
189
|
+
body "<em>Emphasize</em> <strong>this</strong>"
|
190
|
+
end
|
191
|
+
|
192
|
+
def html_mail_with_underscores(recipient)
|
193
|
+
subject "html mail with underscores"
|
194
|
+
body %{<a href="http://google.com" target="_blank">_Google</a>}
|
195
|
+
end
|
196
|
+
|
197
|
+
def custom_template(recipient)
|
198
|
+
recipients recipient
|
199
|
+
subject "[Signed up] Welcome #{recipient}"
|
200
|
+
from "system@loudthinking.com"
|
201
|
+
sent_on Time.local(2004, 12, 12)
|
202
|
+
template "signed_up"
|
203
|
+
|
204
|
+
@recipient = recipient
|
205
|
+
end
|
206
|
+
|
207
|
+
def custom_templating_extension(recipient)
|
208
|
+
recipients recipient
|
209
|
+
subject "[Signed up] Welcome #{recipient}"
|
210
|
+
from "system@loudthinking.com"
|
211
|
+
sent_on Time.local(2004, 12, 12)
|
212
|
+
|
213
|
+
@recipient = recipient
|
214
|
+
end
|
215
|
+
|
216
|
+
def various_newlines(recipient)
|
217
|
+
recipients recipient
|
218
|
+
subject "various newlines"
|
219
|
+
from "test@example.com"
|
220
|
+
|
221
|
+
body "line #1\nline #2\rline #3\r\nline #4\r\r" +
|
222
|
+
"line #5\n\nline#6\r\n\r\nline #7"
|
223
|
+
end
|
224
|
+
|
225
|
+
def various_newlines_multipart(recipient)
|
226
|
+
recipients recipient
|
227
|
+
subject "various newlines multipart"
|
228
|
+
from "test@example.com"
|
229
|
+
content_type "multipart/alternative"
|
230
|
+
|
231
|
+
part :content_type => "text/plain", :body => "line #1\nline #2\rline #3\r\nline #4\r\r"
|
232
|
+
part :content_type => "text/html", :body => "<p>line #1</p>\n<p>line #2</p>\r<p>line #3</p>\r\n<p>line #4</p>\r\r"
|
233
|
+
end
|
234
|
+
|
235
|
+
def nested_multipart(recipient)
|
236
|
+
recipients recipient
|
237
|
+
subject "nested multipart"
|
238
|
+
from "test@example.com"
|
239
|
+
content_type "multipart/mixed"
|
240
|
+
|
241
|
+
part :content_type => "multipart/alternative", :content_disposition => "inline", "foo" => "bar" do |p|
|
242
|
+
p.part :content_type => "text/plain", :body => "test text\nline #2"
|
243
|
+
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
|
244
|
+
end
|
245
|
+
|
246
|
+
attachment :content_type => "application/octet-stream", :filename => "test.txt", :data => "test abcdefghijklmnopqstuvwxyz"
|
247
|
+
end
|
248
|
+
|
249
|
+
def nested_multipart_with_body(recipient)
|
250
|
+
recipients recipient
|
251
|
+
subject "nested multipart with body"
|
252
|
+
from "test@example.com"
|
253
|
+
content_type "multipart/mixed"
|
254
|
+
|
255
|
+
part :content_type => "multipart/alternative", :content_disposition => "inline", :body => "Nothing to see here." do |p|
|
256
|
+
p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def attachment_with_custom_header(recipient)
|
261
|
+
recipients recipient
|
262
|
+
subject "custom header in attachment"
|
263
|
+
from "test@example.com"
|
264
|
+
content_type "multipart/related"
|
265
|
+
part :content_type => "text/html", :body => 'yo'
|
266
|
+
attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "test.jpg"), :data => "i am not a real picture", 'Content-ID' => '<test@test.com>'
|
267
|
+
end
|
268
|
+
|
269
|
+
def unnamed_attachment(recipient)
|
270
|
+
recipients recipient
|
271
|
+
subject "nested multipart"
|
272
|
+
from "test@example.com"
|
273
|
+
content_type "multipart/mixed"
|
274
|
+
part :content_type => "text/plain", :body => "hullo"
|
275
|
+
attachment :content_type => "application/octet-stream", :data => "test abcdefghijklmnopqstuvwxyz"
|
276
|
+
end
|
277
|
+
|
278
|
+
def headers_with_nonalpha_chars(recipient)
|
279
|
+
recipients recipient
|
280
|
+
subject "nonalpha chars"
|
281
|
+
from "One: Two <test@example.com>"
|
282
|
+
cc "Three: Four <test@example.com>"
|
283
|
+
bcc "Five: Six <test@example.com>"
|
284
|
+
body "testing"
|
285
|
+
end
|
286
|
+
|
287
|
+
def custom_content_type_attributes
|
288
|
+
recipients "no.one@nowhere.test"
|
289
|
+
subject "custom content types"
|
290
|
+
from "some.one@somewhere.test"
|
291
|
+
content_type "text/plain; format=flowed"
|
292
|
+
body "testing"
|
293
|
+
end
|
294
|
+
|
295
|
+
def return_path
|
296
|
+
recipients "no.one@nowhere.test"
|
297
|
+
subject "return path test"
|
298
|
+
from "some.one@somewhere.test"
|
299
|
+
headers["return-path"] = "another@somewhere.test"
|
300
|
+
body "testing"
|
301
|
+
end
|
302
|
+
|
303
|
+
def subject_with_i18n(recipient)
|
304
|
+
recipients recipient
|
305
|
+
from "system@loudthinking.com"
|
306
|
+
body "testing"
|
307
|
+
end
|
308
|
+
|
309
|
+
class << self
|
310
|
+
attr_accessor :received_body
|
311
|
+
end
|
312
|
+
|
313
|
+
def receive(mail)
|
314
|
+
self.class.received_body = mail.body
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
class ActionMailerTest < Test::Unit::TestCase
|
319
|
+
|
320
|
+
def encode( text, charset="UTF-8" )
|
321
|
+
Mail::Encodings.q_value_encode( text, charset )
|
322
|
+
end
|
323
|
+
|
324
|
+
def new_mail( charset="UTF-8" )
|
325
|
+
mail = Mail.new
|
326
|
+
mail.charset = charset
|
327
|
+
mail.mime_version = "1.0"
|
328
|
+
mail
|
329
|
+
end
|
330
|
+
|
331
|
+
# Replacing logger work around for mocha bug. Should be fixed in mocha 0.3.3
|
332
|
+
def setup
|
333
|
+
set_delivery_method :test
|
334
|
+
ActionMailer::Base.perform_deliveries = true
|
335
|
+
ActionMailer::Base.raise_delivery_errors = true
|
336
|
+
ActionMailer::Base.deliveries.clear
|
337
|
+
|
338
|
+
@original_logger = TestMailer.logger
|
339
|
+
@recipient = 'test@localhost'
|
340
|
+
|
341
|
+
TestMailer.delivery_method = :test
|
342
|
+
end
|
343
|
+
|
344
|
+
def teardown
|
345
|
+
TestMailer.logger = @original_logger
|
346
|
+
restore_delivery_method
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_nested_parts
|
350
|
+
created = nil
|
351
|
+
assert_nothing_raised { created = TestMailer.nested_multipart(@recipient)}
|
352
|
+
assert_equal 2, created.parts.size
|
353
|
+
assert_equal 2, created.parts.first.parts.size
|
354
|
+
|
355
|
+
assert_equal "multipart/mixed", created.mime_type
|
356
|
+
assert_equal "multipart/alternative", created.parts[0].mime_type
|
357
|
+
assert_equal "bar", created.parts[0].header['foo'].to_s
|
358
|
+
assert_not_nil created.parts[0].charset
|
359
|
+
assert_equal "text/plain", created.parts[0].parts[0].mime_type
|
360
|
+
assert_equal "text/html", created.parts[0].parts[1].mime_type
|
361
|
+
assert_equal "application/octet-stream", created.parts[1].mime_type
|
362
|
+
|
363
|
+
end
|
364
|
+
|
365
|
+
def test_nested_parts_with_body
|
366
|
+
created = nil
|
367
|
+
TestMailer.nested_multipart_with_body(@recipient)
|
368
|
+
assert_nothing_raised { created = TestMailer.nested_multipart_with_body(@recipient)}
|
369
|
+
|
370
|
+
assert_equal 1,created.parts.size
|
371
|
+
assert_equal 2,created.parts.first.parts.size
|
372
|
+
|
373
|
+
assert_equal "multipart/mixed", created.mime_type
|
374
|
+
assert_equal "multipart/alternative", created.parts.first.mime_type
|
375
|
+
assert_equal "text/plain", created.parts.first.parts.first.mime_type
|
376
|
+
assert_equal "Nothing to see here.", created.parts.first.parts.first.body.to_s
|
377
|
+
assert_equal "text/html", created.parts.first.parts.second.mime_type
|
378
|
+
assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.to_s
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_attachment_with_custom_header
|
382
|
+
created = nil
|
383
|
+
assert_nothing_raised { created = TestMailer.attachment_with_custom_header(@recipient) }
|
384
|
+
assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
|
385
|
+
end
|
386
|
+
|
387
|
+
def test_signed_up
|
388
|
+
TestMailer.delivery_method = :test
|
389
|
+
|
390
|
+
Time.stubs(:now => Time.now)
|
391
|
+
|
392
|
+
expected = new_mail
|
393
|
+
expected.to = @recipient
|
394
|
+
expected.subject = "[Signed up] Welcome #{@recipient}"
|
395
|
+
expected.body = "Hello there,\n\nMr. #{@recipient}"
|
396
|
+
expected.from = "system@loudthinking.com"
|
397
|
+
expected.date = Time.now
|
398
|
+
|
399
|
+
created = nil
|
400
|
+
assert_nothing_raised { created = TestMailer.signed_up(@recipient) }
|
401
|
+
assert_not_nil created
|
402
|
+
|
403
|
+
expected.message_id = '<123@456>'
|
404
|
+
created.message_id = '<123@456>'
|
405
|
+
|
406
|
+
assert_equal expected.encoded, created.encoded
|
407
|
+
|
408
|
+
assert_nothing_raised { TestMailer.signed_up(@recipient).deliver }
|
409
|
+
|
410
|
+
delivered = ActionMailer::Base.deliveries.first
|
411
|
+
assert_not_nil delivered
|
412
|
+
|
413
|
+
expected.message_id = '<123@456>'
|
414
|
+
delivered.message_id = '<123@456>'
|
415
|
+
|
416
|
+
assert_equal expected.encoded, delivered.encoded
|
417
|
+
end
|
418
|
+
|
419
|
+
def test_custom_template
|
420
|
+
expected = new_mail
|
421
|
+
expected.to = @recipient
|
422
|
+
expected.subject = "[Signed up] Welcome #{@recipient}"
|
423
|
+
expected.body = "Hello there,\n\nMr. #{@recipient}"
|
424
|
+
expected.from = "system@loudthinking.com"
|
425
|
+
expected.date = Time.local(2004, 12, 12)
|
426
|
+
|
427
|
+
created = nil
|
428
|
+
assert_nothing_raised { created = TestMailer.custom_template(@recipient) }
|
429
|
+
assert_not_nil created
|
430
|
+
expected.message_id = '<123@456>'
|
431
|
+
created.message_id = '<123@456>'
|
432
|
+
assert_equal expected.encoded, created.encoded
|
433
|
+
end
|
434
|
+
|
435
|
+
def test_custom_templating_extension
|
436
|
+
assert ActionView::Template.template_handler_extensions.include?("haml"), "haml extension was not registered"
|
437
|
+
|
438
|
+
# N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory
|
439
|
+
expected = new_mail
|
440
|
+
expected.to = @recipient
|
441
|
+
expected.subject = "[Signed up] Welcome #{@recipient}"
|
442
|
+
expected.body = "Hello there, \n\nMr. #{@recipient}"
|
443
|
+
expected.from = "system@loudthinking.com"
|
444
|
+
expected.date = Time.local(2004, 12, 12)
|
445
|
+
|
446
|
+
# Now that the template is registered, there should be one part. The text/plain part.
|
447
|
+
created = nil
|
448
|
+
assert_nothing_raised { created = TestMailer.custom_templating_extension(@recipient) }
|
449
|
+
assert_not_nil created
|
450
|
+
assert_equal 2, created.parts.length
|
451
|
+
assert_equal 'text/plain', created.parts[0].mime_type
|
452
|
+
assert_equal 'text/html', created.parts[1].mime_type
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_cancelled_account
|
456
|
+
expected = new_mail
|
457
|
+
expected.to = @recipient
|
458
|
+
expected.subject = "[Cancelled] Goodbye #{@recipient}"
|
459
|
+
expected.body = "Goodbye, Mr. #{@recipient}"
|
460
|
+
expected.from = "system@loudthinking.com"
|
461
|
+
expected.date = Time.local(2004, 12, 12)
|
462
|
+
|
463
|
+
created = nil
|
464
|
+
assert_nothing_raised { created = TestMailer.cancelled_account(@recipient) }
|
465
|
+
assert_not_nil created
|
466
|
+
expected.message_id = '<123@456>'
|
467
|
+
created.message_id = '<123@456>'
|
468
|
+
assert_equal expected.encoded, created.encoded
|
469
|
+
|
470
|
+
assert_nothing_raised { TestMailer.cancelled_account(@recipient).deliver }
|
471
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
472
|
+
delivered = ActionMailer::Base.deliveries.first
|
473
|
+
expected.message_id = '<123@456>'
|
474
|
+
delivered.message_id = '<123@456>'
|
475
|
+
|
476
|
+
assert_equal expected.encoded, delivered.encoded
|
477
|
+
end
|
478
|
+
|
479
|
+
def test_cc_bcc
|
480
|
+
expected = new_mail
|
481
|
+
expected.to = @recipient
|
482
|
+
expected.subject = "testing bcc/cc"
|
483
|
+
expected.body = "Nothing to see here."
|
484
|
+
expected.from = "system@loudthinking.com"
|
485
|
+
expected.cc = "nobody@loudthinking.com"
|
486
|
+
expected.bcc = "root@loudthinking.com"
|
487
|
+
expected.date = Time.local 2004, 12, 12
|
488
|
+
|
489
|
+
created = nil
|
490
|
+
assert_nothing_raised do
|
491
|
+
created = TestMailer.cc_bcc @recipient
|
492
|
+
end
|
493
|
+
assert_not_nil created
|
494
|
+
expected.message_id = '<123@456>'
|
495
|
+
created.message_id = '<123@456>'
|
496
|
+
assert_equal expected.encoded, created.encoded
|
497
|
+
|
498
|
+
assert_nothing_raised do
|
499
|
+
TestMailer.cc_bcc(@recipient).deliver
|
500
|
+
end
|
501
|
+
|
502
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
503
|
+
delivered = ActionMailer::Base.deliveries.first
|
504
|
+
expected.message_id = '<123@456>'
|
505
|
+
delivered.message_id = '<123@456>'
|
506
|
+
|
507
|
+
assert_equal expected.encoded, delivered.encoded
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_from_without_name_for_smtp
|
511
|
+
TestMailer.delivery_method = :smtp
|
512
|
+
TestMailer.from_without_name.deliver
|
513
|
+
|
514
|
+
mail = MockSMTP.deliveries.first
|
515
|
+
assert_not_nil mail
|
516
|
+
mail, from, to = mail
|
517
|
+
|
518
|
+
assert_equal 'system@loudthinking.com', from.to_s
|
519
|
+
end
|
520
|
+
|
521
|
+
def test_from_with_name_for_smtp
|
522
|
+
TestMailer.delivery_method = :smtp
|
523
|
+
TestMailer.from_with_name.deliver
|
524
|
+
|
525
|
+
mail = MockSMTP.deliveries.first
|
526
|
+
assert_not_nil mail
|
527
|
+
mail, from, to = mail
|
528
|
+
|
529
|
+
assert_equal 'system@loudthinking.com', from
|
530
|
+
end
|
531
|
+
|
532
|
+
def test_reply_to
|
533
|
+
TestMailer.delivery_method = :test
|
534
|
+
|
535
|
+
expected = new_mail
|
536
|
+
|
537
|
+
expected.to = @recipient
|
538
|
+
expected.subject = "testing reply_to"
|
539
|
+
expected.body = "Nothing to see here."
|
540
|
+
expected.from = "system@loudthinking.com"
|
541
|
+
expected.reply_to = "atraver@gmail.com"
|
542
|
+
expected.date = Time.local 2008, 5, 23
|
543
|
+
|
544
|
+
created = nil
|
545
|
+
assert_nothing_raised do
|
546
|
+
created = TestMailer.different_reply_to @recipient
|
547
|
+
end
|
548
|
+
assert_not_nil created
|
549
|
+
|
550
|
+
expected.message_id = '<123@456>'
|
551
|
+
created.message_id = '<123@456>'
|
552
|
+
|
553
|
+
assert_equal expected.encoded, created.encoded
|
554
|
+
|
555
|
+
assert_nothing_raised do
|
556
|
+
TestMailer.different_reply_to(@recipient).deliver
|
557
|
+
end
|
558
|
+
|
559
|
+
delivered = ActionMailer::Base.deliveries.first
|
560
|
+
assert_not_nil delivered
|
561
|
+
|
562
|
+
expected.message_id = '<123@456>'
|
563
|
+
delivered.message_id = '<123@456>'
|
564
|
+
|
565
|
+
assert_equal expected.encoded, delivered.encoded
|
566
|
+
end
|
567
|
+
|
568
|
+
def test_iso_charset
|
569
|
+
TestMailer.delivery_method = :test
|
570
|
+
expected = new_mail( "iso-8859-1" )
|
571
|
+
expected.to = @recipient
|
572
|
+
expected.subject = encode "testing isø charsets", "iso-8859-1"
|
573
|
+
expected.body = "Nothing to see here."
|
574
|
+
expected.from = "system@loudthinking.com"
|
575
|
+
expected.cc = "nobody@loudthinking.com"
|
576
|
+
expected.bcc = "root@loudthinking.com"
|
577
|
+
expected.date = Time.local 2004, 12, 12
|
578
|
+
|
579
|
+
created = nil
|
580
|
+
assert_nothing_raised do
|
581
|
+
created = TestMailer.iso_charset @recipient
|
582
|
+
end
|
583
|
+
assert_not_nil created
|
584
|
+
|
585
|
+
expected.message_id = '<123@456>'
|
586
|
+
created.message_id = '<123@456>'
|
587
|
+
|
588
|
+
assert_equal expected.encoded, created.encoded
|
589
|
+
|
590
|
+
assert_nothing_raised do
|
591
|
+
TestMailer.iso_charset(@recipient).deliver
|
592
|
+
end
|
593
|
+
|
594
|
+
delivered = ActionMailer::Base.deliveries.first
|
595
|
+
assert_not_nil delivered
|
596
|
+
|
597
|
+
expected.message_id = '<123@456>'
|
598
|
+
delivered.message_id = '<123@456>'
|
599
|
+
|
600
|
+
assert_equal expected.encoded, delivered.encoded
|
601
|
+
end
|
602
|
+
|
603
|
+
def test_unencoded_subject
|
604
|
+
TestMailer.delivery_method = :test
|
605
|
+
expected = new_mail
|
606
|
+
expected.to = @recipient
|
607
|
+
expected.subject = "testing unencoded subject"
|
608
|
+
expected.body = "Nothing to see here."
|
609
|
+
expected.from = "system@loudthinking.com"
|
610
|
+
expected.cc = "nobody@loudthinking.com"
|
611
|
+
expected.bcc = "root@loudthinking.com"
|
612
|
+
expected.date = Time.local 2004, 12, 12
|
613
|
+
|
614
|
+
created = nil
|
615
|
+
assert_nothing_raised do
|
616
|
+
created = TestMailer.unencoded_subject @recipient
|
617
|
+
end
|
618
|
+
assert_not_nil created
|
619
|
+
|
620
|
+
expected.message_id = '<123@456>'
|
621
|
+
created.message_id = '<123@456>'
|
622
|
+
|
623
|
+
assert_equal expected.encoded, created.encoded
|
624
|
+
|
625
|
+
assert_nothing_raised do
|
626
|
+
TestMailer.unencoded_subject(@recipient).deliver
|
627
|
+
end
|
628
|
+
|
629
|
+
delivered = ActionMailer::Base.deliveries.first
|
630
|
+
assert_not_nil delivered
|
631
|
+
|
632
|
+
expected.message_id = '<123@456>'
|
633
|
+
delivered.message_id = '<123@456>'
|
634
|
+
|
635
|
+
assert_equal expected.encoded, delivered.encoded
|
636
|
+
end
|
637
|
+
|
638
|
+
def test_deliveries_array
|
639
|
+
assert_not_nil ActionMailer::Base.deliveries
|
640
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
641
|
+
TestMailer.signed_up(@recipient).deliver
|
642
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
643
|
+
assert_not_nil ActionMailer::Base.deliveries.first
|
644
|
+
end
|
645
|
+
|
646
|
+
def test_perform_deliveries_flag
|
647
|
+
ActionMailer::Base.perform_deliveries = false
|
648
|
+
TestMailer.signed_up(@recipient).deliver
|
649
|
+
assert_equal 0, ActionMailer::Base.deliveries.size
|
650
|
+
ActionMailer::Base.perform_deliveries = true
|
651
|
+
TestMailer.signed_up(@recipient).deliver
|
652
|
+
assert_equal 1, ActionMailer::Base.deliveries.size
|
653
|
+
end
|
654
|
+
|
655
|
+
def test_doesnt_raise_errors_when_raise_delivery_errors_is_false
|
656
|
+
ActionMailer::Base.raise_delivery_errors = false
|
657
|
+
Mail::TestMailer.any_instance.expects(:deliver!).raises(Exception)
|
658
|
+
assert_nothing_raised { TestMailer.signed_up(@recipient).deliver }
|
659
|
+
end
|
660
|
+
|
661
|
+
# def test_performs_delivery_via_sendmail
|
662
|
+
# IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t -f "system@loudthinking.com" test@localhost', 'w+')
|
663
|
+
# TestMailer.delivery_method = :sendmail
|
664
|
+
# TestMailer.signed_up(@recipient).deliver
|
665
|
+
# end
|
666
|
+
|
667
|
+
def test_unquote_quoted_printable_subject
|
668
|
+
msg = <<EOF
|
669
|
+
From: me@example.com
|
670
|
+
Subject: =?UTF-8?Q?testing_testing_=D6=A4?=
|
671
|
+
Content-Type: text/plain; charset=iso-8859-1
|
672
|
+
|
673
|
+
The body
|
674
|
+
EOF
|
675
|
+
mail = Mail.new(msg)
|
676
|
+
assert_equal "testing testing \326\244", mail.subject
|
677
|
+
assert_equal "Subject: =?UTF-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded
|
678
|
+
end
|
679
|
+
|
680
|
+
def test_unquote_7bit_subject
|
681
|
+
msg = <<EOF
|
682
|
+
From: me@example.com
|
683
|
+
Subject: this == working?
|
684
|
+
Content-Type: text/plain; charset=iso-8859-1
|
685
|
+
|
686
|
+
The body
|
687
|
+
EOF
|
688
|
+
mail = Mail.new(msg)
|
689
|
+
assert_equal "this == working?", mail.subject
|
690
|
+
assert_equal "Subject: this == working?\r\n", mail[:subject].encoded
|
691
|
+
end
|
692
|
+
|
693
|
+
def test_unquote_7bit_body
|
694
|
+
msg = <<EOF
|
695
|
+
From: me@example.com
|
696
|
+
Subject: subject
|
697
|
+
Content-Type: text/plain; charset=iso-8859-1
|
698
|
+
Content-Transfer-Encoding: 7bit
|
699
|
+
|
700
|
+
The=3Dbody
|
701
|
+
EOF
|
702
|
+
mail = Mail.new(msg)
|
703
|
+
assert_equal "The=3Dbody", mail.body.to_s.strip
|
704
|
+
assert_equal "The=3Dbody", mail.body.encoded.strip
|
705
|
+
end
|
706
|
+
|
707
|
+
def test_unquote_quoted_printable_body
|
708
|
+
msg = <<EOF
|
709
|
+
From: me@example.com
|
710
|
+
Subject: subject
|
711
|
+
Content-Type: text/plain; charset=iso-8859-1
|
712
|
+
Content-Transfer-Encoding: quoted-printable
|
713
|
+
|
714
|
+
The=3Dbody
|
715
|
+
EOF
|
716
|
+
mail = Mail.new(msg)
|
717
|
+
assert_equal "The=body", mail.body.to_s.strip
|
718
|
+
if ActionMailer::VERSION::MINOR > 1
|
719
|
+
assert_equal "The=3Dbody", mail.body.encoded.strip
|
720
|
+
else
|
721
|
+
assert_equal "The=3Dbody=", mail.body.encoded.strip
|
722
|
+
end
|
723
|
+
end
|
724
|
+
|
725
|
+
def test_unquote_base64_body
|
726
|
+
msg = <<EOF
|
727
|
+
From: me@example.com
|
728
|
+
Subject: subject
|
729
|
+
Content-Type: text/plain; charset=iso-8859-1
|
730
|
+
Content-Transfer-Encoding: base64
|
731
|
+
|
732
|
+
VGhlIGJvZHk=
|
733
|
+
EOF
|
734
|
+
mail = Mail.new(msg)
|
735
|
+
assert_equal "The body", mail.body.to_s.strip
|
736
|
+
assert_equal "VGhlIGJvZHk=", mail.body.encoded.strip
|
737
|
+
end
|
738
|
+
|
739
|
+
def test_extended_headers
|
740
|
+
@recipient = "Grytøyr <test@localhost>"
|
741
|
+
|
742
|
+
expected = new_mail "iso-8859-1"
|
743
|
+
expected.to = @recipient
|
744
|
+
expected.subject = "testing extended headers"
|
745
|
+
expected.body = "Nothing to see here."
|
746
|
+
expected.from = "Grytøyr <stian1@example.net>"
|
747
|
+
expected.cc = "Grytøyr <stian2@example.net>"
|
748
|
+
expected.bcc = "Grytøyr <stian3@example.net>"
|
749
|
+
expected.date = Time.local 2004, 12, 12
|
750
|
+
|
751
|
+
created = nil
|
752
|
+
assert_nothing_raised do
|
753
|
+
created = TestMailer.extended_headers @recipient
|
754
|
+
end
|
755
|
+
|
756
|
+
assert_not_nil created
|
757
|
+
expected.message_id = '<123@456>'
|
758
|
+
created.message_id = '<123@456>'
|
759
|
+
|
760
|
+
assert_equal expected.encoded, created.encoded
|
761
|
+
|
762
|
+
assert_nothing_raised do
|
763
|
+
TestMailer.extended_headers(@recipient).deliver
|
764
|
+
end
|
765
|
+
|
766
|
+
delivered = ActionMailer::Base.deliveries.first
|
767
|
+
assert_not_nil delivered
|
768
|
+
|
769
|
+
expected.message_id = '<123@456>'
|
770
|
+
delivered.message_id = '<123@456>'
|
771
|
+
|
772
|
+
assert_equal expected.encoded, delivered.encoded
|
773
|
+
end
|
774
|
+
|
775
|
+
def test_utf8_body_is_not_quoted
|
776
|
+
@recipient = "Foo áëô îü <extended@example.net>"
|
777
|
+
expected = new_mail "UTF-8"
|
778
|
+
expected.to = @recipient
|
779
|
+
expected.subject = "testing UTF-8 body"
|
780
|
+
expected.body = "åœö blah"
|
781
|
+
expected.from = @recipient
|
782
|
+
expected.cc = @recipient
|
783
|
+
expected.bcc = @recipient
|
784
|
+
expected.date = Time.local 2004, 12, 12
|
785
|
+
|
786
|
+
created = TestMailer.utf8_body @recipient
|
787
|
+
assert_match(/åœö blah/, created.decoded)
|
788
|
+
end
|
789
|
+
|
790
|
+
def test_multiple_utf8_recipients
|
791
|
+
@recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"]
|
792
|
+
expected = new_mail "UTF-8"
|
793
|
+
expected.to = @recipient
|
794
|
+
expected.subject = "testing UTF-8 body"
|
795
|
+
expected.body = "åœö blah"
|
796
|
+
expected.from = @recipient.first
|
797
|
+
expected.cc = @recipient
|
798
|
+
expected.bcc = @recipient
|
799
|
+
expected.date = Time.local 2004, 12, 12
|
800
|
+
|
801
|
+
created = TestMailer.utf8_body @recipient
|
802
|
+
from_regexp = Regexp.escape('From: Foo =?UTF-8?B?w6HDq8O0?= =?UTF-8?B?IMOuw7w=?=')
|
803
|
+
assert_match(/#{from_regexp}/m, created.encoded)
|
804
|
+
|
805
|
+
to_regexp = Regexp.escape("To: =?UTF-8?B?Rm9vIMOhw6vDtCDDrsO8?= <extended@example.net>")
|
806
|
+
assert_match(/#{to_regexp}/m, created.encoded)
|
807
|
+
end
|
808
|
+
|
809
|
+
def test_receive_decodes_base64_encoded_mail
|
810
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email")
|
811
|
+
TestMailer.receive(fixture)
|
812
|
+
assert_match(/Jamis/, TestMailer.received_body.to_s)
|
813
|
+
end
|
814
|
+
|
815
|
+
def test_receive_attachments
|
816
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email2")
|
817
|
+
mail = Mail.new(fixture)
|
818
|
+
attachment = mail.attachments.last
|
819
|
+
assert_equal "smime.p7s", attachment.filename
|
820
|
+
assert_equal "application/pkcs7-signature", mail.parts.last.mime_type
|
821
|
+
end
|
822
|
+
|
823
|
+
def test_decode_attachment_without_charset
|
824
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email3")
|
825
|
+
mail = Mail.new(fixture)
|
826
|
+
attachment = mail.attachments.last
|
827
|
+
assert_equal 1026, attachment.read.length
|
828
|
+
end
|
829
|
+
|
830
|
+
def test_attachment_using_content_location
|
831
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email12")
|
832
|
+
mail = Mail.new(fixture)
|
833
|
+
assert_equal 1, mail.attachments.length
|
834
|
+
assert_equal "Photo25.jpg", mail.attachments.first.filename
|
835
|
+
end
|
836
|
+
|
837
|
+
def test_attachment_with_text_type
|
838
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email13")
|
839
|
+
mail = Mail.new(fixture)
|
840
|
+
assert mail.has_attachments?
|
841
|
+
assert_equal 1, mail.attachments.length
|
842
|
+
assert_equal "hello.rb", mail.attachments.first.filename
|
843
|
+
end
|
844
|
+
|
845
|
+
def test_decode_part_without_content_type
|
846
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email4")
|
847
|
+
mail = Mail.new(fixture)
|
848
|
+
assert_nothing_raised { mail.body }
|
849
|
+
end
|
850
|
+
|
851
|
+
def test_decode_message_without_content_type
|
852
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email5")
|
853
|
+
mail = Mail.new(fixture)
|
854
|
+
assert_nothing_raised { mail.body }
|
855
|
+
end
|
856
|
+
|
857
|
+
def test_decode_message_with_incorrect_charset
|
858
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email6")
|
859
|
+
mail = Mail.new(fixture)
|
860
|
+
assert_nothing_raised { mail.body }
|
861
|
+
end
|
862
|
+
|
863
|
+
def test_multipart_with_mime_version
|
864
|
+
mail = TestMailer.multipart_with_mime_version(@recipient)
|
865
|
+
assert_equal "1.1", mail.mime_version
|
866
|
+
end
|
867
|
+
|
868
|
+
def test_multipart_with_utf8_subject
|
869
|
+
mail = TestMailer.multipart_with_utf8_subject(@recipient)
|
870
|
+
regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC?=')
|
871
|
+
assert_match(/#{regex}/, mail.encoded)
|
872
|
+
string = "Foo áëô îü"
|
873
|
+
assert_match(string, mail.subject)
|
874
|
+
end
|
875
|
+
|
876
|
+
def test_implicitly_multipart_with_utf8
|
877
|
+
mail = TestMailer.implicitly_multipart_with_utf8
|
878
|
+
regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC?=')
|
879
|
+
assert_match(/#{regex}/, mail.encoded)
|
880
|
+
string = "Foo áëô îü"
|
881
|
+
assert_match(string, mail.subject)
|
882
|
+
end
|
883
|
+
|
884
|
+
def test_explicitly_multipart_messages
|
885
|
+
mail = TestMailer.explicitly_multipart_example(@recipient)
|
886
|
+
assert_equal 3, mail.parts.length
|
887
|
+
assert_equal 'multipart/mixed', mail.mime_type
|
888
|
+
assert_equal "text/plain", mail.parts[0].mime_type
|
889
|
+
|
890
|
+
assert_equal "text/html", mail.parts[1].mime_type
|
891
|
+
assert_equal "iso-8859-1", mail.parts[1].charset
|
892
|
+
|
893
|
+
assert_equal "image/jpeg", mail.parts[2].mime_type
|
894
|
+
|
895
|
+
assert_equal "attachment", mail.parts[2][:content_disposition].disposition_type
|
896
|
+
assert_equal "foo.jpg", mail.parts[2][:content_disposition].filename
|
897
|
+
assert_equal "foo.jpg", mail.parts[2][:content_type].filename
|
898
|
+
assert_nil mail.parts[2].charset
|
899
|
+
end
|
900
|
+
|
901
|
+
def test_explicitly_multipart_with_content_type
|
902
|
+
mail = TestMailer.explicitly_multipart_example(@recipient, "multipart/alternative")
|
903
|
+
assert_equal 3, mail.parts.length
|
904
|
+
assert_equal "multipart/alternative", mail.mime_type
|
905
|
+
end
|
906
|
+
|
907
|
+
def test_explicitly_multipart_with_invalid_content_type
|
908
|
+
mail = TestMailer.explicitly_multipart_example(@recipient, "text/xml")
|
909
|
+
assert_equal 3, mail.parts.length
|
910
|
+
assert_equal 'multipart/mixed', mail.mime_type
|
911
|
+
end
|
912
|
+
|
913
|
+
def test_implicitly_multipart_messages
|
914
|
+
assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"
|
915
|
+
|
916
|
+
mail = TestMailer.implicitly_multipart_example(@recipient)
|
917
|
+
assert_equal 3, mail.parts.length
|
918
|
+
assert_equal "1.0", mail.mime_version.to_s
|
919
|
+
assert_equal "multipart/alternative", mail.mime_type
|
920
|
+
assert_equal "text/plain", mail.parts[0].mime_type
|
921
|
+
assert_equal "UTF-8", mail.parts[0].charset
|
922
|
+
assert_equal "text/html", mail.parts[1].mime_type
|
923
|
+
assert_equal "UTF-8", mail.parts[1].charset
|
924
|
+
assert_equal "application/x-yaml", mail.parts[2].mime_type
|
925
|
+
assert_equal "UTF-8", mail.parts[2].charset
|
926
|
+
end
|
927
|
+
|
928
|
+
def test_implicitly_multipart_messages_with_custom_order
|
929
|
+
assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"
|
930
|
+
|
931
|
+
mail = TestMailer.implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
|
932
|
+
assert_equal 3, mail.parts.length
|
933
|
+
assert_equal "application/x-yaml", mail.parts[0].mime_type
|
934
|
+
assert_equal "text/plain", mail.parts[1].mime_type
|
935
|
+
assert_equal "text/html", mail.parts[2].mime_type
|
936
|
+
end
|
937
|
+
|
938
|
+
def test_implicitly_multipart_messages_with_charset
|
939
|
+
mail = TestMailer.implicitly_multipart_example(@recipient, 'iso-8859-1')
|
940
|
+
|
941
|
+
assert_equal "multipart/alternative", mail.header['content-type'].content_type
|
942
|
+
|
943
|
+
assert_equal 'iso-8859-1', mail.parts[0].content_type_parameters[:charset]
|
944
|
+
assert_equal 'iso-8859-1', mail.parts[1].content_type_parameters[:charset]
|
945
|
+
assert_equal 'iso-8859-1', mail.parts[2].content_type_parameters[:charset]
|
946
|
+
end
|
947
|
+
|
948
|
+
def test_html_mail
|
949
|
+
mail = TestMailer.html_mail(@recipient)
|
950
|
+
assert_equal "text/html", mail.mime_type
|
951
|
+
end
|
952
|
+
|
953
|
+
def test_html_mail_with_underscores
|
954
|
+
mail = TestMailer.html_mail_with_underscores(@recipient)
|
955
|
+
assert_equal %{<a href="http://google.com" target="_blank">_Google</a>}, mail.body.to_s
|
956
|
+
end
|
957
|
+
|
958
|
+
def test_various_newlines
|
959
|
+
mail = TestMailer.various_newlines(@recipient)
|
960
|
+
assert_equal("line #1\nline #2\nline #3\nline #4\n\n" +
|
961
|
+
"line #5\n\nline#6\n\nline #7", mail.body.to_s)
|
962
|
+
end
|
963
|
+
|
964
|
+
def test_various_newlines_multipart
|
965
|
+
mail = TestMailer.various_newlines_multipart(@recipient)
|
966
|
+
assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body.to_s
|
967
|
+
assert_equal "<p>line #1</p>\n<p>line #2</p>\n<p>line #3</p>\n<p>line #4</p>\n\n", mail.parts[1].body.to_s
|
968
|
+
assert_equal "line #1\r\nline #2\r\nline #3\r\nline #4\r\n\r\n", mail.parts[0].body.encoded
|
969
|
+
assert_equal "<p>line #1</p>\r\n<p>line #2</p>\r\n<p>line #3</p>\r\n<p>line #4</p>\r\n\r\n", mail.parts[1].body.encoded
|
970
|
+
end
|
971
|
+
|
972
|
+
def test_headers_removed_on_smtp_delivery
|
973
|
+
TestMailer.delivery_method = :smtp
|
974
|
+
TestMailer.cc_bcc(@recipient).deliver
|
975
|
+
assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com")
|
976
|
+
assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com")
|
977
|
+
assert MockSMTP.deliveries[0][2].include?(@recipient)
|
978
|
+
assert_match %r{^Cc: nobody@loudthinking.com}, MockSMTP.deliveries[0][0]
|
979
|
+
assert_match %r{^To: #{@recipient}}, MockSMTP.deliveries[0][0]
|
980
|
+
assert_no_match %r{^Bcc: root@loudthinking.com}, MockSMTP.deliveries[0][0]
|
981
|
+
end
|
982
|
+
|
983
|
+
def test_file_delivery_should_create_a_file
|
984
|
+
TestMailer.delivery_method = :file
|
985
|
+
tmp_location = TestMailer.file_settings[:location]
|
986
|
+
|
987
|
+
result = TestMailer.cc_bcc(@recipient).deliver
|
988
|
+
assert File.exists?(tmp_location)
|
989
|
+
assert File.directory?(tmp_location)
|
990
|
+
assert File.exists?(File.join(tmp_location, @recipient))
|
991
|
+
assert File.exists?(File.join(tmp_location, 'nobody@loudthinking.com'))
|
992
|
+
assert File.exists?(File.join(tmp_location, 'root@loudthinking.com'))
|
993
|
+
end
|
994
|
+
|
995
|
+
def test_recursive_multipart_processing
|
996
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
|
997
|
+
mail = Mail.new(fixture)
|
998
|
+
assert_equal(2, mail.parts.length)
|
999
|
+
assert_equal(4, mail.parts.first.parts.length)
|
1000
|
+
if ActionMailer::VERSION::MINOR > 1
|
1001
|
+
assert_equal("This is the first part.\n", mail.parts.first.parts.first.body.to_s)
|
1002
|
+
else
|
1003
|
+
assert_equal("This is the first part.", mail.parts.first.parts.first.body.to_s)
|
1004
|
+
end
|
1005
|
+
assert_equal("test.rb", mail.parts.first.parts.second.filename)
|
1006
|
+
assert_equal("flowed", mail.parts.first.parts.fourth.content_type_parameters[:format])
|
1007
|
+
assert_equal('smime.p7s', mail.parts.second.filename)
|
1008
|
+
end
|
1009
|
+
|
1010
|
+
def test_decode_encoded_attachment_filename
|
1011
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email8")
|
1012
|
+
mail = Mail.new(fixture)
|
1013
|
+
attachment = mail.attachments.last
|
1014
|
+
|
1015
|
+
expected = "01 Quien Te Dij\212at. Pitbull.mp3"
|
1016
|
+
|
1017
|
+
if expected.respond_to?(:force_encoding)
|
1018
|
+
result = attachment.filename.dup
|
1019
|
+
expected.force_encoding(Encoding::ASCII_8BIT)
|
1020
|
+
result.force_encoding(Encoding::ASCII_8BIT)
|
1021
|
+
assert_equal expected, result
|
1022
|
+
else
|
1023
|
+
assert_equal expected, attachment.filename
|
1024
|
+
end
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
def test_decode_message_with_unknown_charset
|
1028
|
+
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email10")
|
1029
|
+
mail = Mail.new(fixture)
|
1030
|
+
assert_nothing_raised { mail.body }
|
1031
|
+
end
|
1032
|
+
|
1033
|
+
def test_empty_header_values_omitted
|
1034
|
+
result = TestMailer.unnamed_attachment(@recipient).encoded
|
1035
|
+
assert_match %r{Content-Type: application/octet-stream}, result
|
1036
|
+
assert_match %r{Content-Disposition: attachment}, result
|
1037
|
+
end
|
1038
|
+
|
1039
|
+
def test_headers_with_nonalpha_chars
|
1040
|
+
mail = TestMailer.headers_with_nonalpha_chars(@recipient)
|
1041
|
+
assert !mail.from_addrs.empty?
|
1042
|
+
assert !mail.cc_addrs.empty?
|
1043
|
+
assert !mail.bcc_addrs.empty?
|
1044
|
+
assert_match(/:/, mail[:from].decoded)
|
1045
|
+
assert_match(/:/, mail[:cc].decoded)
|
1046
|
+
assert_match(/:/, mail[:bcc].decoded)
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
def test_with_mail_object_deliver
|
1050
|
+
TestMailer.delivery_method = :test
|
1051
|
+
mail = TestMailer.headers_with_nonalpha_chars(@recipient)
|
1052
|
+
assert_nothing_raised { mail.deliver }
|
1053
|
+
assert_equal 1, TestMailer.deliveries.length
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
def test_multipart_with_template_path_with_dots
|
1057
|
+
mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient)
|
1058
|
+
assert_equal 2, mail.parts.length
|
1059
|
+
assert_equal "text/plain", mail.parts[0].mime_type
|
1060
|
+
assert_equal "text/html", mail.parts[1].mime_type
|
1061
|
+
assert_equal "UTF-8", mail.parts[1].charset
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
def test_custom_content_type_attributes
|
1065
|
+
mail = TestMailer.custom_content_type_attributes
|
1066
|
+
assert_match %r{format=flowed}, mail.content_type
|
1067
|
+
assert_match %r{charset=UTF-8}, mail.content_type
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
def test_return_path_with_create
|
1071
|
+
mail = TestMailer.return_path
|
1072
|
+
assert_equal "another@somewhere.test", mail.return_path
|
1073
|
+
end
|
1074
|
+
|
1075
|
+
def test_return_path_with_deliver
|
1076
|
+
TestMailer.delivery_method = :smtp
|
1077
|
+
TestMailer.return_path.deliver
|
1078
|
+
assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
|
1079
|
+
assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s
|
1080
|
+
end
|
1081
|
+
|
1082
|
+
def test_starttls_is_enabled_if_supported
|
1083
|
+
TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
|
1084
|
+
MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true)
|
1085
|
+
MockSMTP.any_instance.expects(:enable_starttls_auto)
|
1086
|
+
TestMailer.delivery_method = :smtp
|
1087
|
+
TestMailer.signed_up(@recipient).deliver
|
1088
|
+
end
|
1089
|
+
|
1090
|
+
def test_starttls_is_disabled_if_not_supported
|
1091
|
+
TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
|
1092
|
+
MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false)
|
1093
|
+
MockSMTP.any_instance.expects(:enable_starttls_auto).never
|
1094
|
+
TestMailer.delivery_method = :smtp
|
1095
|
+
TestMailer.signed_up(@recipient).deliver
|
1096
|
+
end
|
1097
|
+
|
1098
|
+
def test_starttls_is_not_enabled
|
1099
|
+
TestMailer.smtp_settings.merge!(:enable_starttls_auto => false)
|
1100
|
+
MockSMTP.any_instance.expects(:respond_to?).never
|
1101
|
+
TestMailer.delivery_method = :smtp
|
1102
|
+
TestMailer.signed_up(@recipient).deliver
|
1103
|
+
ensure
|
1104
|
+
TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
|
1105
|
+
end
|
1106
|
+
end
|
1107
|
+
|
1108
|
+
class InheritableTemplateRootTest < ActiveSupport::TestCase
|
1109
|
+
def test_attr
|
1110
|
+
expected = File.expand_path("#{File.dirname(__FILE__)}/fixtures/path.with.dots")
|
1111
|
+
assert_equal expected, FunkyPathMailer.template_root.to_s
|
1112
|
+
|
1113
|
+
sub = Class.new(FunkyPathMailer)
|
1114
|
+
assert_deprecated do
|
1115
|
+
sub.template_root = 'test/path'
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
assert_equal File.expand_path('test/path'), sub.template_root.to_s
|
1119
|
+
assert_equal expected, FunkyPathMailer.template_root.to_s
|
1120
|
+
end
|
1121
|
+
end
|
1122
|
+
|
1123
|
+
# class MethodNamingTest < ActiveSupport::TestCase
|
1124
|
+
# include ActionMailer::TestHelper
|
1125
|
+
|
1126
|
+
# class TestMailer < ActionMailer::Base
|
1127
|
+
# def send
|
1128
|
+
# body 'foo'
|
1129
|
+
# end
|
1130
|
+
# end
|
1131
|
+
|
1132
|
+
# def setup
|
1133
|
+
# set_delivery_method :test
|
1134
|
+
# ActionMailer::Base.perform_deliveries = true
|
1135
|
+
# ActionMailer::Base.deliveries.clear
|
1136
|
+
# end
|
1137
|
+
|
1138
|
+
# def teardown
|
1139
|
+
# restore_delivery_method
|
1140
|
+
# end
|
1141
|
+
|
1142
|
+
# def test_send_method
|
1143
|
+
# assert_nothing_raised do
|
1144
|
+
# assert_emails 1 do
|
1145
|
+
# assert_deprecated do
|
1146
|
+
# TestMailer.deliver_send
|
1147
|
+
# end
|
1148
|
+
# end
|
1149
|
+
# end
|
1150
|
+
# end
|
1151
|
+
# end
|
1152
|
+
class RespondToTest < Test::Unit::TestCase
|
1153
|
+
class RespondToMailer < ActionMailer::Base; end
|
1154
|
+
|
1155
|
+
def setup
|
1156
|
+
set_delivery_method :test
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
def teardown
|
1160
|
+
restore_delivery_method
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
def test_should_respond_to_new
|
1164
|
+
assert_respond_to RespondToMailer, :new
|
1165
|
+
end
|
1166
|
+
|
1167
|
+
def test_should_respond_to_create_with_template_suffix
|
1168
|
+
assert_respond_to RespondToMailer, :create_any_old_template
|
1169
|
+
end
|
1170
|
+
|
1171
|
+
def test_should_respond_to_deliver_with_template_suffix
|
1172
|
+
assert_respond_to RespondToMailer, :deliver_any_old_template
|
1173
|
+
end
|
1174
|
+
|
1175
|
+
def test_should_not_respond_to_new_with_template_suffix
|
1176
|
+
assert !RespondToMailer.respond_to?(:new_any_old_template)
|
1177
|
+
end
|
1178
|
+
|
1179
|
+
def test_should_not_respond_to_create_with_template_suffix_unless_it_is_separated_by_an_underscore
|
1180
|
+
assert !RespondToMailer.respond_to?(:createany_old_template)
|
1181
|
+
end
|
1182
|
+
|
1183
|
+
def test_should_not_respond_to_deliver_with_template_suffix_unless_it_is_separated_by_an_underscore
|
1184
|
+
assert !RespondToMailer.respond_to?(:deliverany_old_template)
|
1185
|
+
end
|
1186
|
+
|
1187
|
+
def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_uppercase_letter
|
1188
|
+
assert !RespondToMailer.respond_to?(:create_Any_old_template)
|
1189
|
+
end
|
1190
|
+
|
1191
|
+
def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_uppercase_letter
|
1192
|
+
assert !RespondToMailer.respond_to?(:deliver_Any_old_template)
|
1193
|
+
end
|
1194
|
+
|
1195
|
+
def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_digit
|
1196
|
+
assert !RespondToMailer.respond_to?(:create_1_template)
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_digit
|
1200
|
+
assert !RespondToMailer.respond_to?(:deliver_1_template)
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
def test_should_not_respond_to_method_where_deliver_is_not_a_suffix
|
1204
|
+
assert !RespondToMailer.respond_to?(:foo_deliver_template)
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
|
1208
|
+
error = assert_raise NoMethodError do
|
1209
|
+
RespondToMailer.not_a_method
|
1210
|
+
end
|
1211
|
+
|
1212
|
+
assert_match(/method.*not_a_method/, error.message)
|
1213
|
+
end
|
1214
|
+
end
|