diff options
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/README.rdoc | 2 | ||||
-rwxr-xr-x | actionmailer/Rakefile | 2 | ||||
-rw-r--r-- | actionmailer/actionmailer.gemspec | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 17 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/mail_helper.rb | 28 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/old_api.rb | 6 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/tmail_compat.rb | 21 | ||||
-rw-r--r-- | actionmailer/test/abstract_unit.rb | 3 | ||||
-rw-r--r-- | actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb | 4 | ||||
-rw-r--r-- | actionmailer/test/i18n_with_controller_test.rb | 46 | ||||
-rw-r--r-- | actionmailer/test/old_base/tmail_compat_test.rb | 9 |
11 files changed, 100 insertions, 40 deletions
diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc index dfb696eb55..b346bd9e79 100644 --- a/actionmailer/README.rdoc +++ b/actionmailer/README.rdoc @@ -59,7 +59,7 @@ generated would look like this: Mr. david@loudthinking.com -In previous version of rails you would call <tt>create_method_name</tt> and +In previous version of Rails you would call <tt>create_method_name</tt> and <tt>deliver_method_name</tt>. Rails 3.0 has a much simpler interface, you simply call the method and optionally call +deliver+ on the return value. diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index 123ef9bbbf..df996acbc2 100755 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -17,7 +17,7 @@ namespace :test do task :isolated 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) + sh(ruby, '-Ilib:test', file) end or raise "Failures" end end diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec index 29b5813785..2ae85f8b57 100644 --- a/actionmailer/actionmailer.gemspec +++ b/actionmailer/actionmailer.gemspec @@ -20,5 +20,5 @@ Gem::Specification.new do |s| s.has_rdoc = true s.add_dependency('actionpack', version) - s.add_dependency('mail', '~> 2.2.9') + s.add_dependency('mail', '~> 2.2.15') end diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 840708cdc6..6ae1eac42a 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -246,7 +246,7 @@ module ActionMailer #:nodoc: # but Action Mailer translates them appropriately and sets the correct values. # # As you can pass in any header, you need to either quote the header as a string, or pass it in as - # an underscorised symbol, so the following will work: + # an underscored symbol, so the following will work: # # class Notifier < ActionMailer::Base # default 'Content-Transfer-Encoding' => '7bit', @@ -298,7 +298,7 @@ module ActionMailer #:nodoc: # # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method. # * <tt>:location</tt> - The location of the sendmail executable. Defaults to <tt>/usr/sbin/sendmail</tt>. - # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt> with <tt>-f sender@addres</tt> + # * <tt>:arguments</tt> - The command line arguments. Defaults to <tt>-i -t</tt> with <tt>-f sender@address</tt> # added automatically before the message is sent. # # * <tt>file_settings</tt> - Allows you to override options for the <tt>:file</tt> delivery method. @@ -404,7 +404,7 @@ module ActionMailer #:nodoc: end end - def respond_to?(method, *args) #:nodoc: + def respond_to?(method, include_private = false) #:nodoc: super || action_methods.include?(method.to_s) end @@ -693,15 +693,8 @@ module ActionMailer #:nodoc: end def each_template(paths, name, &block) #:nodoc: - Array.wrap(paths).each do |path| - templates = lookup_context.find_all(name, path) - templates = templates.uniq_by { |t| t.formats } - - unless templates.empty? - templates.each(&block) - return - end - end + templates = lookup_context.find_all(name, Array.wrap(paths)) + templates.uniq_by { |t| t.formats }.each(&block) end def create_parts_from_responses(m, responses) #:nodoc: diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index 80ffc9b7ee..887c7012d9 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -3,17 +3,8 @@ module ActionMailer # Uses Text::Format to take the text and format it, indented two spaces for # each line, and wrapped at 72 columns. def block_format(text) - begin - require 'text/format' - rescue LoadError => e - $stderr.puts "You don't have text-format installed in your application. Please add it to your Gemfile and run bundle install" - raise e - end unless defined?(Text::Format) - formatted = text.split(/\n\r\n/).collect { |paragraph| - Text::Format.new( - :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph - ).format + simple_format(paragraph) }.join("\n") # Make list points stand on their own line @@ -37,5 +28,22 @@ module ActionMailer def attachments @_message.attachments end + + private + def simple_format(text, len = 72, indent = 2) + sentences = [[]] + + text.split.each do |word| + if (sentences.last + [word]).join(' ').length > len + sentences << [word] + else + sentences.last << word + end + end + + sentences.map { |sentence| + "#{" " * indent}#{sentence.join(' ')}" + }.join "\n" + end end end diff --git a/actionmailer/lib/action_mailer/old_api.rb b/actionmailer/lib/action_mailer/old_api.rb index a8d7454898..04728cafb0 100644 --- a/actionmailer/lib/action_mailer/old_api.rb +++ b/actionmailer/lib/action_mailer/old_api.rb @@ -201,7 +201,7 @@ module ActionMailer if String === @body @parts.unshift create_inline_part(@body) elsif @parts.empty? || @parts.all? { |p| p.content_disposition =~ /^attachment/ } - lookup_context.find_all(@template, @mailer_name).each do |template| + lookup_context.find_all(@template, [@mailer_name]).each do |template| self.formats = template.formats @parts << create_inline_part(render(:template => template), template.mime_type) end @@ -242,12 +242,12 @@ module ActionMailer ct.to_s.split("/") end - def parse_content_type(defaults=nil) + def parse_content_type if @content_type.blank? [ nil, {} ] else ctype, *attrs = @content_type.split(/;\s*/) - attrs = Hash[attrs.map { |attr| attr.split(/\=/, 2) }] + attrs = Hash[attrs.map { |attr| attr.split(/=/, 2) }] [ctype, {"charset" => @charset}.merge!(attrs)] end end diff --git a/actionmailer/lib/action_mailer/tmail_compat.rb b/actionmailer/lib/action_mailer/tmail_compat.rb index 26cc474e91..1b2cdcfb27 100644 --- a/actionmailer/lib/action_mailer/tmail_compat.rb +++ b/actionmailer/lib/action_mailer/tmail_compat.rb @@ -2,16 +2,18 @@ module Mail class Message def set_content_type(*args) - ActiveSupport::Deprecation.warn('Message#set_content_type is deprecated, please just call ' << - 'Message#content_type with the same arguments', caller[0,2]) + message = 'Message#set_content_type is deprecated, please just call ' << + 'Message#content_type with the same arguments' + ActiveSupport::Deprecation.warn(message, caller[0,2]) content_type(*args) end alias :old_transfer_encoding :transfer_encoding def transfer_encoding(value = nil) if value - ActiveSupport::Deprecation.warn('Message#transfer_encoding is deprecated, please call ' << - 'Message#content_transfer_encoding with the same arguments', caller[0,2]) + message = 'Message#transfer_encoding is deprecated, ' << + 'please call Message#content_transfer_encoding with the same arguments' + ActiveSupport::Deprecation.warn(message, caller[0,2]) content_transfer_encoding(value) else old_transfer_encoding @@ -19,16 +21,17 @@ module Mail end def transfer_encoding=(value) - ActiveSupport::Deprecation.warn('Message#transfer_encoding= is deprecated, please call ' << - 'Message#content_transfer_encoding= with the same arguments', caller[0,2]) + message = 'Message#transfer_encoding= is deprecated, ' << + 'please call Message#content_transfer_encoding= with the same arguments' + ActiveSupport::Deprecation.warn(message, caller[0,2]) self.content_transfer_encoding = value end def original_filename - ActiveSupport::Deprecation.warn('Message#original_filename is deprecated, ' << - 'please call Message#filename', caller[0,2]) + message = 'Message#original_filename is deprecated, please call Message#filename' + ActiveSupport::Deprecation.warn(message, caller[0,2]) filename end end -end
\ No newline at end of file +end diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 0dce0ac15d..ce664bf301 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -25,7 +25,6 @@ end silence_warnings do # These external dependencies have warnings :/ - require 'text/format' require 'mail' end @@ -79,4 +78,4 @@ def restore_delivery_method ActionMailer::Base.delivery_method = @old_delivery_method end -ActiveSupport::Deprecation.silenced = true
\ No newline at end of file +ActiveSupport::Deprecation.silenced = true diff --git a/actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb b/actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb new file mode 100644 index 0000000000..f5340283f1 --- /dev/null +++ b/actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb @@ -0,0 +1,4 @@ +Hello there, + +Mr. <%= @recipient %>. Be greeted, new member! + diff --git a/actionmailer/test/i18n_with_controller_test.rb b/actionmailer/test/i18n_with_controller_test.rb new file mode 100644 index 0000000000..7040ae6f8d --- /dev/null +++ b/actionmailer/test/i18n_with_controller_test.rb @@ -0,0 +1,46 @@ +require 'abstract_unit' +require 'action_controller' + +class I18nTestMailer < ActionMailer::Base + configure do |c| + c.assets_dir = '' + end + + def mail_with_i18n_subject(recipient) + @recipient = recipient + I18n.locale = :de + mail(:to => recipient, :subject => "#{I18n.t :email_subject} #{recipient}", + :from => "system@loudthinking.com", :date => Time.local(2004, 12, 12)) + end +end + +class TestController < ActionController::Base + def send_mail + I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver + render :text => 'Mail sent' + end +end + +class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest + Routes = ActionDispatch::Routing::RouteSet.new + Routes.draw do + match ':controller(/:action(/:id))' + end + + def app + Routes + end + + def setup + I18n.backend.store_translations('de', :email_subject => '[Signed up] Welcome') + end + + def teardown + I18n.locale = :en + end + + def test_send_mail + get '/test/send_mail' + assert_equal "Mail sent", @response.body + end +end diff --git a/actionmailer/test/old_base/tmail_compat_test.rb b/actionmailer/test/old_base/tmail_compat_test.rb index 23706e99ff..51558c2bfa 100644 --- a/actionmailer/test/old_base/tmail_compat_test.rb +++ b/actionmailer/test/old_base/tmail_compat_test.rb @@ -1,6 +1,14 @@ require 'abstract_unit' class TmailCompatTest < ActiveSupport::TestCase + def setup + @silence = ActiveSupport::Deprecation.silenced + ActiveSupport::Deprecation.silenced = false + end + + def teardown + ActiveSupport::Deprecation.silenced = @silence + end def test_set_content_type_raises_deprecation_warning mail = Mail.new @@ -31,5 +39,4 @@ class TmailCompatTest < ActiveSupport::TestCase end assert_equal mail.content_transfer_encoding, "base64" end - end |