Update actionmailer with new hash syntax.

This commit is contained in:
Kirill Nikitin 2012-10-07 21:54:14 +04:00
parent 918f7038b3
commit 96f290eac0
15 changed files with 169 additions and 169 deletions

View File

@ -3,7 +3,7 @@ require 'rake/packagetask'
require 'rubygems/package_task' require 'rubygems/package_task'
desc "Default Task" desc "Default Task"
task :default => [ :test ] task default: [ :test ]
# Run the unit tests # Run the unit tests
Rake::TestTask.new { |t| Rake::TestTask.new { |t|
@ -29,7 +29,7 @@ Gem::PackageTask.new(spec) do |p|
end end
desc "Release to gemcutter" desc "Release to gemcutter"
task :release => :package do task release: :package do
require 'rake/gemcutter' require 'rake/gemcutter'
Rake::Gemcutter::Tasks.new(spec).define Rake::Gemcutter::Tasks.new(spec).define
Rake::Task['gem:push'].invoke Rake::Task['gem:push'].invoke

View File

@ -23,13 +23,13 @@ module ActionMailer
# Examples: # Examples:
# #
# class Notifier < ActionMailer::Base # class Notifier < ActionMailer::Base
# default :from => 'no-reply@example.com', # default from: 'no-reply@example.com',
# :return_path => 'system@example.com' # return_path: 'system@example.com'
# #
# def welcome(recipient) # def welcome(recipient)
# @account = recipient # @account = recipient
# mail(:to => recipient.email_address_with_name, # mail(to: recipient.email_address_with_name,
# :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"]) # bcc: ["bcc@example.com", "Order Watcher <watcher@example.com>"])
# end # end
# end # end
# #
@ -62,21 +62,21 @@ module ActionMailer
# #
# If you want to explicitly render only certain templates, pass a block: # If you want to explicitly render only certain templates, pass a block:
# #
# mail(:to => user.email) do |format| # mail(to: user.email) do |format|
# format.text # format.text
# format.html # format.html
# end # end
# #
# The block syntax is also useful in providing information specific to a part: # The block syntax is also useful in providing information specific to a part:
# #
# mail(:to => user.email) do |format| # mail(to: user.email) do |format|
# format.text(:content_transfer_encoding => "base64") # format.text(:content_transfer_encoding => "base64")
# format.html # format.html
# end # end
# #
# Or even to render a special view: # Or even to render a special view:
# #
# mail(:to => user.email) do |format| # mail(to: user.email) do |format|
# format.text # format.text
# format.html { render "some_other_template" } # format.html { render "some_other_template" }
# end # end
@ -100,12 +100,12 @@ module ActionMailer
# You can even use Action Pack helpers in these views. For example: # You can even use Action Pack helpers in these views. For example:
# #
# You got a new note! # You got a new note!
# <%= truncate(@note.body, :length => 25) %> # <%= truncate(@note.body, length: 25) %>
# #
# If you need to access the subject, from or the recipients in the view, you can do that through message object: # If you need to access the subject, from or the recipients in the view, you can do that through message object:
# #
# You got a new note from <%= message.from %>! # You got a new note from <%= message.from %>!
# <%= truncate(@note.body, :length => 25) %> # <%= truncate(@note.body, length: 25) %>
# #
# #
# = Generating URLs # = Generating URLs
@ -116,11 +116,11 @@ module ActionMailer
# #
# When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>: # When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
# #
# <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %> # <%= url_for(host: "example.com", controller: "welcome", action: "greeting") %>
# #
# When using named routes you only need to supply the <tt>:host</tt>: # When using named routes you only need to supply the <tt>:host</tt>:
# #
# <%= users_url(:host => "example.com") %> # <%= users_url(host: "example.com") %>
# #
# You should use the <tt>named_route_url</tt> style (which generates absolute URLs) and avoid using the # You should use the <tt>named_route_url</tt> style (which generates absolute URLs) and avoid using the
# <tt>named_route_path</tt> style (which generates relative URLs), since clients reading the mail will # <tt>named_route_path</tt> style (which generates relative URLs), since clients reading the mail will
@ -176,7 +176,7 @@ module ActionMailer
# class ApplicationMailer < ActionMailer::Base # class ApplicationMailer < ActionMailer::Base
# def welcome(recipient) # def welcome(recipient)
# attachments['free_book.pdf'] = File.read('path/to/file.pdf') # attachments['free_book.pdf'] = File.read('path/to/file.pdf')
# mail(:to => recipient, :subject => "New account information") # mail(to: recipient, subject: "New account information")
# end # end
# end # end
# #
@ -192,7 +192,7 @@ module ActionMailer
# class ApplicationMailer < ActionMailer::Base # class ApplicationMailer < ActionMailer::Base
# def welcome(recipient) # def welcome(recipient)
# attachments['free_book.pdf'] = File.read('path/to/file.pdf') # attachments['free_book.pdf'] = File.read('path/to/file.pdf')
# mail(:to => recipient, :subject => "New account information", :body => "") # mail(to: recipient, subject: "New account information", body: "")
# end # end
# end # end
# #
@ -204,7 +204,7 @@ module ActionMailer
# class ApplicationMailer < ActionMailer::Base # class ApplicationMailer < ActionMailer::Base
# def welcome(recipient) # def welcome(recipient)
# attachments.inline['photo.png'] = File.read('path/to/photo.png') # attachments.inline['photo.png'] = File.read('path/to/photo.png')
# mail(:to => recipient, :subject => "Here is what we look like") # mail(to: recipient, subject: "Here is what we look like")
# end # end
# end # end
# #
@ -220,7 +220,7 @@ module ActionMailer
# #
# <h1>Please Don't Cringe</h1> # <h1>Please Don't Cringe</h1>
# #
# <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%> # <%= image_tag attachments['photo.png'].url, alt: 'Our Photo', class: 'photo' -%>
# #
# = Observing and Intercepting Mails # = Observing and Intercepting Mails
# #
@ -241,7 +241,7 @@ module ActionMailer
# default method inside the class definition: # default method inside the class definition:
# #
# class Notifier < ActionMailer::Base # class Notifier < ActionMailer::Base
# default :sender => 'system@example.com' # default sender: 'system@example.com'
# end # end
# #
# You can pass in any header value that a <tt>Mail::Message</tt> accepts. Out of the box, # You can pass in any header value that a <tt>Mail::Message</tt> accepts. Out of the box,
@ -260,7 +260,7 @@ module ActionMailer
# #
# class Notifier < ActionMailer::Base # class Notifier < ActionMailer::Base
# default 'Content-Transfer-Encoding' => '7bit', # default 'Content-Transfer-Encoding' => '7bit',
# :content_description => 'This is a description' # content_description: 'This is a description'
# end # end
# #
# Finally, Action Mailer also supports passing <tt>Proc</tt> objects into the default hash, so you # Finally, Action Mailer also supports passing <tt>Proc</tt> objects into the default hash, so you
@ -386,10 +386,10 @@ module ActionMailer
class_attribute :default_params class_attribute :default_params
self.default_params = { self.default_params = {
:mime_version => "1.0", mime_version: "1.0",
:charset => "UTF-8", charset: "UTF-8",
:content_type => "text/plain", content_type: "text/plain",
:parts_order => [ "text/plain", "text/enriched", "text/html" ] parts_order: [ "text/plain", "text/enriched", "text/html" ]
}.freeze }.freeze
class_attribute :queue class_attribute :queue
@ -549,17 +549,17 @@ module ActionMailer
# #
# You can also specify overrides if you want by passing a hash instead of a string: # You can also specify overrides if you want by passing a hash instead of a string:
# #
# mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip', # mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
# :content => File.read('/path/to/filename.jpg')} # content: File.read('/path/to/filename.jpg')}
# #
# If you want to use a different encoding than Base64, you can pass an encoding in, # If you want to use a different encoding than Base64, you can pass an encoding in,
# but then it is up to you to pass in the content pre-encoded, and don't expect # but then it is up to you to pass in the content pre-encoded, and don't expect
# Mail to know how to decode this data: # Mail to know how to decode this data:
# #
# file_content = SpecialEncode(File.read('/path/to/filename.jpg')) # file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
# mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip', # mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
# :encoding => 'SpecialEncoding', # encoding: 'SpecialEncoding',
# :content => file_content } # content: file_content }
# #
# You can also search for specific attachments: # You can also search for specific attachments:
# #
@ -597,9 +597,9 @@ module ActionMailer
# class method: # class method:
# #
# class Notifier < ActionMailer::Base # class Notifier < ActionMailer::Base
# self.default :from => 'no-reply@test.lindsaar.net', # self.default from: 'no-reply@test.lindsaar.net',
# :bcc => 'email_logger@test.lindsaar.net', # bcc: 'email_logger@test.lindsaar.net',
# :reply_to => 'bounces@test.lindsaar.net' # reply_to: 'bounces@test.lindsaar.net'
# end # end
# #
# If you need other headers not listed above, you can either pass them in # If you need other headers not listed above, you can either pass them in
@ -621,10 +621,10 @@ module ActionMailer
# For example: # For example:
# #
# class Notifier < ActionMailer::Base # class Notifier < ActionMailer::Base
# default :from => 'no-reply@test.lindsaar.net', # default from: 'no-reply@test.lindsaar.net',
# #
# def welcome # def welcome
# mail(:to => 'mikel@test.lindsaar.net') # mail(to: 'mikel@test.lindsaar.net')
# end # end
# end # end
# #
@ -633,22 +633,22 @@ module ActionMailer
# #
# However, those can be customized: # However, those can be customized:
# #
# mail(:template_path => 'notifications', :template_name => 'another') # mail(template_path: 'notifications', template_name: 'another')
# #
# And now it will look for all templates at "app/views/notifications" with name "another". # And now it will look for all templates at "app/views/notifications" with name "another".
# #
# If you do pass a block, you can render specific templates of your choice: # If you do pass a block, you can render specific templates of your choice:
# #
# mail(:to => 'mikel@test.lindsaar.net') do |format| # mail(to: 'mikel@test.lindsaar.net') do |format|
# format.text # format.text
# format.html # format.html
# end # end
# #
# You can even render text directly without using a template: # You can even render text directly without using a template:
# #
# mail(:to => 'mikel@test.lindsaar.net') do |format| # mail(to: 'mikel@test.lindsaar.net') do |format|
# format.text { render :text => "Hello Mikel!" } # format.text { render text: "Hello Mikel!" }
# format.html { render :text => "<h1>Hello Mikel!</h1>" } # format.html { render text: "<h1>Hello Mikel!</h1>" }
# end # end
# #
# Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and # Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
@ -657,7 +657,7 @@ module ActionMailer
# The block syntax also allows you to customize the part headers if desired: # The block syntax also allows you to customize the part headers if desired:
# #
# mail(:to => 'mikel@test.lindsaar.net') do |format| # mail(:to => 'mikel@test.lindsaar.net') do |format|
# format.text(:content_transfer_encoding => "base64") # format.text(content_transfer_encoding: "base64")
# format.html # format.html
# end # end
# #
@ -730,7 +730,7 @@ module ActionMailer
# humanized version of the <tt>action_name</tt>. # humanized version of the <tt>action_name</tt>.
def default_i18n_subject #:nodoc: def default_i18n_subject #:nodoc:
mailer_scope = self.class.mailer_name.tr('/', '.') mailer_scope = self.class.mailer_name.tr('/', '.')
I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize) I18n.t(:subject, scope: [mailer_scope, action_name], default: action_name.humanize)
end end
def collect_responses_and_parts_order(headers) #:nodoc: def collect_responses_and_parts_order(headers) #:nodoc:
@ -743,8 +743,8 @@ module ActionMailer
responses = collector.responses responses = collector.responses
elsif headers[:body] elsif headers[:body]
responses << { responses << {
:body => headers.delete(:body), body: headers.delete(:body),
:content_type => self.class.default[:content_type] || "text/plain" content_type: self.class.default[:content_type] || "text/plain"
} }
else else
templates_path = headers.delete(:template_path) || self.class.mailer_name templates_path = headers.delete(:template_path) || self.class.mailer_name
@ -754,8 +754,8 @@ module ActionMailer
self.formats = template.formats self.formats = template.formats
responses << { responses << {
:body => render(:template => template), body: render(template: template),
:content_type => template.type.to_s content_type: template.type.to_s
} }
end end
end end

View File

@ -21,7 +21,7 @@ module ActionMailer
alias :all :any alias :all :any
def custom(mime, options={}) def custom(mime, options={})
options.reverse_merge!(:content_type => mime.to_s) options.reverse_merge!(content_type: mime.to_s)
@context.formats = [mime.to_sym] @context.formats = [mime.to_sym]
options[:body] = block_given? ? yield : @default_render.call options[:body] = block_given? ? yield : @default_render.call
@responses << options @responses << options

View File

@ -20,27 +20,27 @@ module ActionMailer
self.delivery_method = :smtp self.delivery_method = :smtp
add_delivery_method :smtp, Mail::SMTP, add_delivery_method :smtp, Mail::SMTP,
:address => "localhost", address: "localhost",
:port => 25, port: 25,
:domain => 'localhost.localdomain', domain: 'localhost.localdomain',
:user_name => nil, user_name: nil,
:password => nil, password: nil,
:authentication => nil, authentication: nil,
:enable_starttls_auto => true enable_starttls_auto: true
add_delivery_method :file, Mail::FileDelivery, add_delivery_method :file, Mail::FileDelivery,
:location => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails" location: defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
add_delivery_method :sendmail, Mail::Sendmail, add_delivery_method :sendmail, Mail::Sendmail,
:location => '/usr/sbin/sendmail', location: '/usr/sbin/sendmail',
:arguments => '-i -t' arguments: '-i -t'
add_delivery_method :test, Mail::TestMailer add_delivery_method :test, Mail::TestMailer
end end
module ClassMethods module ClassMethods
# Provides a list of emails that have been delivered by Mail::TestMailer # Provides a list of emails that have been delivered by Mail::TestMailer
delegate :deliveries, :deliveries=, :to => Mail::TestMailer delegate :deliveries, :deliveries=, to: Mail::TestMailer
# Adds a new delivery method through the given class using the given # Adds a new delivery method through the given class using the given
# symbol as alias and the default options supplied. # symbol as alias and the default options supplied.

View File

@ -3,7 +3,7 @@ module Rails
class MailerGenerator < NamedBase class MailerGenerator < NamedBase
source_root File.expand_path("../templates", __FILE__) source_root File.expand_path("../templates", __FILE__)
argument :actions, :type => :array, :default => [], :banner => "method method" argument :actions, type: :array, default: [], banner: "method method"
check_class_collision check_class_collision
def create_mailer_file def create_mailer_file

View File

@ -3,9 +3,9 @@ require 'action_controller'
class AssetHostMailer < ActionMailer::Base class AssetHostMailer < ActionMailer::Base
def email_with_asset def email_with_asset
mail :to => 'test@localhost', mail to: 'test@localhost',
:subject => 'testing email containing asset path while asset_host is set', subject: 'testing email containing asset path while asset_host is set',
:from => 'tester@example.com' from: 'tester@example.com'
end end
end end

View File

@ -30,21 +30,21 @@ class BaseTest < ActiveSupport::TestCase
end end
test "mail() with from overwrites the class level default" do test "mail() with from overwrites the class level default" do
email = BaseMailer.welcome(:from => 'someone@example.com', email = BaseMailer.welcome(from: 'someone@example.com',
:to => 'another@example.org') to: 'another@example.org')
assert_equal(['someone@example.com'], email.from) assert_equal(['someone@example.com'], email.from)
assert_equal(['another@example.org'], email.to) assert_equal(['another@example.org'], email.to)
end end
test "mail() with bcc, cc, content_type, charset, mime_version, reply_to and date" do test "mail() with bcc, cc, content_type, charset, mime_version, reply_to and date" do
time = Time.now.beginning_of_day.to_datetime time = Time.now.beginning_of_day.to_datetime
email = BaseMailer.welcome(:bcc => 'bcc@test.lindsaar.net', email = BaseMailer.welcome(bcc: 'bcc@test.lindsaar.net',
:cc => 'cc@test.lindsaar.net', cc: 'cc@test.lindsaar.net',
:content_type => 'multipart/mixed', content_type: 'multipart/mixed',
:charset => 'iso-8559-1', charset: 'iso-8559-1',
:mime_version => '2.0', mime_version: '2.0',
:reply_to => 'reply-to@test.lindsaar.net', reply_to: 'reply-to@test.lindsaar.net',
:date => time) date: time)
assert_equal(['bcc@test.lindsaar.net'], email.bcc) assert_equal(['bcc@test.lindsaar.net'], email.bcc)
assert_equal(['cc@test.lindsaar.net'], email.cc) assert_equal(['cc@test.lindsaar.net'], email.cc)
assert_equal('multipart/mixed; charset=iso-8559-1', email.content_type) assert_equal('multipart/mixed; charset=iso-8559-1', email.content_type)
@ -60,7 +60,7 @@ class BaseTest < ActiveSupport::TestCase
end end
test "can pass in :body to the mail method hash" do test "can pass in :body to the mail method hash" do
email = BaseMailer.welcome(:body => "Hello there") email = BaseMailer.welcome(body: "Hello there")
assert_equal("text/plain", email.mime_type) assert_equal("text/plain", email.mime_type)
assert_equal("Hello there", email.body.encoded) assert_equal("Hello there", email.body.encoded)
end end
@ -142,7 +142,7 @@ class BaseTest < ActiveSupport::TestCase
end end
test "adds the given :body as part" do test "adds the given :body as part" do
email = BaseMailer.attachment_with_content(:body => "I'm the eggman") email = BaseMailer.attachment_with_content(body: "I'm the eggman")
assert_equal(2, email.parts.length) assert_equal(2, email.parts.length)
assert_equal("multipart/mixed", email.mime_type) assert_equal("multipart/mixed", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type) assert_equal("text/plain", email.parts[0].mime_type)
@ -165,31 +165,31 @@ class BaseTest < ActiveSupport::TestCase
# Defaults values # Defaults values
test "uses default charset from class" do test "uses default charset from class" do
with_default BaseMailer, :charset => "US-ASCII" do with_default BaseMailer, charset: "US-ASCII" do
email = BaseMailer.welcome email = BaseMailer.welcome
assert_equal("US-ASCII", email.charset) assert_equal("US-ASCII", email.charset)
email = BaseMailer.welcome(:charset => "iso-8559-1") email = BaseMailer.welcome(charset: "iso-8559-1")
assert_equal("iso-8559-1", email.charset) assert_equal("iso-8559-1", email.charset)
end end
end end
test "uses default content type from class" do test "uses default content type from class" do
with_default BaseMailer, :content_type => "text/html" do with_default BaseMailer, content_type: "text/html" do
email = BaseMailer.welcome email = BaseMailer.welcome
assert_equal("text/html", email.mime_type) assert_equal("text/html", email.mime_type)
email = BaseMailer.welcome(:content_type => "text/plain") email = BaseMailer.welcome(content_type: "text/plain")
assert_equal("text/plain", email.mime_type) assert_equal("text/plain", email.mime_type)
end end
end end
test "uses default mime version from class" do test "uses default mime version from class" do
with_default BaseMailer, :mime_version => "2.0" do with_default BaseMailer, mime_version: "2.0" do
email = BaseMailer.welcome email = BaseMailer.welcome
assert_equal("2.0", email.mime_version) assert_equal("2.0", email.mime_version)
email = BaseMailer.welcome(:mime_version => "1.0") email = BaseMailer.welcome(mime_version: "1.0")
assert_equal("1.0", email.mime_version) assert_equal("1.0", email.mime_version)
end end
end end
@ -202,17 +202,17 @@ class BaseTest < ActiveSupport::TestCase
end end
test "subject gets default from I18n" do test "subject gets default from I18n" do
BaseMailer.default :subject => nil BaseMailer.default subject: nil
email = BaseMailer.welcome(:subject => nil) email = BaseMailer.welcome(subject: nil)
assert_equal "Welcome", email.subject assert_equal "Welcome", email.subject
I18n.backend.store_translations('en', :base_mailer => {:welcome => {:subject => "New Subject!"}}) I18n.backend.store_translations('en', base_mailer: {welcome: {subject: "New Subject!"}})
email = BaseMailer.welcome(:subject => nil) email = BaseMailer.welcome(subject: nil)
assert_equal "New Subject!", email.subject assert_equal "New Subject!", email.subject
end end
test "translations are scoped properly" do test "translations are scoped properly" do
I18n.backend.store_translations('en', :base_mailer => {:email_with_translations => {:greet_user => "Hello %{name}!"}}) I18n.backend.store_translations('en', base_mailer: {email_with_translations: {greet_user: "Hello %{name}!"}})
email = BaseMailer.email_with_translations email = BaseMailer.email_with_translations
assert_equal 'Hello lifo!', email.body.encoded assert_equal 'Hello lifo!', email.body.encoded
end end
@ -230,19 +230,19 @@ class BaseTest < ActiveSupport::TestCase
test "implicit multipart with sort order" do test "implicit multipart with sort order" do
order = ["text/html", "text/plain"] order = ["text/html", "text/plain"]
with_default BaseMailer, :parts_order => order do with_default BaseMailer, parts_order: order do
email = BaseMailer.implicit_multipart email = BaseMailer.implicit_multipart
assert_equal("text/html", email.parts[0].mime_type) assert_equal("text/html", email.parts[0].mime_type)
assert_equal("text/plain", email.parts[1].mime_type) assert_equal("text/plain", email.parts[1].mime_type)
email = BaseMailer.implicit_multipart(:parts_order => order.reverse) email = BaseMailer.implicit_multipart(parts_order: order.reverse)
assert_equal("text/plain", email.parts[0].mime_type) assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("text/html", email.parts[1].mime_type) assert_equal("text/html", email.parts[1].mime_type)
end end
end end
test "implicit multipart with attachments creates nested parts" do test "implicit multipart with attachments creates nested parts" do
email = BaseMailer.implicit_multipart(:attachments => true) email = BaseMailer.implicit_multipart(attachments: true)
assert_equal("application/pdf", email.parts[0].mime_type) assert_equal("application/pdf", email.parts[0].mime_type)
assert_equal("multipart/alternative", email.parts[1].mime_type) assert_equal("multipart/alternative", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[0].mime_type) assert_equal("text/plain", email.parts[1].parts[0].mime_type)
@ -253,8 +253,8 @@ class BaseTest < ActiveSupport::TestCase
test "implicit multipart with attachments and sort order" do test "implicit multipart with attachments and sort order" do
order = ["text/html", "text/plain"] order = ["text/html", "text/plain"]
with_default BaseMailer, :parts_order => order do with_default BaseMailer, parts_order: order do
email = BaseMailer.implicit_multipart(:attachments => true) email = BaseMailer.implicit_multipart(attachments: true)
assert_equal("application/pdf", email.parts[0].mime_type) assert_equal("application/pdf", email.parts[0].mime_type)
assert_equal("multipart/alternative", email.parts[1].mime_type) assert_equal("multipart/alternative", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[1].mime_type) assert_equal("text/plain", email.parts[1].parts[1].mime_type)
@ -273,7 +273,7 @@ class BaseTest < ActiveSupport::TestCase
end end
test "implicit multipart with other locale" do test "implicit multipart with other locale" do
swap I18n, :locale => :pl do swap I18n, locale: :pl do
email = BaseMailer.implicit_with_locale email = BaseMailer.implicit_with_locale
assert_equal(2, email.parts.size) assert_equal(2, email.parts.size)
assert_equal("multipart/alternative", email.mime_type) assert_equal("multipart/alternative", email.mime_type)
@ -324,19 +324,19 @@ class BaseTest < ActiveSupport::TestCase
test "explicit multipart does not sort order" do test "explicit multipart does not sort order" do
order = ["text/html", "text/plain"] order = ["text/html", "text/plain"]
with_default BaseMailer, :parts_order => order do with_default BaseMailer, parts_order: order do
email = BaseMailer.explicit_multipart email = BaseMailer.explicit_multipart
assert_equal("text/plain", email.parts[0].mime_type) assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("text/html", email.parts[1].mime_type) assert_equal("text/html", email.parts[1].mime_type)
email = BaseMailer.explicit_multipart(:parts_order => order.reverse) email = BaseMailer.explicit_multipart(parts_order: order.reverse)
assert_equal("text/plain", email.parts[0].mime_type) assert_equal("text/plain", email.parts[0].mime_type)
assert_equal("text/html", email.parts[1].mime_type) assert_equal("text/html", email.parts[1].mime_type)
end end
end end
test "explicit multipart with attachments creates nested parts" do test "explicit multipart with attachments creates nested parts" do
email = BaseMailer.explicit_multipart(:attachments => true) email = BaseMailer.explicit_multipart(attachments: true)
assert_equal("application/pdf", email.parts[0].mime_type) assert_equal("application/pdf", email.parts[0].mime_type)
assert_equal("multipart/alternative", email.parts[1].mime_type) assert_equal("multipart/alternative", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[0].mime_type) assert_equal("text/plain", email.parts[1].parts[0].mime_type)
@ -651,7 +651,7 @@ class BaseTest < ActiveSupport::TestCase
test "default_from can be set" do test "default_from can be set" do
class DefaultFromMailer < ActionMailer::Base class DefaultFromMailer < ActionMailer::Base
default :to => 'system@test.lindsaar.net' default to: 'system@test.lindsaar.net'
self.default_options = {from: "robert.pankowecki@gmail.com"} self.default_options = {from: "robert.pankowecki@gmail.com"}
def welcome def welcome

View File

@ -22,24 +22,24 @@ end
class DefaultsDeliveryMethodsTest < ActiveSupport::TestCase class DefaultsDeliveryMethodsTest < ActiveSupport::TestCase
test "default smtp settings" do test "default smtp settings" do
settings = { :address => "localhost", settings = { address: "localhost",
:port => 25, port: 25,
:domain => 'localhost.localdomain', domain: 'localhost.localdomain',
:user_name => nil, user_name: nil,
:password => nil, password: nil,
:authentication => nil, authentication: nil,
:enable_starttls_auto => true } enable_starttls_auto: true }
assert_equal settings, ActionMailer::Base.smtp_settings assert_equal settings, ActionMailer::Base.smtp_settings
end end
test "default file delivery settings" do test "default file delivery settings" do
settings = {:location => "#{Dir.tmpdir}/mails"} settings = {location: "#{Dir.tmpdir}/mails"}
assert_equal settings, ActionMailer::Base.file_settings assert_equal settings, ActionMailer::Base.file_settings
end end
test "default sendmail settings" do test "default sendmail settings" do
settings = {:location => '/usr/sbin/sendmail', settings = {location: '/usr/sbin/sendmail',
:arguments => '-i -t'} arguments: '-i -t'}
assert_equal settings, ActionMailer::Base.sendmail_settings assert_equal settings, ActionMailer::Base.sendmail_settings
end end
end end
@ -63,8 +63,8 @@ class CustomDeliveryMethodsTest < ActiveSupport::TestCase
end end
test "allow to customize custom settings" do test "allow to customize custom settings" do
ActionMailer::Base.custom_settings = { :foo => :bar } ActionMailer::Base.custom_settings = { foo: :bar }
assert_equal Hash[:foo => :bar], ActionMailer::Base.custom_settings assert_equal Hash[foo: :bar], ActionMailer::Base.custom_settings
end end
test "respond to custom settings" do test "respond to custom settings" do
@ -82,8 +82,8 @@ end
class MailDeliveryTest < ActiveSupport::TestCase class MailDeliveryTest < ActiveSupport::TestCase
class DeliveryMailer < ActionMailer::Base class DeliveryMailer < ActionMailer::Base
DEFAULT_HEADERS = { DEFAULT_HEADERS = {
:to => 'mikel@test.lindsaar.net', to: 'mikel@test.lindsaar.net',
:from => 'jose@test.plataformatec.com' from: 'jose@test.plataformatec.com'
} }
def welcome(hash={}) def welcome(hash={})
@ -110,7 +110,7 @@ class MailDeliveryTest < ActiveSupport::TestCase
test "delivery method can be customized per instance" do test "delivery method can be customized per instance" do
email = DeliveryMailer.welcome.deliver email = DeliveryMailer.welcome.deliver
assert_instance_of Mail::SMTP, email.delivery_method assert_instance_of Mail::SMTP, email.delivery_method
email = DeliveryMailer.welcome(:delivery_method => :test).deliver email = DeliveryMailer.welcome(delivery_method: :test).deliver
assert_instance_of Mail::TestMailer, email.delivery_method assert_instance_of Mail::TestMailer, email.delivery_method
end end
@ -125,7 +125,7 @@ class MailDeliveryTest < ActiveSupport::TestCase
test "delivery method options default to class level options" do test "delivery method options default to class level options" do
default_options = {a: "b"} default_options = {a: "b"}
ActionMailer::Base.add_delivery_method :optioned, MyOptionedDelivery, default_options ActionMailer::Base.add_delivery_method :optioned, MyOptionedDelivery, default_options
mail_instance = DeliveryMailer.welcome(:delivery_method => :optioned) mail_instance = DeliveryMailer.welcome(delivery_method: :optioned)
assert_equal default_options, mail_instance.delivery_method.options assert_equal default_options, mail_instance.delivery_method.options
end end
@ -133,21 +133,21 @@ class MailDeliveryTest < ActiveSupport::TestCase
default_options = {a: "b"} default_options = {a: "b"}
ActionMailer::Base.add_delivery_method :optioned, MyOptionedDelivery, default_options ActionMailer::Base.add_delivery_method :optioned, MyOptionedDelivery, default_options
overridden_options = {a: "a"} overridden_options = {a: "a"}
mail_instance = DeliveryMailer.welcome(:delivery_method => :optioned, :delivery_method_options => overridden_options) mail_instance = DeliveryMailer.welcome(delivery_method: :optioned, delivery_method_options: overridden_options)
assert_equal overridden_options, mail_instance.delivery_method.options assert_equal overridden_options, mail_instance.delivery_method.options
end end
test "default delivery options can be overridden per mail instance" do test "default delivery options can be overridden per mail instance" do
settings = { :address => "localhost", settings = { address: "localhost",
:port => 25, port: 25,
:domain => 'localhost.localdomain', domain: 'localhost.localdomain',
:user_name => nil, user_name: nil,
:password => nil, password: nil,
:authentication => nil, authentication: nil,
:enable_starttls_auto => true } enable_starttls_auto: true }
assert_equal settings, ActionMailer::Base.smtp_settings assert_equal settings, ActionMailer::Base.smtp_settings
overridden_options = {user_name: "overridden", :password => "somethingobtuse"} overridden_options = {user_name: "overridden", password: "somethingobtuse"}
mail_instance = DeliveryMailer.welcome(:delivery_method_options => overridden_options) mail_instance = DeliveryMailer.welcome(delivery_method_options: overridden_options)
delivery_method_instance = mail_instance.delivery_method delivery_method_instance = mail_instance.delivery_method
assert_equal "overridden", delivery_method_instance.settings[:user_name] assert_equal "overridden", delivery_method_instance.settings[:user_name]
assert_equal "somethingobtuse", delivery_method_instance.settings[:password] assert_equal "somethingobtuse", delivery_method_instance.settings[:password]

View File

@ -9,15 +9,15 @@ class I18nTestMailer < ActionMailer::Base
def mail_with_i18n_subject(recipient) def mail_with_i18n_subject(recipient)
@recipient = recipient @recipient = recipient
I18n.locale = :de I18n.locale = :de
mail(:to => recipient, :subject => "#{I18n.t :email_subject} #{recipient}", mail(to: recipient, subject: "#{I18n.t :email_subject} #{recipient}",
:from => "system@loudthinking.com", :date => Time.local(2004, 12, 12)) from: "system@loudthinking.com", date: Time.local(2004, 12, 12))
end end
end end
class TestController < ActionController::Base class TestController < ActionController::Base
def send_mail def send_mail
I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver
render :text => 'Mail sent' render text: 'Mail sent'
end end
end end
@ -32,7 +32,7 @@ class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest
end end
def setup def setup
I18n.backend.store_translations('de', :email_subject => '[Signed up] Welcome') I18n.backend.store_translations('de', email_subject: '[Signed up] Welcome')
end end
def teardown def teardown

View File

@ -10,7 +10,7 @@ class HelperMailer < ActionMailer::Base
"it off!" "it off!"
mail_with_defaults do |format| mail_with_defaults do |format|
format.html { render(:inline => "<%= block_format @text %>") } format.html { render(inline: "<%= block_format @text %>") }
end end
end end
@ -18,7 +18,7 @@ class HelperMailer < ActionMailer::Base
@text = "But soft! What light through yonder window breaks?" @text = "But soft! What light through yonder window breaks?"
mail_with_defaults do |format| mail_with_defaults do |format|
format.html { render(:inline => "<%= format_paragraph @text, 15, 1 %>") } format.html { render(inline: "<%= format_paragraph @text, 15, 1 %>") }
end end
end end
@ -26,19 +26,19 @@ class HelperMailer < ActionMailer::Base
@text = "Antidisestablishmentarianism is very long." @text = "Antidisestablishmentarianism is very long."
mail_with_defaults do |format| mail_with_defaults do |format|
format.html { render(:inline => "<%= format_paragraph @text, 10, 1 %>") } format.html { render(inline: "<%= format_paragraph @text, 10, 1 %>") }
end end
end end
def use_mailer def use_mailer
mail_with_defaults do |format| mail_with_defaults do |format|
format.html { render(:inline => "<%= mailer.message.subject %>") } format.html { render(inline: "<%= mailer.message.subject %>") }
end end
end end
def use_message def use_message
mail_with_defaults do |format| mail_with_defaults do |format|
format.html { render(:inline => "<%= message.subject %>") } format.html { render(inline: "<%= message.subject %>") }
end end
end end
@ -55,15 +55,15 @@ The second
TEXT TEXT
mail_with_defaults do |format| mail_with_defaults do |format|
format.html { render(:inline => "<%= block_format @text %>") } format.html { render(inline: "<%= block_format @text %>") }
end end
end end
protected protected
def mail_with_defaults(&block) def mail_with_defaults(&block)
mail(:to => "test@localhost", :from => "tester@example.com", mail(to: "test@localhost", from: "tester@example.com",
:subject => "using helpers", &block) subject: "using helpers", &block)
end end
end end

View File

@ -1,9 +1,9 @@
require 'abstract_unit' require 'abstract_unit'
class AutoLayoutMailer < ActionMailer::Base class AutoLayoutMailer < ActionMailer::Base
default :to => 'test@localhost', default to: 'test@localhost',
:subject => "You have a mail", subject: "You have a mail",
:from => "tester@example.com" from: "tester@example.com"
def hello def hello
mail() mail()
@ -11,16 +11,16 @@ class AutoLayoutMailer < ActionMailer::Base
def spam def spam
@world = "Earth" @world = "Earth"
mail(:body => render(:inline => "Hello, <%= @world %>", :layout => 'spam')) mail(body: render(inline: "Hello, <%= @world %>", layout: 'spam'))
end end
def nolayout def nolayout
@world = "Earth" @world = "Earth"
mail(:body => render(:inline => "Hello, <%= @world %>", :layout => false)) mail(body: render(inline: "Hello, <%= @world %>", layout: false))
end end
def multipart(type = nil) def multipart(type = nil)
mail(:content_type => type) do |format| mail(content_type: type) do |format|
format.text { render } format.text { render }
format.html { render } format.html { render }
end end
@ -28,11 +28,11 @@ class AutoLayoutMailer < ActionMailer::Base
end end
class ExplicitLayoutMailer < ActionMailer::Base class ExplicitLayoutMailer < ActionMailer::Base
layout 'spam', :except => [:logout] layout 'spam', except: [:logout]
default :to => 'test@localhost', default to: 'test@localhost',
:subject => "You have a mail", subject: "You have a mail",
:from => "tester@example.com" from: "tester@example.com"
def signup def signup
mail() mail()

View File

@ -1,13 +1,13 @@
class BaseMailer < ActionMailer::Base class BaseMailer < ActionMailer::Base
self.mailer_name = "base_mailer" self.mailer_name = "base_mailer"
default :to => 'system@test.lindsaar.net', default to: 'system@test.lindsaar.net',
:from => 'jose@test.plataformatec.com', from: 'jose@test.plataformatec.com',
:reply_to => 'mikel@test.lindsaar.net' reply_to: 'mikel@test.lindsaar.net'
def welcome(hash = {}) def welcome(hash = {})
headers['X-SPAM'] = "Not SPAM" headers['X-SPAM'] = "Not SPAM"
mail({:subject => "The first email on new API!"}.merge!(hash)) mail({subject: "The first email on new API!"}.merge!(hash))
end end
def welcome_with_headers(hash = {}) def welcome_with_headers(hash = {})
@ -16,7 +16,7 @@ class BaseMailer < ActionMailer::Base
end end
def welcome_from_another_path(path) def welcome_from_another_path(path)
mail(:template_name => "welcome", :template_path => path) mail(template_name: "welcome", template_path: path)
end end
def html_only(hash = {}) def html_only(hash = {})
@ -38,15 +38,15 @@ class BaseMailer < ActionMailer::Base
end end
def attachment_with_hash def attachment_with_hash
attachments['invoice.jpg'] = { :data => "\312\213\254\232)b", attachments['invoice.jpg'] = { data: "\312\213\254\232)b",
:mime_type => "image/x-jpg", mime_type: "image/x-jpg",
:transfer_encoding => "base64" } transfer_encoding: "base64" }
mail mail
end end
def attachment_with_hash_default_encoding def attachment_with_hash_default_encoding
attachments['invoice.jpg'] = { :data => "\312\213\254\232)b", attachments['invoice.jpg'] = { data: "\312\213\254\232)b",
:mime_type => "image/x-jpg" } mime_type: "image/x-jpg" }
mail mail
end end
@ -62,8 +62,8 @@ class BaseMailer < ActionMailer::Base
def explicit_multipart(hash = {}) def explicit_multipart(hash = {})
attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments) attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments)
mail(hash) do |format| mail(hash) do |format|
format.text { render :text => "TEXT Explicit Multipart" } format.text { render text: "TEXT Explicit Multipart" }
format.html { render :text => "HTML Explicit Multipart" } format.html { render text: "HTML Explicit Multipart" }
end end
end end
@ -76,13 +76,13 @@ class BaseMailer < ActionMailer::Base
def explicit_multipart_with_any(hash = {}) def explicit_multipart_with_any(hash = {})
mail(hash) do |format| mail(hash) do |format|
format.any(:text, :html){ render :text => "Format with any!" } format.any(:text, :html){ render text: "Format with any!" }
end end
end end
def explicit_multipart_with_options(include_html = false) def explicit_multipart_with_options(include_html = false)
mail do |format| mail do |format|
format.text(:content_transfer_encoding => "base64"){ render "welcome" } format.text(content_transfer_encoding: "base64"){ render "welcome" }
format.html{ render "welcome" } if include_html format.html{ render "welcome" } if include_html
end end
end end
@ -95,24 +95,24 @@ class BaseMailer < ActionMailer::Base
end end
def implicit_different_template(template_name='') def implicit_different_template(template_name='')
mail(:template_name => template_name) mail(template_name: template_name)
end end
def explicit_different_template(template_name='') def explicit_different_template(template_name='')
mail do |format| mail do |format|
format.text { render :template => "#{mailer_name}/#{template_name}" } format.text { render template: "#{mailer_name}/#{template_name}" }
format.html { render :template => "#{mailer_name}/#{template_name}" } format.html { render template: "#{mailer_name}/#{template_name}" }
end end
end end
def different_layout(layout_name='') def different_layout(layout_name='')
mail do |format| mail do |format|
format.text { render :layout => layout_name } format.text { render layout: layout_name }
format.html { render :layout => layout_name } format.html { render layout: layout_name }
end end
end end
def email_with_translations def email_with_translations
mail :body => render("email_with_translations", :formats => [:html]) mail body: render("email_with_translations", formats: [:html])
end end
end end

