actionmailer 2.1.2 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionmailer might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,11 +1,14 @@
1
- *2.1.2 (October 23rd, 2008)*
1
+ *2.2.1 [RC2] (November 14th, 2008)*
2
2
 
3
- * Included in Rails 2.1.2
3
+ * Turn on STARTTLS if it is available in Net::SMTP (added in Ruby 1.8.7) and the SMTP server supports it (This is required for Gmail's SMTP server) #1336 [Grant Hollingworth]
4
4
 
5
5
 
6
- *2.1.1 (September 4th, 2008)*
6
+ *2.2.0 [RC1] (October 24th, 2008)*
7
7
 
8
- * Included in Rails 2.1.1
8
+ * Add layout functionality to mailers [Pratik]
9
+
10
+ Mailer layouts behaves just like controller layouts, except layout names need to
11
+ have '_mailer' postfix for them to be automatically picked up.
9
12
 
10
13
 
11
14
  *2.1.0 (May 31st, 2008)*
data/README CHANGED
File without changes
data/Rakefile CHANGED
@@ -5,8 +5,6 @@ require 'rake/rdoctask'
5
5
  require 'rake/packagetask'
6
6
  require 'rake/gempackagetask'
7
7
  require 'rake/contrib/sshpublisher'
8
- require 'rake/contrib/rubyforgepublisher'
9
-
10
8
  require File.join(File.dirname(__FILE__), 'lib', 'action_mailer', 'version')
11
9
 
12
10
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
@@ -57,7 +55,7 @@ spec = Gem::Specification.new do |s|
57
55
  s.rubyforge_project = "actionmailer"
58
56
  s.homepage = "http://www.rubyonrails.org"
59
57
 
60
- s.add_dependency('actionpack', '= 2.1.2' + PKG_BUILD)
58
+ s.add_dependency('actionpack', '= 2.2.2' + PKG_BUILD)
61
59
 
62
60
  s.has_rdoc = true
63
61
  s.requirements << 'none'
@@ -78,8 +76,8 @@ end
78
76
 
79
77
  desc "Publish the API documentation"
80
78
  task :pgem => [:package] do
81
- Rake::SshFilePublisher.new("david@greed.loudthinking.com", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
82
- `ssh david@greed.loudthinking.com '/u/sites/gems/gemupdate.sh'`
79
+ Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
80
+ `ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
83
81
  end
84
82
 
85
83
  desc "Publish the API documentation"
@@ -21,13 +21,13 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- unless defined?(ActionController)
25
- begin
26
- $:.unshift "#{File.dirname(__FILE__)}/../../actionpack/lib"
24
+ begin
25
+ require 'action_controller'
26
+ rescue LoadError
27
+ actionpack_path = "#{File.dirname(__FILE__)}/../../actionpack/lib"
28
+ if File.directory?(actionpack_path)
29
+ $:.unshift actionpack_path
27
30
  require 'action_controller'
28
- rescue LoadError
29
- require 'rubygems'
30
- gem 'actionpack', '>= 1.12.5'
31
31
  end
32
32
  end
33
33
 
@@ -216,7 +216,7 @@ module ActionMailer #:nodoc:
216
216
  # * <tt>:domain</tt> - If you need to specify a HELO domain, you can do it here.
217
217
  # * <tt>:user_name</tt> - If your mail server requires authentication, set the username in this setting.
218
218
  # * <tt>:password</tt> - If your mail server requires authentication, set the password in this setting.
219
- # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
219
+ # * <tt>:authentication</tt> - If your mail server requires authentication, you need to specify the authentication type here.
220
220
  # This is a symbol and one of <tt>:plain</tt>, <tt>:login</tt>, <tt>:cram_md5</tt>.
221
221
  #
222
222
  # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
@@ -233,10 +233,10 @@ module ActionMailer #:nodoc:
233
233
  # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with <tt>delivery_method :test</tt>. Most useful
234
234
  # for unit and functional testing.
235
235
  #
236
- # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
236
+ # * <tt>default_charset</tt> - The default charset used for the body and to encode the subject. Defaults to UTF-8. You can also
237
237
  # pick a different charset from inside a method with +charset+.
238
238
  # * <tt>default_content_type</tt> - The default content type used for the main part of the message. Defaults to "text/plain". You
239
- # can also pick a different content type from inside a method with +content_type+.
239
+ # can also pick a different content type from inside a method with +content_type+.
240
240
  # * <tt>default_mime_version</tt> - The default mime version used for the message. Defaults to <tt>1.0</tt>. You
241
241
  # can also pick a different value from inside a method with +mime_version+.
242
242
  # * <tt>default_implicit_parts_order</tt> - When a message is built implicitly (i.e. multiple parts are assembled from templates
@@ -246,16 +246,16 @@ module ActionMailer #:nodoc:
246
246
  # +implicit_parts_order+.
247
247
  class Base
248
248
  include AdvAttrAccessor, PartContainer
249
- include ActionController::UrlWriter if Object.const_defined?(:ActionController)
249
+ if Object.const_defined?(:ActionController)
250
+ include ActionController::UrlWriter
251
+ include ActionController::Layout
252
+ end
250
253
 
251
254
  private_class_method :new #:nodoc:
252
255
 
253
- class_inheritable_accessor :template_root
256
+ class_inheritable_accessor :view_paths
254
257
  cattr_accessor :logger
255
258
 
256
- cattr_accessor :template_extensions
257
- @@template_extensions = ['erb', 'builder', 'rhtml', 'rxml']
258
-
259
259
  @@smtp_settings = {
260
260
  :address => "localhost",
261
261
  :port => 25,
@@ -296,6 +296,9 @@ module ActionMailer #:nodoc:
296
296
  @@default_implicit_parts_order = [ "text/html", "text/enriched", "text/plain" ]
297
297
  cattr_accessor :default_implicit_parts_order
298
298
 
299
+ cattr_reader :protected_instance_variables
300
+ @@protected_instance_variables = %w(@body)
301
+
299
302
  # Specify the BCC addresses for the message
300
303
  adv_attr_accessor :bcc
301
304
 
@@ -365,6 +368,7 @@ module ActionMailer #:nodoc:
365
368
 
366
369
  # The mail object instance referenced by this mailer.
367
370
  attr_reader :mail
371
+ attr_reader :template_name, :default_template_name, :action_name
368
372
 
369
373
  class << self
370
374
  attr_writer :mailer_name
@@ -377,12 +381,20 @@ module ActionMailer #:nodoc:
377
381
  alias_method :controller_name, :mailer_name
378
382
  alias_method :controller_path, :mailer_name
379
383
 
380
- def method_missing(method_symbol, *parameters)#:nodoc:
381
- case method_symbol.id2name
382
- when /^create_([_a-z]\w*)/ then new($1, *parameters).mail
383
- when /^deliver_([_a-z]\w*)/ then new($1, *parameters).deliver!
384
- when "new" then nil
385
- else super
384
+ def respond_to?(method_symbol, include_private = false) #:nodoc:
385
+ matches_dynamic_method?(method_symbol) || super
386
+ end
387
+
388
+ def method_missing(method_symbol, *parameters) #:nodoc:
389
+ if match = matches_dynamic_method?(method_symbol)
390
+ case match[1]
391
+ when 'create' then new(match[2], *parameters).mail
392
+ when 'deliver' then new(match[2], *parameters).deliver!
393
+ when 'new' then nil
394
+ else super
395
+ end
396
+ else
397
+ super
386
398
  end
387
399
  end
388
400
 
@@ -414,21 +426,25 @@ module ActionMailer #:nodoc:
414
426
  new.deliver!(mail)
415
427
  end
416
428
 
417
- # Register a template extension so mailer templates written in a
418
- # templating language other than rhtml or rxml are supported.
419
- # To use this, include in your template-language plugin's init
420
- # code or on a per-application basis, this can be invoked from
421
- # <tt>config/environment.rb</tt>:
422
- #
423
- # ActionMailer::Base.register_template_extension('haml')
424
429
  def register_template_extension(extension)
425
- template_extensions << extension
430
+ ActiveSupport::Deprecation.warn(
431
+ "ActionMailer::Base.register_template_extension has been deprecated." +
432
+ "Use ActionView::Base.register_template_extension instead", caller)
433
+ end
434
+
435
+ def template_root
436
+ self.view_paths && self.view_paths.first
426
437
  end
427
438
 
428
439
  def template_root=(root)
429
- write_inheritable_attribute(:template_root, root)
430
- ActionView::TemplateFinder.process_view_paths(root)
440
+ self.view_paths = ActionView::Base.process_view_paths(root)
431
441
  end
442
+
443
+ private
444
+ def matches_dynamic_method?(method_name) #:nodoc:
445
+ method_name = method_name.to_s
446
+ /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
447
+ end
432
448
  end
433
449
 
434
450
  # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
@@ -452,16 +468,18 @@ module ActionMailer #:nodoc:
452
468
  # "the_template_file.text.html.erb", etc.). Only do this if parts
453
469
  # have not already been specified manually.
454
470
  if @parts.empty?
455
- templates = Dir.glob("#{template_path}/#{@template}.*")
456
- templates.each do |path|
457
- basename = File.basename(path)
458
- template_regex = Regexp.new("^([^\\\.]+)\\\.([^\\\.]+\\\.[^\\\.]+)\\\.(" + template_extensions.join('|') + ")$")
459
- next unless md = template_regex.match(basename)
460
- template_name = basename
461
- content_type = md.captures[1].gsub('.', '/')
462
- @parts << Part.new(:content_type => content_type,
463
- :disposition => "inline", :charset => charset,
464
- :body => render_message(template_name, @body))
471
+ Dir.glob("#{template_path}/#{@template}.*").each do |path|
472
+ template = template_root["#{mailer_name}/#{File.basename(path)}"]
473
+
474
+ # Skip unless template has a multipart format
475
+ next unless template && template.multipart?
476
+
477
+ @parts << Part.new(
478
+ :content_type => template.content_type,
479
+ :disposition => "inline",
480
+ :charset => charset,
481
+ :body => render_message(template, @body)
482
+ )
465
483
  end
466
484
  unless @parts.empty?
467
485
  @content_type = "multipart/alternative"
@@ -474,7 +492,7 @@ module ActionMailer #:nodoc:
474
492
  # normal template exists (or if there were no implicit parts) we render
475
493
  # it.
476
494
  template_exists = @parts.empty?
477
- template_exists ||= Dir.glob("#{template_path}/#{@template}.*").any? { |i| File.basename(i).split(".").length == 2 }
495
+ template_exists ||= template_root["#{mailer_name}/#{@template}"]
478
496
  @body = render_message(@template, @body) if template_exists
479
497
 
480
498
  # Finally, if there are other message parts and a textual body exists,
@@ -522,6 +540,7 @@ module ActionMailer #:nodoc:
522
540
  @content_type ||= @@default_content_type.dup
523
541
  @implicit_parts_order ||= @@default_implicit_parts_order.dup
524
542
  @template ||= method_name
543
+ @default_template_name = @action_name = @template
525
544
  @mailer_name ||= self.class.name.underscore
526
545
  @parts ||= []
527
546
  @headers ||= {}
@@ -530,16 +549,38 @@ module ActionMailer #:nodoc:
530
549
  end
531
550
 
532
551
  def render_message(method_name, body)
533
- render :file => method_name, :body => body, :use_full_path => true
552
+ render :file => method_name, :body => body
534
553
  end
535
554
 
536
555
  def render(opts)
537
556
  body = opts.delete(:body)
538
- if opts[:file] && opts[:file] !~ /\//
557
+ if opts[:file] && (opts[:file] !~ /\// && !opts[:file].respond_to?(:render))
539
558
  opts[:file] = "#{mailer_name}/#{opts[:file]}"
540
559
  end
541
- opts[:use_full_path] = true
542
- initialize_template_class(body).render(opts)
560
+
561
+ begin
562
+ old_template, @template = @template, initialize_template_class(body)
563
+ layout = respond_to?(:pick_layout, true) ? pick_layout(opts) : false
564
+ @template.render(opts.merge(:layout => layout))
565
+ ensure
566
+ @template = old_template
567
+ end
568
+ end
569
+
570
+ def default_template_format
571
+ :html
572
+ end
573
+
574
+ def candidate_for_layout?(options)
575
+ !@template.send(:_exempt_from_layout?, default_template_name)
576
+ end
577
+
578
+ def template_root
579
+ self.class.template_root
580
+ end
581
+
582
+ def template_root=(root)
583
+ self.class.template_root = root
543
584
  end
544
585
 
545
586
  def template_path
@@ -547,7 +588,7 @@ module ActionMailer #:nodoc:
547
588
  end
548
589
 
549
590
  def initialize_template_class(assigns)
550
- ActionView::Base.new([template_root], assigns, self)
591
+ ActionView::Base.new(view_paths, assigns, self)
551
592
  end
552
593
 
553
594
  def sort_parts(parts, order = [])
@@ -625,8 +666,10 @@ module ActionMailer #:nodoc:
625
666
  mail.ready_to_send
626
667
  sender = mail['return-path'] || mail.from
627
668
 
628
- Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain],
629
- smtp_settings[:user_name], smtp_settings[:password], smtp_settings[:authentication]) do |smtp|
669
+ smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
670
+ smtp.enable_starttls_auto if smtp.respond_to?(:enable_starttls_auto)
671
+ smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password],
672
+ smtp_settings[:authentication]) do |smtp|
630
673
  smtp.sendmail(mail.encoded, sender, destinations)
631
674
  end
632
675
  end
@@ -72,7 +72,7 @@ module ActionMailer
72
72
  methods.flatten.each do |method|
73
73
  master_helper_module.module_eval <<-end_eval
74
74
  def #{method}(*args, &block)
75
- controller.send!(%(#{method}), *args, &block)
75
+ controller.__send__(%(#{method}), *args, &block)
76
76
  end
77
77
  end_eval
78
78
  end
@@ -92,7 +92,7 @@ module ActionMailer
92
92
  inherited_without_helper(child)
93
93
  begin
94
94
  child.master_helper_module = Module.new
95
- child.master_helper_module.send! :include, master_helper_module
95
+ child.master_helper_module.__send__(:include, master_helper_module)
96
96
  child.helper child.name.to_s.underscore
97
97
  rescue MissingSourceFile => e
98
98
  raise unless e.is_missing?("helpers/#{child.name.to_s.underscore}_helper")
@@ -38,7 +38,7 @@ module TMail
38
38
  # = Class Address
39
39
  #
40
40
  # Provides a complete handling library for email addresses. Can parse a string of an
41
- # address directly or take in preformatted addresses themseleves. Allows you to add
41
+ # address directly or take in preformatted addresses themselves. Allows you to add
42
42
  # and remove phrases from the front of the address and provides a compare function for
43
43
  # email addresses.
44
44
  #
@@ -143,7 +143,7 @@ module TMail
143
143
 
144
144
  # This is to catch an unquoted "@" symbol in the local part of the
145
145
  # address. Handles addresses like <"@"@me.com> and makes sure they
146
- # stay like <"@"@me.com> (previously were becomming <@@me.com>)
146
+ # stay like <"@"@me.com> (previously were becoming <@@me.com>)
147
147
  if local && (local.join == '@' || local.join =~ /\A[^"].*?@.*?[^"]\Z/)
148
148
  @local = "\"#{local.join}\""
149
149
  else
@@ -59,7 +59,7 @@ module TMail
59
59
  #
60
60
  # This is because a mailbox doesn't have the : after the From that designates the
61
61
  # beginning of the envelope sender (which can be different to the from address of
62
- # the emial)
62
+ # the email)
63
63
  #
64
64
  # Other fields can be passed as normal, "Reply-To", "Received" etc.
65
65
  #
@@ -42,7 +42,7 @@ module TMail
42
42
  # Allows you to query the mail object with a string to get the contents
43
43
  # of the field you want.
44
44
  #
45
- # Returns a string of the exact contnts of the field
45
+ # Returns a string of the exact contents of the field
46
46
  #
47
47
  # mail.from = "mikel <mikel@lindsaar.net>"
48
48
  # mail.header_string("From") #=> "mikel <mikel@lindsaar.net>"
@@ -255,7 +255,7 @@ module TMail
255
255
  alias fetch []
256
256
 
257
257
  # Allows you to set or delete TMail header objects at will.
258
- # Eamples:
258
+ # Examples:
259
259
  # @mail = TMail::Mail.new
260
260
  # @mail['to'].to_s # => 'mikel@test.com.au'
261
261
  # @mail['to'] = 'mikel@elsewhere.org'
@@ -265,7 +265,7 @@ module TMail
265
265
  # @mail['to'].to_s # => nil
266
266
  # @mail.encoded # => "\r\n"
267
267
  #
268
- # Note: setting mail[] = nil actualy deletes the header field in question from the object,
268
+ # Note: setting mail[] = nil actually deletes the header field in question from the object,
269
269
  # it does not just set the value of the hash to nil
270
270
  def []=( key, val )
271
271
  dkey = key.downcase
@@ -1,7 +1,7 @@
1
1
  module ActionMailer
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
- MINOR = 1
4
+ MINOR = 2
5
5
  TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -1,6 +1,8 @@
1
1
  require 'test/unit'
2
2
 
3
3
  $:.unshift "#{File.dirname(__FILE__)}/../lib"
4
+ $:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib"
5
+ $:.unshift "#{File.dirname(__FILE__)}/../../actionpack/lib"
4
6
  require 'action_mailer'
5
7
  require 'action_mailer/test_case'
6
8
 
@@ -22,11 +24,15 @@ class MockSMTP
22
24
  def sendmail(mail, from, to)
23
25
  @@deliveries << [mail, from, to]
24
26
  end
27
+
28
+ def start(*args)
29
+ yield self
30
+ end
25
31
  end
26
32
 
27
33
  class Net::SMTP
28
- def self.start(*args)
29
- yield MockSMTP.new
34
+ def self.new(*args)
35
+ MockSMTP.new
30
36
  end
31
37
  end
32
38
 
@@ -0,0 +1 @@
1
+ Hello from layout <%= yield %>
@@ -0,0 +1 @@
1
+ Spammer layout <%= yield %>
@@ -0,0 +1,2 @@
1
+ body: <%= @body %>
2
+ bar: <%= @bar %>
@@ -0,0 +1,10 @@
1
+ <html>
2
+ <body>
3
+ HTML formatted message to <strong><%= @recipient %></strong>.
4
+ </body>
5
+ </html>
6
+ <html>
7
+ <body>
8
+ HTML formatted message to <strong><%= @recipient %></strong>.
9
+ </body>
10
+ </html>
@@ -0,0 +1,78 @@
1
+ require 'abstract_unit'
2
+
3
+ class AutoLayoutMailer < ActionMailer::Base
4
+ def hello(recipient)
5
+ recipients recipient
6
+ subject "You have a mail"
7
+ from "tester@example.com"
8
+ end
9
+
10
+ def spam(recipient)
11
+ recipients recipient
12
+ subject "You have a mail"
13
+ from "tester@example.com"
14
+ body render(:inline => "Hello, <%= @world %>", :layout => 'spam', :body => { :world => "Earth" })
15
+ end
16
+
17
+ def nolayout(recipient)
18
+ recipients recipient
19
+ subject "You have a mail"
20
+ from "tester@example.com"
21
+ body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" })
22
+ end
23
+ end
24
+
25
+ class ExplicitLayoutMailer < ActionMailer::Base
26
+ layout 'spam', :except => [:logout]
27
+
28
+ def signup(recipient)
29
+ recipients recipient
30
+ subject "You have a mail"
31
+ from "tester@example.com"
32
+ end
33
+
34
+ def logout(recipient)
35
+ recipients recipient
36
+ subject "You have a mail"
37
+ from "tester@example.com"
38
+ end
39
+ end
40
+
41
+ class LayoutMailerTest < Test::Unit::TestCase
42
+ def setup
43
+ set_delivery_method :test
44
+ ActionMailer::Base.perform_deliveries = true
45
+ ActionMailer::Base.deliveries = []
46
+
47
+ @recipient = 'test@localhost'
48
+ end
49
+
50
+ def teardown
51
+ restore_delivery_method
52
+ end
53
+
54
+ def test_should_pickup_default_layout
55
+ mail = AutoLayoutMailer.create_hello(@recipient)
56
+ assert_equal "Hello from layout Inside", mail.body.strip
57
+ end
58
+
59
+ def test_should_pickup_layout_given_to_render
60
+ mail = AutoLayoutMailer.create_spam(@recipient)
61
+ assert_equal "Spammer layout Hello, Earth", mail.body.strip
62
+ end
63
+
64
+ def test_should_respect_layout_false
65
+ mail = AutoLayoutMailer.create_nolayout(@recipient)
66
+ assert_equal "Hello, Earth", mail.body.strip
67
+ end
68
+
69
+ def test_explicit_class_layout
70
+ mail = ExplicitLayoutMailer.create_signup(@recipient)
71
+ assert_equal "Spammer layout We do not spam", mail.body.strip
72
+ end
73
+
74
+ def test_explicit_layout_exceptions
75
+ mail = ExplicitLayoutMailer.create_logout(@recipient)
76
+ assert_equal "You logged out", mail.body.strip
77
+ end
78
+ end
@@ -20,13 +20,13 @@ class RenderMailer < ActionMailer::Base
20
20
  subject "rendering rxml template"
21
21
  from "tester@example.com"
22
22
  end
23
-
23
+
24
24
  def included_subtemplate(recipient)
25
25
  recipients recipient
26
26
  subject "Including another template in the one being rendered"
27
27
  from "tester@example.com"
28
28
  end
29
-
29
+
30
30
  def included_old_subtemplate(recipient)
31
31
  recipients recipient
32
32
  subject "Including another template in the one being rendered"
@@ -83,17 +83,11 @@ class RenderHelperTest < Test::Unit::TestCase
83
83
  mail = RenderMailer.deliver_rxml_template(@recipient)
84
84
  assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test/>", mail.body.strip
85
85
  end
86
-
86
+
87
87
  def test_included_subtemplate
88
88
  mail = RenderMailer.deliver_included_subtemplate(@recipient)
89
89
  assert_equal "Hey Ho, let's go!", mail.body.strip
90
90
  end
91
-
92
- def test_deprecated_old_subtemplate
93
- assert_raises ActionView::ActionViewError do
94
- RenderMailer.deliver_included_old_subtemplate(@recipient)
95
- end
96
- end
97
91
  end
98
92
 
99
93
  class FirstSecondHelperTest < Test::Unit::TestCase
@@ -219,7 +219,7 @@ class TestMailer < ActionMailer::Base
219
219
  end
220
220
  attachment :content_type => "application/octet-stream",:filename => "test.txt", :body => "test abcdefghijklmnopqstuvwxyz"
221
221
  end
222
-
222
+
223
223
  def nested_multipart_with_body(recipient)
224
224
  recipients recipient
225
225
  subject "nested multipart with body"
@@ -273,6 +273,13 @@ class TestMailer < ActionMailer::Base
273
273
  headers "return-path" => "another@somewhere.test"
274
274
  end
275
275
 
276
+ def body_ivar(recipient)
277
+ recipients recipient
278
+ subject "Body as a local variable"
279
+ from "test@example.com"
280
+ body :body => "foo", :bar => "baz"
281
+ end
282
+
276
283
  class <<self
277
284
  attr_accessor :received_body
278
285
  end
@@ -321,7 +328,7 @@ class ActionMailerTest < Test::Unit::TestCase
321
328
  assert_nothing_raised { created = TestMailer.create_nested_multipart(@recipient)}
322
329
  assert_equal 2,created.parts.size
323
330
  assert_equal 2,created.parts.first.parts.size
324
-
331
+
325
332
  assert_equal "multipart/mixed", created.content_type
326
333
  assert_equal "multipart/alternative", created.parts.first.content_type
327
334
  assert_equal "bar", created.parts.first.header['foo'].to_s
@@ -366,7 +373,7 @@ class ActionMailerTest < Test::Unit::TestCase
366
373
  assert_not_nil ActionMailer::Base.deliveries.first
367
374
  assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
368
375
  end
369
-
376
+
370
377
  def test_custom_template
371
378
  expected = new_mail
372
379
  expected.to = @recipient
@@ -382,7 +389,6 @@ class ActionMailerTest < Test::Unit::TestCase
382
389
  end
383
390
 
384
391
  def test_custom_templating_extension
385
- #
386
392
  # N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory
387
393
  expected = new_mail
388
394
  expected.to = @recipient
@@ -390,18 +396,10 @@ class ActionMailerTest < Test::Unit::TestCase
390
396
  expected.body = "Hello there, \n\nMr. #{@recipient}"
391
397
  expected.from = "system@loudthinking.com"
392
398
  expected.date = Time.local(2004, 12, 12)
393
-
399
+
394
400
  # Stub the render method so no alternative renderers need be present.
395
401
  ActionView::Base.any_instance.stubs(:render).returns("Hello there, \n\nMr. #{@recipient}")
396
-
397
- # If the template is not registered, there should be no parts.
398
- created = nil
399
- assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
400
- assert_not_nil created
401
- assert_equal 0, created.parts.length
402
-
403
- ActionMailer::Base.register_template_extension('haml')
404
-
402
+
405
403
  # Now that the template is registered, there should be one part. The text/plain part.
406
404
  created = nil
407
405
  assert_nothing_raised { created = TestMailer.create_custom_templating_extension(@recipient) }
@@ -428,7 +426,7 @@ class ActionMailerTest < Test::Unit::TestCase
428
426
  assert_not_nil ActionMailer::Base.deliveries.first
429
427
  assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
430
428
  end
431
-
429
+
432
430
  def test_cc_bcc
433
431
  expected = new_mail
434
432
  expected.to = @recipient
@@ -550,7 +548,7 @@ class ActionMailerTest < Test::Unit::TestCase
550
548
  TestMailer.deliver_signed_up(@recipient)
551
549
  assert_equal 1, ActionMailer::Base.deliveries.size
552
550
  end
553
-
551
+
554
552
  def test_doesnt_raise_errors_when_raise_delivery_errors_is_false
555
553
  ActionMailer::Base.raise_delivery_errors = false
556
554
  TestMailer.any_instance.expects(:perform_delivery_test).raises(Exception)
@@ -670,7 +668,7 @@ EOF
670
668
  assert_not_nil ActionMailer::Base.deliveries.first
671
669
  assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
672
670
  end
673
-
671
+
674
672
  def test_utf8_body_is_not_quoted
675
673
  @recipient = "Foo áëô îü <extended@example.net>"
676
674
  expected = new_mail "utf-8"
@@ -760,7 +758,7 @@ EOF
760
758
  mail = TestMailer.create_multipart_with_mime_version(@recipient)
761
759
  assert_equal "1.1", mail.mime_version
762
760
  end
763
-
761
+
764
762
  def test_multipart_with_utf8_subject
765
763
  mail = TestMailer.create_multipart_with_utf8_subject(@recipient)
766
764
  assert_match(/\nSubject: =\?utf-8\?Q\?Foo_.*?\?=/, mail.encoded)
@@ -825,7 +823,7 @@ EOF
825
823
  mail = TestMailer.create_implicitly_multipart_example(@recipient, 'iso-8859-1')
826
824
 
827
825
  assert_equal "multipart/alternative", mail.header['content-type'].body
828
-
826
+
829
827
  assert_equal 'iso-8859-1', mail.parts[0].sub_header("content-type", "charset")
830
828
  assert_equal 'iso-8859-1', mail.parts[1].sub_header("content-type", "charset")
831
829
  assert_equal 'iso-8859-1', mail.parts[2].sub_header("content-type", "charset")
@@ -852,7 +850,7 @@ EOF
852
850
  assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body
853
851
  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
854
852
  end
855
-
853
+
856
854
  def test_headers_removed_on_smtp_delivery
857
855
  ActionMailer::Base.delivery_method = :smtp
858
856
  TestMailer.deliver_cc_bcc(@recipient)
@@ -935,6 +933,25 @@ EOF
935
933
  TestMailer.deliver_return_path
936
934
  assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
937
935
  end
936
+
937
+ def test_body_is_stored_as_an_ivar
938
+ mail = TestMailer.create_body_ivar(@recipient)
939
+ assert_equal "body: foo\nbar: baz", mail.body
940
+ end
941
+
942
+ def test_starttls_is_enabled_if_supported
943
+ MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true)
944
+ MockSMTP.any_instance.expects(:enable_starttls_auto)
945
+ ActionMailer::Base.delivery_method = :smtp
946
+ TestMailer.deliver_signed_up(@recipient)
947
+ end
948
+
949
+ def test_starttls_is_disabled_if_not_supported
950
+ MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false)
951
+ MockSMTP.any_instance.expects(:enable_starttls_auto).never
952
+ ActionMailer::Base.delivery_method = :smtp
953
+ TestMailer.deliver_signed_up(@recipient)
954
+ end
938
955
  end
939
956
 
940
957
  end # uses_mocha
@@ -977,3 +994,67 @@ class MethodNamingTest < Test::Unit::TestCase
977
994
  end
978
995
  end
979
996
  end
997
+
998
+ class RespondToTest < Test::Unit::TestCase
999
+ class RespondToMailer < ActionMailer::Base; end
1000
+
1001
+ def setup
1002
+ set_delivery_method :test
1003
+ end
1004
+
1005
+ def teardown
1006
+ restore_delivery_method
1007
+ end
1008
+
1009
+ def test_should_respond_to_new
1010
+ assert RespondToMailer.respond_to?(:new)
1011
+ end
1012
+
1013
+ def test_should_respond_to_create_with_template_suffix
1014
+ assert RespondToMailer.respond_to?(:create_any_old_template)
1015
+ end
1016
+
1017
+ def test_should_respond_to_deliver_with_template_suffix
1018
+ assert RespondToMailer.respond_to?(:deliver_any_old_template)
1019
+ end
1020
+
1021
+ def test_should_not_respond_to_new_with_template_suffix
1022
+ assert !RespondToMailer.respond_to?(:new_any_old_template)
1023
+ end
1024
+
1025
+ def test_should_not_respond_to_create_with_template_suffix_unless_it_is_separated_by_an_underscore
1026
+ assert !RespondToMailer.respond_to?(:createany_old_template)
1027
+ end
1028
+
1029
+ def test_should_not_respond_to_deliver_with_template_suffix_unless_it_is_separated_by_an_underscore
1030
+ assert !RespondToMailer.respond_to?(:deliverany_old_template)
1031
+ end
1032
+
1033
+ def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_uppercase_letter
1034
+ assert !RespondToMailer.respond_to?(:create_Any_old_template)
1035
+ end
1036
+
1037
+ def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_uppercase_letter
1038
+ assert !RespondToMailer.respond_to?(:deliver_Any_old_template)
1039
+ end
1040
+
1041
+ def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_digit
1042
+ assert !RespondToMailer.respond_to?(:create_1_template)
1043
+ end
1044
+
1045
+ def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_digit
1046
+ assert !RespondToMailer.respond_to?(:deliver_1_template)
1047
+ end
1048
+
1049
+ def test_should_not_respond_to_method_where_deliver_is_not_a_suffix
1050
+ assert !RespondToMailer.respond_to?(:foo_deliver_template)
1051
+ end
1052
+
1053
+ def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
1054
+ error = assert_raises NoMethodError do
1055
+ RespondToMailer.not_a_method
1056
+ end
1057
+
1058
+ assert_match /undefined method.*not_a_method/, error.message
1059
+ end
1060
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -9,7 +9,7 @@ autorequire: action_mailer
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-23 00:00:00 +02:00
12
+ date: 2008-11-20 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.1.2
23
+ version: 2.2.2
24
24
  version:
25
25
  description: Makes it trivial to test and deliver emails sent from a single service layer.
26
26
  email: david@loudthinking.com
@@ -87,6 +87,11 @@ files:
87
87
  - test/abstract_unit.rb
88
88
  - test/delivery_method_test.rb
89
89
  - test/fixtures
90
+ - test/fixtures/auto_layout_mailer
91
+ - test/fixtures/auto_layout_mailer/hello.html.erb
92
+ - test/fixtures/explicit_layout_mailer
93
+ - test/fixtures/explicit_layout_mailer/logout.html.erb
94
+ - test/fixtures/explicit_layout_mailer/signup.html.erb
90
95
  - test/fixtures/first_mailer
91
96
  - test/fixtures/first_mailer/share.erb
92
97
  - test/fixtures/helper_mailer
@@ -96,6 +101,9 @@ files:
96
101
  - test/fixtures/helper_mailer/use_mail_helper.erb
97
102
  - test/fixtures/helpers
98
103
  - test/fixtures/helpers/example_helper.rb
104
+ - test/fixtures/layouts
105
+ - test/fixtures/layouts/auto_layout_mailer.html.erb
106
+ - test/fixtures/layouts/spam.html.erb
99
107
  - test/fixtures/path.with.dots
100
108
  - test/fixtures/path.with.dots/funky_path_mailer
101
109
  - test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb
@@ -121,19 +129,22 @@ files:
121
129
  - test/fixtures/templates/signed_up.erb
122
130
  - test/fixtures/test_mailer
123
131
  - test/fixtures/test_mailer/_subtemplate.text.plain.erb
132
+ - test/fixtures/test_mailer/body_ivar.erb
124
133
  - test/fixtures/test_mailer/custom_templating_extension.text.html.haml
125
134
  - test/fixtures/test_mailer/custom_templating_extension.text.plain.haml
126
135
  - test/fixtures/test_mailer/implicitly_multipart_example.ignored.erb
127
136
  - test/fixtures/test_mailer/implicitly_multipart_example.rhtml.bak
128
137
  - test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb
138
+ - test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb~
129
139
  - test/fixtures/test_mailer/implicitly_multipart_example.text.plain.erb
130
140
  - test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.erb
131
141
  - test/fixtures/test_mailer/included_subtemplate.text.plain.erb
132
142
  - test/fixtures/test_mailer/rxml_template.builder
133
143
  - test/fixtures/test_mailer/rxml_template.rxml
134
- - test/fixtures/test_mailer/signed_up.erb
144
+ - test/fixtures/test_mailer/signed_up.html.erb
135
145
  - test/fixtures/test_mailer/signed_up_with_url.erb
136
146
  - test/mail_helper_test.rb
147
+ - test/mail_layout_test.rb
137
148
  - test/mail_render_test.rb
138
149
  - test/mail_service_test.rb
139
150
  - test/quoting_test.rb
@@ -162,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
173
  requirements:
163
174
  - none
164
175
  rubyforge_project: actionmailer
165
- rubygems_version: 1.3.0
176
+ rubygems_version: 1.3.1
166
177
  signing_key:
167
178
  specification_version: 2
168
179
  summary: Service layer for easy email delivery and testing.