diff options
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/Rakefile | 6 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 58 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb | 1 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/vendor/tmail.rb | 1 | ||||
-rw-r--r-- | actionmailer/test/adv_attr_test.rb | 18 | ||||
-rw-r--r-- | actionmailer/test/fixtures/auto_layout_mailer/multipart.html.erb (renamed from actionmailer/test/fixtures/auto_layout_mailer/multipart.text.html.erb) | 0 | ||||
-rw-r--r-- | actionmailer/test/fixtures/auto_layout_mailer/multipart.text.erb (renamed from actionmailer/test/fixtures/auto_layout_mailer/multipart.text.plain.erb) | 0 | ||||
-rw-r--r-- | actionmailer/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb | 2 | ||||
-rw-r--r-- | actionmailer/test/fixtures/test_mailer/_subtemplate.text.erb (renamed from actionmailer/test/fixtures/test_mailer/_subtemplate.text.plain.erb) | 0 | ||||
-rw-r--r-- | actionmailer/test/fixtures/test_mailer/custom_templating_extension.html.haml (renamed from actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.html.haml) | 0 | ||||
-rw-r--r-- | actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.haml (renamed from actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.plain.haml) | 0 | ||||
-rw-r--r-- | actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.html.erb (renamed from actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb) | 0 | ||||
-rw-r--r-- | actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.html.erb~ (renamed from actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb~) | 0 | ||||
-rw-r--r-- | actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.erb (renamed from actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.erb) | 0 | ||||
-rw-r--r-- | actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.yaml.erb (renamed from actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.erb) | 0 | ||||
-rw-r--r-- | actionmailer/test/fixtures/test_mailer/included_subtemplate.text.erb (renamed from actionmailer/test/fixtures/test_mailer/included_subtemplate.text.plain.erb) | 0 | ||||
-rw-r--r-- | actionmailer/test/fixtures/test_mailer/rxml_template.builder | 2 | ||||
-rw-r--r-- | actionmailer/test/mail_service_test.rb | 25 |
18 files changed, 71 insertions, 42 deletions
diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index f06f18ff76..24c25abc8b 100644 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -28,6 +28,12 @@ Rake::TestTask.new { |t| t.warning = false } +task :isolated_test do + ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME')) + Dir.glob("test/*_test.rb").all? do |file| + system(ruby, '-Ilib:test', file) + end or raise "Failures" +end # Generate the RDoc documentation Rake::RDocTask.new { |rdoc| diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 9eee5783a0..af2cc2ee24 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -465,48 +465,48 @@ module ActionMailer #:nodoc: def create!(method_name, *parameters) #:nodoc: initialize_defaults(method_name) __send__(method_name, *parameters) - + # If an explicit, textual body has not been set, we check assumptions. unless String === @body # First, we look to see if there are any likely templates that match, # which include the content-type in their file name (i.e., # "the_template_file.text.html.erb", etc.). Only do this if parts # have not already been specified manually. - if @parts.empty? - Dir.glob("#{template_path}/#{@template}.*").each do |path| - template = template_root.find_by_parts("#{mailer_name}/#{File.basename(path)}") - - # Skip unless template has a multipart format - next unless template && template.multipart? - + # if @parts.empty? + template_root.find_all_by_parts(@template, {}, template_path).each do |template| @parts << Part.new( - :content_type => template.content_type, + :content_type => template.mime_type ? template.mime_type.to_s : "text/plain", :disposition => "inline", :charset => charset, :body => render_template(template, @body) ) end - unless @parts.empty? + + if @parts.size > 1 @content_type = "multipart/alternative" if @content_type !~ /^multipart/ @parts = sort_parts(@parts, @implicit_parts_order) end - end - + # end + # Then, if there were such templates, we check to see if we ought to # also render a "normal" template (without the content type). If a # normal template exists (or if there were no implicit parts) we render # it. - template_exists = @parts.empty? - template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}") - @body = render_message(@template, @body) if template_exists + # ==== + # TODO: Revisit this + # template_exists = @parts.empty? + # template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}") + # @body = render_message(@template, @body) if template_exists # Finally, if there are other message parts and a textual body exists, # we shift it onto the front of the parts and set the body to nil (so # that create_mail doesn't try to render it in addition to the parts). - if !@parts.empty? && String === @body - @parts.unshift Part.new(:charset => charset, :body => @body) - @body = nil - end + # ==== + # TODO: Revisit this + # if !@parts.empty? && String === @body + # @parts.unshift Part.new(:charset => charset, :body => @body) + # @body = nil + # end end # If this is a multipart e-mail add the mime_version if it is not @@ -555,12 +555,13 @@ module ActionMailer #:nodoc: end def render_template(template, body) - if template.respond_to?(:content_type) - @current_template_content_type = template.content_type + if template.respond_to?(:mime_type) + @current_template_content_type = template.mime_type && template.mime_type.to_sym.to_s end @template = initialize_template_class(body) - layout = _pick_layout(layout, true) unless template.exempt_from_layout? + layout = _pick_layout(layout, true) unless + ActionController::Base.exempt_from_layout.include?(template.handler) @template._render_template_with_layout(template, layout, {}) ensure @current_template_content_type = nil @@ -580,11 +581,11 @@ module ActionMailer #:nodoc: if file prefix = mailer_name unless file =~ /\// - template = view_paths.find_by_parts(file, formats, prefix) + template = view_paths.find_by_parts(file, {:formats => formats}, prefix) end layout = _pick_layout(layout, - !template || !template.exempt_from_layout?) + !template || ActionController::Base.exempt_from_layout.include?(template.handler)) if template @template._render_template_with_layout(template, layout, opts) @@ -611,7 +612,7 @@ module ActionMailer #:nodoc: end def template_path - "#{template_root}/#{mailer_name}" + "#{mailer_name}" end def initialize_template_class(assigns) @@ -622,7 +623,7 @@ module ActionMailer #:nodoc: def sort_parts(parts, order = []) order = order.collect { |s| s.downcase } - + parts = parts.sort do |a, b| a_ct = a.content_type.downcase b_ct = b.content_type.downcase @@ -663,10 +664,13 @@ module ActionMailer #:nodoc: headers.each { |k, v| m[k] = v } real_content_type, ctype_attrs = parse_content_type - + if @parts.empty? m.set_content_type(real_content_type, nil, ctype_attrs) m.body = normalize_new_lines(body) + elsif @parts.size == 1 && @parts.first.parts.empty? + m.set_content_type(real_content_type, nil, ctype_attrs) + m.body = normalize_new_lines(@parts.first.body) else if String === body part = TMail::Mail.new diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb index c3a8803dc4..23a3f75de3 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/mail.rb @@ -518,6 +518,7 @@ module TMail def parse_body( f = nil ) return if @body_parsed + if f parse_body_0 f else diff --git a/actionmailer/lib/action_mailer/vendor/tmail.rb b/actionmailer/lib/action_mailer/vendor/tmail.rb index 51d36cdd0d..60555605f6 100644 --- a/actionmailer/lib/action_mailer/vendor/tmail.rb +++ b/actionmailer/lib/action_mailer/vendor/tmail.rb @@ -12,6 +12,7 @@ end require 'tmail' +require 'active_support/core_ext/kernel/reporting' silence_warnings do TMail::Encoder.const_set("MAX_LINE_LEN", 200) end diff --git a/actionmailer/test/adv_attr_test.rb b/actionmailer/test/adv_attr_test.rb new file mode 100644 index 0000000000..fd909a5627 --- /dev/null +++ b/actionmailer/test/adv_attr_test.rb @@ -0,0 +1,18 @@ +require 'abstract_unit' +require 'action_mailer/adv_attr_accessor' + +class AdvAttrTest < Test::Unit::TestCase + class Person + include ActionMailer::AdvAttrAccessor + adv_attr_accessor :name + end + + def test_adv_attr + bob = Person.new + assert_nil bob.name + bob.name 'Bob' + assert_equal 'Bob', bob.name + + assert_raise(ArgumentError) {bob.name 'x', 'y'} + end +end diff --git a/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.html.erb b/actionmailer/test/fixtures/auto_layout_mailer/multipart.html.erb index 6d73f199c4..6d73f199c4 100644 --- a/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.html.erb +++ b/actionmailer/test/fixtures/auto_layout_mailer/multipart.html.erb diff --git a/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.plain.erb b/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.erb index f4b91e4031..f4b91e4031 100644 --- a/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.plain.erb +++ b/actionmailer/test/fixtures/auto_layout_mailer/multipart.text.erb diff --git a/actionmailer/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb b/actionmailer/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb index 897a5065cf..2d0cd5c124 100644 --- a/actionmailer/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb +++ b/actionmailer/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.erb @@ -1 +1 @@ -Have a lovely picture, from me. Enjoy!
\ No newline at end of file +Have some dots. Enjoy!
\ No newline at end of file diff --git a/actionmailer/test/fixtures/test_mailer/_subtemplate.text.plain.erb b/actionmailer/test/fixtures/test_mailer/_subtemplate.text.erb index 3b4ba35f20..3b4ba35f20 100644 --- a/actionmailer/test/fixtures/test_mailer/_subtemplate.text.plain.erb +++ b/actionmailer/test/fixtures/test_mailer/_subtemplate.text.erb diff --git a/actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.html.haml b/actionmailer/test/fixtures/test_mailer/custom_templating_extension.html.haml index 847d065c37..847d065c37 100644 --- a/actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.html.haml +++ b/actionmailer/test/fixtures/test_mailer/custom_templating_extension.html.haml diff --git a/actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.plain.haml b/actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.haml index 847d065c37..847d065c37 100644 --- a/actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.plain.haml +++ b/actionmailer/test/fixtures/test_mailer/custom_templating_extension.text.haml diff --git a/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.html.erb index 946d99ede5..946d99ede5 100644 --- a/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb +++ b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.html.erb diff --git a/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb~ b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.html.erb~ index 946d99ede5..946d99ede5 100644 --- a/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.html.erb~ +++ b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.html.erb~ diff --git a/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.erb b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.erb index a6c8d54cf9..a6c8d54cf9 100644 --- a/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.erb +++ b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.erb diff --git a/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.erb b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.yaml.erb index c14348c770..c14348c770 100644 --- a/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.erb +++ b/actionmailer/test/fixtures/test_mailer/implicitly_multipart_example.yaml.erb diff --git a/actionmailer/test/fixtures/test_mailer/included_subtemplate.text.plain.erb b/actionmailer/test/fixtures/test_mailer/included_subtemplate.text.erb index a93c30ea1a..a93c30ea1a 100644 --- a/actionmailer/test/fixtures/test_mailer/included_subtemplate.text.plain.erb +++ b/actionmailer/test/fixtures/test_mailer/included_subtemplate.text.erb diff --git a/actionmailer/test/fixtures/test_mailer/rxml_template.builder b/actionmailer/test/fixtures/test_mailer/rxml_template.builder deleted file mode 100644 index d566bd8d7c..0000000000 --- a/actionmailer/test/fixtures/test_mailer/rxml_template.builder +++ /dev/null @@ -1,2 +0,0 @@ -xml.instruct! -xml.test
\ No newline at end of file diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index b7d5fd5dd3..30d1b836c4 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -6,10 +6,10 @@ class FunkyPathMailer < ActionMailer::Base def multipart_with_template_path_with_dots(recipient) recipients recipient - subject "Have a lovely picture" + subject "This path has dots" from "Chad Fowler <chad@chadfowler.com>" - attachment :content_type => "image/jpeg", - :body => "not really a jpeg, we're only testing, after all" + attachment :content_type => "text/plain", + :body => "dots dots dots..." end end @@ -338,6 +338,7 @@ class ActionMailerTest < Test::Unit::TestCase def test_nested_parts_with_body created = nil + TestMailer.create_nested_multipart_with_body(@recipient) assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)} assert_equal 1,created.parts.size assert_equal 2,created.parts.first.parts.size @@ -351,8 +352,8 @@ class ActionMailerTest < Test::Unit::TestCase def test_attachment_with_custom_header created = nil - assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient)} - assert_equal "<test@test.com>", created.parts[1].header['content-id'].to_s + assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) } + assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" } end def test_signed_up @@ -824,7 +825,7 @@ EOF assert_equal 3, mail.parts.length assert_equal "1.0", mail.mime_version assert_equal "multipart/alternative", mail.content_type - assert_equal "text/yaml", mail.parts[0].content_type + assert_equal "application/x-yaml", mail.parts[0].content_type assert_equal "utf-8", mail.parts[0].sub_header("content-type", "charset") assert_equal "text/plain", mail.parts[1].content_type assert_equal "utf-8", mail.parts[1].sub_header("content-type", "charset") @@ -835,11 +836,11 @@ EOF def test_implicitly_multipart_messages_with_custom_order assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered" - mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["text/yaml", "text/plain"]) + mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"]) assert_equal 3, mail.parts.length assert_equal "text/html", mail.parts[0].content_type assert_equal "text/plain", mail.parts[1].content_type - assert_equal "text/yaml", mail.parts[2].content_type + assert_equal "application/x-yaml", mail.parts[2].content_type end def test_implicitly_multipart_messages_with_charset @@ -938,8 +939,8 @@ EOF def test_multipart_with_template_path_with_dots mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient) assert_equal 2, mail.parts.length - assert_equal 'text/plain', mail.parts[0].content_type - assert_equal 'utf-8', mail.parts[0].charset + assert "text/plain", mail.parts[1].content_type + assert "utf-8", mail.parts[1].charset end def test_custom_content_type_attributes @@ -994,13 +995,13 @@ end class InheritableTemplateRootTest < Test::Unit::TestCase def test_attr - expected = "#{File.dirname(__FILE__)}/fixtures/path.with.dots" + expected = File.expand_path("#{File.dirname(__FILE__)}/fixtures/path.with.dots") assert_equal expected, FunkyPathMailer.template_root.to_s sub = Class.new(FunkyPathMailer) sub.template_root = 'test/path' - assert_equal 'test/path', sub.template_root.to_s + assert_equal File.expand_path('test/path'), sub.template_root.to_s assert_equal expected, FunkyPathMailer.template_root.to_s end end |