View File

@ -1,7 +1,7 @@
class ProcMailer < ActionMailer::Base class ProcMailer < ActionMailer::Base
default :to => 'system@test.lindsaar.net', default to: 'system@test.lindsaar.net',
'X-Proc-Method' => Proc.new { Time.now.to_i.to_s }, 'X-Proc-Method' => Proc.new { Time.now.to_i.to_s },
:subject => Proc.new { give_a_greeting } subject: Proc.new { give_a_greeting }
def welcome def welcome
mail mail

View File

@ -3,9 +3,9 @@ require 'abstract_unit'
class TestHelperMailer < ActionMailer::Base class TestHelperMailer < ActionMailer::Base
def test def test
@world = "Earth" @world = "Earth"
mail :body => render(:inline => "Hello, <%= @world %>"), mail body: render(inline: "Hello, <%= @world %>"),
:to => "test@example.com", to: "test@example.com",
:from => "tester@example.com" from: "tester@example.com"
end end
end end

View File

@ -19,9 +19,9 @@ class UrlTestMailer < ActionMailer::Base
def signed_up_with_url(recipient) def signed_up_with_url(recipient)
@recipient = recipient @recipient = recipient
@welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting" @welcome_url = url_for host: "example.com", controller: "welcome", action: "greeting"
mail(:to => recipient, :subject => "[Signed up] Welcome #{recipient}", mail(to: recipient, subject: "[Signed up] Welcome #{recipient}",
:from => "system@loudthinking.com", :date => Time.local(2004, 12, 12)) from: "system@loudthinking.com", date: Time.local(2004, 12, 12))
end end
end end
@ -58,7 +58,7 @@ class ActionMailerUrlTest < ActionMailer::TestCase
AppRoutes.draw do AppRoutes.draw do
get ':controller(/:action(/:id))' get ':controller(/:action(/:id))'
get '/welcome' => "foo#bar", :as => "welcome" get '/welcome' => "foo#bar", as: "welcome"
end end
expected = new_mail expected = new_mail