Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #7869 from Locke23rus/actionmailer_new_hash_syntax

Update actionmailer with new hash syntax.

Just to make clear we don't accept this kind of pull request because it can invalidate a lot of pull requests.

I'm accepting this because Action Mailer has only two open pull requests.
  • Loading branch information...
commit 221211088bc2a0421dc641355017d3ba78b25cc5 2 parents 918f703 + 96f290e
@rafaelfranca rafaelfranca authored
View
4 actionmailer/Rakefile
@@ -3,7 +3,7 @@ require 'rake/packagetask'
require 'rubygems/package_task'
desc "Default Task"
-task :default => [ :test ]
+task default: [ :test ]
# Run the unit tests
Rake::TestTask.new { |t|
@@ -29,7 +29,7 @@ Gem::PackageTask.new(spec) do |p|
end
desc "Release to gemcutter"
-task :release => :package do
+task release: :package do
require 'rake/gemcutter'
Rake::Gemcutter::Tasks.new(spec).define
Rake::Task['gem:push'].invoke
View
84 actionmailer/lib/action_mailer/base.rb
@@ -23,13 +23,13 @@ module ActionMailer
# Examples:
#
# class Notifier < ActionMailer::Base
- # default :from => 'no-reply@example.com',
- # :return_path => 'system@example.com'
+ # default from: 'no-reply@example.com',
+ # return_path: 'system@example.com'
#
# def welcome(recipient)
# @account = recipient
- # mail(:to => recipient.email_address_with_name,
- # :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"])
+ # mail(to: recipient.email_address_with_name,
+ # bcc: ["bcc@example.com", "Order Watcher <watcher@example.com>"])
# end
# end
#
@@ -62,21 +62,21 @@ module ActionMailer
#
# 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.html
# end
#
# 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.html
# end
#
# Or even to render a special view:
#
- # mail(:to => user.email) do |format|
+ # mail(to: user.email) do |format|
# format.text
# format.html { render "some_other_template" }
# end
@@ -100,12 +100,12 @@ module ActionMailer
# You can even use Action Pack helpers in these views. For example:
#
# 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:
#
# You got a new note from <%= message.from %>!
- # <%= truncate(@note.body, :length => 25) %>
+ # <%= truncate(@note.body, length: 25) %>
#
#
# = 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>:
#
- # <%= 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>:
#
- # <%= 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
# <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
# def welcome(recipient)
# 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
#
@@ -192,7 +192,7 @@ module ActionMailer
# class ApplicationMailer < ActionMailer::Base
# def welcome(recipient)
# 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
#
@@ -204,7 +204,7 @@ module ActionMailer
# class ApplicationMailer < ActionMailer::Base
# def welcome(recipient)
# 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
#
@@ -220,7 +220,7 @@ module ActionMailer
#
# <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
#
@@ -241,7 +241,7 @@ module ActionMailer
# default method inside the class definition:
#
# class Notifier < ActionMailer::Base
- # default :sender => 'system@example.com'
+ # default sender: 'system@example.com'
# end
#
# 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
# default 'Content-Transfer-Encoding' => '7bit',
- # :content_description => 'This is a description'
+ # content_description: 'This is a description'
# end
#
# Finally, Action Mailer also supports passing <tt>Proc</tt> objects into the default hash, so you
@@ -386,10 +386,10 @@ class Base < AbstractController::Base
class_attribute :default_params
self.default_params = {
- :mime_version => "1.0",
- :charset => "UTF-8",
- :content_type => "text/plain",
- :parts_order => [ "text/plain", "text/enriched", "text/html" ]
+ mime_version: "1.0",
+ charset: "UTF-8",
+ content_type: "text/plain",
+ parts_order: [ "text/plain", "text/enriched", "text/html" ]
}.freeze
class_attribute :queue
@@ -549,17 +549,17 @@ def headers(args=nil)
#
# 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',
- # :content => File.read('/path/to/filename.jpg')}
+ # mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
+ # content: File.read('/path/to/filename.jpg')}
#
# 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
# Mail to know how to decode this data:
#
# file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
- # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
- # :encoding => 'SpecialEncoding',
- # :content => file_content }
+ # mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
+ # encoding: 'SpecialEncoding',
+ # content: file_content }
#
# You can also search for specific attachments:
#
@@ -597,9 +597,9 @@ def attachments
# class method:
#
# class Notifier < ActionMailer::Base
- # self.default :from => 'no-reply@test.lindsaar.net',
- # :bcc => 'email_logger@test.lindsaar.net',
- # :reply_to => 'bounces@test.lindsaar.net'
+ # self.default from: 'no-reply@test.lindsaar.net',
+ # bcc: 'email_logger@test.lindsaar.net',
+ # reply_to: 'bounces@test.lindsaar.net'
# end
#
# If you need other headers not listed above, you can either pass them in
@@ -621,10 +621,10 @@ def attachments
# For example:
#
# class Notifier < ActionMailer::Base
- # default :from => 'no-reply@test.lindsaar.net',
+ # default from: 'no-reply@test.lindsaar.net',
#
# def welcome
- # mail(:to => 'mikel@test.lindsaar.net')
+ # mail(to: 'mikel@test.lindsaar.net')
# end
# end
#
@@ -633,22 +633,22 @@ def attachments
#
# 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".
#
# 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.html
# end
#
# You can even render text directly without using a template:
#
- # mail(:to => 'mikel@test.lindsaar.net') do |format|
- # format.text { render :text => "Hello Mikel!" }
- # format.html { render :text => "<h1>Hello Mikel!</h1>" }
+ # mail(to: 'mikel@test.lindsaar.net') do |format|
+ # format.text { render text: "Hello Mikel!" }
+ # format.html { render text: "<h1>Hello Mikel!</h1>" }
# end
#
# Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
@@ -657,7 +657,7 @@ def attachments
# The block syntax also allows you to customize the part headers if desired:
#
# mail(:to => 'mikel@test.lindsaar.net') do |format|
- # format.text(:content_transfer_encoding => "base64")
+ # format.text(content_transfer_encoding: "base64")
# format.html
# end
#
@@ -730,7 +730,7 @@ def set_content_type(m, user_content_type, class_default)
# humanized version of the <tt>action_name</tt>.
def default_i18n_subject #:nodoc:
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
def collect_responses_and_parts_order(headers) #:nodoc:
@@ -743,8 +743,8 @@ def collect_responses_and_parts_order(headers) #:nodoc:
responses = collector.responses
elsif headers[:body]
responses << {
- :body => headers.delete(:body),
- :content_type => self.class.default[:content_type] || "text/plain"
+ body: headers.delete(:body),
+ content_type: self.class.default[:content_type] || "text/plain"
}
else
templates_path = headers.delete(:template_path) || self.class.mailer_name
@@ -754,8 +754,8 @@ def collect_responses_and_parts_order(headers) #:nodoc:
self.formats = template.formats
responses << {
- :body => render(:template => template),
- :content_type => template.type.to_s
+ body: render(template: template),
+ content_type: template.type.to_s
}
end
end
View
2  actionmailer/lib/action_mailer/collector.rb
@@ -21,7 +21,7 @@ def any(*args, &block)
alias :all :any
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]
options[:body] = block_given? ? yield : @default_render.call
@responses << options
View
22 actionmailer/lib/action_mailer/delivery_methods.rb
@@ -20,27 +20,27 @@ module DeliveryMethods
self.delivery_method = :smtp
add_delivery_method :smtp, Mail::SMTP,
- :address => "localhost",
- :port => 25,
- :domain => 'localhost.localdomain',
- :user_name => nil,
- :password => nil,
- :authentication => nil,
- :enable_starttls_auto => true
+ address: "localhost",
+ port: 25,
+ domain: 'localhost.localdomain',
+ user_name: nil,
+ password: nil,
+ authentication: nil,
+ enable_starttls_auto: true
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,
- :location => '/usr/sbin/sendmail',
- :arguments => '-i -t'
+ location: '/usr/sbin/sendmail',
+ arguments: '-i -t'
add_delivery_method :test, Mail::TestMailer
end
module ClassMethods
# 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
# symbol as alias and the default options supplied.
View
2  actionmailer/lib/rails/generators/mailer/mailer_generator.rb
@@ -3,7 +3,7 @@ module Generators
class MailerGenerator < NamedBase
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
def create_mailer_file
View
6 actionmailer/test/asset_host_test.rb
@@ -3,9 +3,9 @@
class AssetHostMailer < ActionMailer::Base
def email_with_asset
- mail :to => 'test@localhost',
- :subject => 'testing email containing asset path while asset_host is set',
- :from => 'tester@example.com'
+ mail to: 'test@localhost',
+ subject: 'testing email containing asset path while asset_host is set',
+ from: 'tester@example.com'
end
end
View
64 actionmailer/test/base_test.rb
@@ -30,21 +30,21 @@ def teardown
end
test "mail() with from overwrites the class level default" do
- email = BaseMailer.welcome(:from => 'someone@example.com',
- :to => 'another@example.org')
+ email = BaseMailer.welcome(from: 'someone@example.com',
+ to: 'another@example.org')
assert_equal(['someone@example.com'], email.from)
assert_equal(['another@example.org'], email.to)
end
test "mail() with bcc, cc, content_type, charset, mime_version, reply_to and date" do
time = Time.now.beginning_of_day.to_datetime
- email = BaseMailer.welcome(:bcc => 'bcc@test.lindsaar.net',
- :cc => 'cc@test.lindsaar.net',
- :content_type => 'multipart/mixed',
- :charset => 'iso-8559-1',
- :mime_version => '2.0',
- :reply_to => 'reply-to@test.lindsaar.net',
- :date => time)
+ email = BaseMailer.welcome(bcc: 'bcc@test.lindsaar.net',
+ cc: 'cc@test.lindsaar.net',
+ content_type: 'multipart/mixed',
+ charset: 'iso-8559-1',
+ mime_version: '2.0',
+ reply_to: 'reply-to@test.lindsaar.net',
+ date: time)
assert_equal(['bcc@test.lindsaar.net'], email.bcc)
assert_equal(['cc@test.lindsaar.net'], email.cc)
assert_equal('multipart/mixed; charset=iso-8559-1', email.content_type)
@@ -60,7 +60,7 @@ def teardown
end
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("Hello there", email.body.encoded)
end
@@ -142,7 +142,7 @@ def teardown
end
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("multipart/mixed", email.mime_type)
assert_equal("text/plain", email.parts[0].mime_type)
@@ -165,31 +165,31 @@ def teardown
# Defaults values
test "uses default charset from class" do
- with_default BaseMailer, :charset => "US-ASCII" do
+ with_default BaseMailer, charset: "US-ASCII" do
email = BaseMailer.welcome
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)
end
end
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
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)
end
end
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
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)
end
end
@@ -202,17 +202,17 @@ def teardown
end
test "subject gets default from I18n" do
- BaseMailer.default :subject => nil
- email = BaseMailer.welcome(:subject => nil)
+ BaseMailer.default subject: nil
+ email = BaseMailer.welcome(subject: nil)
assert_equal "Welcome", email.subject
- I18n.backend.store_translations('en', :base_mailer => {:welcome => {:subject => "New Subject!"}})
- email = BaseMailer.welcome(:subject => nil)
+ I18n.backend.store_translations('en', base_mailer: {welcome: {subject: "New Subject!"}})
+ email = BaseMailer.welcome(subject: nil)
assert_equal "New Subject!", email.subject
end
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
assert_equal 'Hello lifo!', email.body.encoded
end
@@ -230,19 +230,19 @@ def teardown
test "implicit multipart with sort order" do
order = ["text/html", "text/plain"]
- with_default BaseMailer, :parts_order => order do
+ with_default BaseMailer, parts_order: order do
email = BaseMailer.implicit_multipart
assert_equal("text/html", email.parts[0].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/html", email.parts[1].mime_type)
end
end
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("multipart/alternative", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[0].mime_type)
@@ -253,8 +253,8 @@ def teardown
test "implicit multipart with attachments and sort order" do
order = ["text/html", "text/plain"]
- with_default BaseMailer, :parts_order => order do
- email = BaseMailer.implicit_multipart(:attachments => true)
+ with_default BaseMailer, parts_order: order do
+ email = BaseMailer.implicit_multipart(attachments: true)
assert_equal("application/pdf", email.parts[0].mime_type)
assert_equal("multipart/alternative", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[1].mime_type)
@@ -273,7 +273,7 @@ def teardown
end
test "implicit multipart with other locale" do
- swap I18n, :locale => :pl do
+ swap I18n, locale: :pl do
email = BaseMailer.implicit_with_locale
assert_equal(2, email.parts.size)
assert_equal("multipart/alternative", email.mime_type)
@@ -324,19 +324,19 @@ def teardown
test "explicit multipart does not sort order" do
order = ["text/html", "text/plain"]
- with_default BaseMailer, :parts_order => order do
+ with_default BaseMailer, parts_order: order do
email = BaseMailer.explicit_multipart
assert_equal("text/plain", email.parts[0].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/html", email.parts[1].mime_type)
end
end
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("multipart/alternative", email.parts[1].mime_type)
assert_equal("text/plain", email.parts[1].parts[0].mime_type)
@@ -651,7 +651,7 @@ def welcome
test "default_from can be set" do
class DefaultFromMailer < ActionMailer::Base
- default :to => 'system@test.lindsaar.net'
+ default to: 'system@test.lindsaar.net'
self.default_options = {from: "robert.pankowecki@gmail.com"}
def welcome
View
52 actionmailer/test/delivery_methods_test.rb
@@ -22,24 +22,24 @@ def deliver!(mail)
class DefaultsDeliveryMethodsTest < ActiveSupport::TestCase
test "default smtp settings" do
- settings = { :address => "localhost",
- :port => 25,
- :domain => 'localhost.localdomain',
- :user_name => nil,
- :password => nil,
- :authentication => nil,
- :enable_starttls_auto => true }
+ settings = { address: "localhost",
+ port: 25,
+ domain: 'localhost.localdomain',
+ user_name: nil,
+ password: nil,
+ authentication: nil,
+ enable_starttls_auto: true }
assert_equal settings, ActionMailer::Base.smtp_settings
end
test "default file delivery settings" do
- settings = {:location => "#{Dir.tmpdir}/mails"}
+ settings = {location: "#{Dir.tmpdir}/mails"}
assert_equal settings, ActionMailer::Base.file_settings
end
test "default sendmail settings" do
- settings = {:location => '/usr/sbin/sendmail',
- :arguments => '-i -t'}
+ settings = {location: '/usr/sbin/sendmail',
+ arguments: '-i -t'}
assert_equal settings, ActionMailer::Base.sendmail_settings
end
end
@@ -63,8 +63,8 @@ def teardown
end
test "allow to customize custom settings" do
- ActionMailer::Base.custom_settings = { :foo => :bar }
- assert_equal Hash[:foo => :bar], ActionMailer::Base.custom_settings
+ ActionMailer::Base.custom_settings = { foo: :bar }
+ assert_equal Hash[foo: :bar], ActionMailer::Base.custom_settings
end
test "respond to custom settings" do
@@ -82,8 +82,8 @@ def teardown
class MailDeliveryTest < ActiveSupport::TestCase
class DeliveryMailer < ActionMailer::Base
DEFAULT_HEADERS = {
- :to => 'mikel@test.lindsaar.net',
- :from => 'jose@test.plataformatec.com'
+ to: 'mikel@test.lindsaar.net',
+ from: 'jose@test.plataformatec.com'
}
def welcome(hash={})
@@ -110,7 +110,7 @@ def teardown
test "delivery method can be customized per instance" do
email = DeliveryMailer.welcome.deliver
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
end
@@ -125,7 +125,7 @@ def teardown
test "delivery method options default to class level options" do
default_options = {a: "b"}
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
end
@@ -133,21 +133,21 @@ def teardown
default_options = {a: "b"}
ActionMailer::Base.add_delivery_method :optioned, MyOptionedDelivery, default_options
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
end
test "default delivery options can be overridden per mail instance" do
- settings = { :address => "localhost",
- :port => 25,
- :domain => 'localhost.localdomain',
- :user_name => nil,
- :password => nil,
- :authentication => nil,
- :enable_starttls_auto => true }
+ settings = { address: "localhost",
+ port: 25,
+ domain: 'localhost.localdomain',
+ user_name: nil,
+ password: nil,
+ authentication: nil,
+ enable_starttls_auto: true }
assert_equal settings, ActionMailer::Base.smtp_settings
- overridden_options = {user_name: "overridden", :password => "somethingobtuse"}
- mail_instance = DeliveryMailer.welcome(:delivery_method_options => overridden_options)
+ overridden_options = {user_name: "overridden", password: "somethingobtuse"}
+ mail_instance = DeliveryMailer.welcome(delivery_method_options: overridden_options)
delivery_method_instance = mail_instance.delivery_method
assert_equal "overridden", delivery_method_instance.settings[:user_name]
assert_equal "somethingobtuse", delivery_method_instance.settings[:password]
View
8 actionmailer/test/i18n_with_controller_test.rb
@@ -9,15 +9,15 @@ class I18nTestMailer < ActionMailer::Base
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))
+ 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'
+ render text: 'Mail sent'
end
end
@@ -32,7 +32,7 @@ def app
end
def setup
- I18n.backend.store_translations('de', :email_subject => '[Signed up] Welcome')
+ I18n.backend.store_translations('de', email_subject: '[Signed up] Welcome')
end
def teardown
View
16 actionmailer/test/mail_helper_test.rb
@@ -10,7 +10,7 @@ def use_mail_helper
"it off!"
mail_with_defaults do |format|
- format.html { render(:inline => "<%= block_format @text %>") }
+ format.html { render(inline: "<%= block_format @text %>") }
end
end
@@ -18,7 +18,7 @@ def use_format_paragraph
@text = "But soft! What light through yonder window breaks?"
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
@@ -26,19 +26,19 @@ def use_format_paragraph_with_long_first_word
@text = "Antidisestablishmentarianism is very long."
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
def use_mailer
mail_with_defaults do |format|
- format.html { render(:inline => "<%= mailer.message.subject %>") }
+ format.html { render(inline: "<%= mailer.message.subject %>") }
end
end
def use_message
mail_with_defaults do |format|
- format.html { render(:inline => "<%= message.subject %>") }
+ format.html { render(inline: "<%= message.subject %>") }
end
end
@@ -55,15 +55,15 @@ def use_block_format
TEXT
mail_with_defaults do |format|
- format.html { render(:inline => "<%= block_format @text %>") }
+ format.html { render(inline: "<%= block_format @text %>") }
end
end
protected
def mail_with_defaults(&block)
- mail(:to => "test@localhost", :from => "tester@example.com",
- :subject => "using helpers", &block)
+ mail(to: "test@localhost", from: "tester@example.com",
+ subject: "using helpers", &block)
end
end
View
20 actionmailer/test/mail_layout_test.rb
@@ -1,9 +1,9 @@
require 'abstract_unit'
class AutoLayoutMailer < ActionMailer::Base
- default :to => 'test@localhost',
- :subject => "You have a mail",
- :from => "tester@example.com"
+ default to: 'test@localhost',
+ subject: "You have a mail",
+ from: "tester@example.com"
def hello
mail()
@@ -11,16 +11,16 @@ def hello
def spam
@world = "Earth"
- mail(:body => render(:inline => "Hello, <%= @world %>", :layout => 'spam'))
+ mail(body: render(inline: "Hello, <%= @world %>", layout: 'spam'))
end
def nolayout
@world = "Earth"
- mail(:body => render(:inline => "Hello, <%= @world %>", :layout => false))
+ mail(body: render(inline: "Hello, <%= @world %>", layout: false))
end
def multipart(type = nil)
- mail(:content_type => type) do |format|
+ mail(content_type: type) do |format|
format.text { render }
format.html { render }
end
@@ -28,11 +28,11 @@ def multipart(type = nil)
end
class ExplicitLayoutMailer < ActionMailer::Base
- layout 'spam', :except => [:logout]
+ layout 'spam', except: [:logout]
- default :to => 'test@localhost',
- :subject => "You have a mail",
- :from => "tester@example.com"
+ default to: 'test@localhost',
+ subject: "You have a mail",
+ from: "tester@example.com"
def signup
mail()
View
40 actionmailer/test/mailers/base_mailer.rb
@@ -1,13 +1,13 @@
class BaseMailer < ActionMailer::Base
self.mailer_name = "base_mailer"
- default :to => 'system@test.lindsaar.net',
- :from => 'jose@test.plataformatec.com',
- :reply_to => 'mikel@test.lindsaar.net'
+ default to: 'system@test.lindsaar.net',
+ from: 'jose@test.plataformatec.com',
+ reply_to: 'mikel@test.lindsaar.net'
def welcome(hash = {})
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
def welcome_with_headers(hash = {})
@@ -16,7 +16,7 @@ def welcome_with_headers(hash = {})
end
def welcome_from_another_path(path)
- mail(:template_name => "welcome", :template_path => path)
+ mail(template_name: "welcome", template_path: path)
end
def html_only(hash = {})
@@ -38,15 +38,15 @@ def attachment_with_content(hash = {})
end
def attachment_with_hash
- attachments['invoice.jpg'] = { :data => "\312\213\254\232)b",
- :mime_type => "image/x-jpg",
- :transfer_encoding => "base64" }
+ attachments['invoice.jpg'] = { data: "\312\213\254\232)b",
+ mime_type: "image/x-jpg",
+ transfer_encoding: "base64" }
mail
end
def attachment_with_hash_default_encoding
- attachments['invoice.jpg'] = { :data => "\312\213\254\232)b",
- :mime_type => "image/x-jpg" }
+ attachments['invoice.jpg'] = { data: "\312\213\254\232)b",
+ mime_type: "image/x-jpg" }
mail
end
@@ -62,8 +62,8 @@ def implicit_with_locale(hash = {})
def explicit_multipart(hash = {})
attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments)
mail(hash) do |format|
- format.text { render :text => "TEXT Explicit Multipart" }
- format.html { render :text => "HTML Explicit Multipart" }
+ format.text { render text: "TEXT Explicit Multipart" }
+ format.html { render text: "HTML Explicit Multipart" }
end
end
@@ -76,13 +76,13 @@ def explicit_multipart_templates(hash = {})
def explicit_multipart_with_any(hash = {})
mail(hash) do |format|
- format.any(:text, :html){ render :text => "Format with any!" }
+ format.any(:text, :html){ render text: "Format with any!" }
end
end
def explicit_multipart_with_options(include_html = false)
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
end
end
@@ -95,24 +95,24 @@ def explicit_multipart_with_one_template(hash = {})
end
def implicit_different_template(template_name='')
- mail(:template_name => template_name)
+ mail(template_name: template_name)
end
def explicit_different_template(template_name='')
mail do |format|
- format.text { render :template => "#{mailer_name}/#{template_name}" }
- format.html { render :template => "#{mailer_name}/#{template_name}" }
+ format.text { render template: "#{mailer_name}/#{template_name}" }
+ format.html { render template: "#{mailer_name}/#{template_name}" }
end
end
def different_layout(layout_name='')
mail do |format|
- format.text { render :layout => layout_name }
- format.html { render :layout => layout_name }
+ format.text { render layout: layout_name }
+ format.html { render layout: layout_name }
end
end
def email_with_translations
- mail :body => render("email_with_translations", :formats => [:html])
+ mail body: render("email_with_translations", formats: [:html])
end
end
View
4 actionmailer/test/mailers/proc_mailer.rb
@@ -1,7 +1,7 @@
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 },
- :subject => Proc.new { give_a_greeting }
+ subject: Proc.new { give_a_greeting }
def welcome
mail
View
6 actionmailer/test/test_helper_test.rb
@@ -3,9 +3,9 @@
class TestHelperMailer < ActionMailer::Base
def test
@world = "Earth"
- mail :body => render(:inline => "Hello, <%= @world %>"),
- :to => "test@example.com",
- :from => "tester@example.com"
+ mail body: render(inline: "Hello, <%= @world %>"),
+ to: "test@example.com",
+ from: "tester@example.com"
end
end
View
8 actionmailer/test/url_test.rb
@@ -19,9 +19,9 @@ class UrlTestMailer < ActionMailer::Base
def signed_up_with_url(recipient)
@recipient = recipient
- @welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
- mail(:to => recipient, :subject => "[Signed up] Welcome #{recipient}",
- :from => "system@loudthinking.com", :date => Time.local(2004, 12, 12))
+ @welcome_url = url_for host: "example.com", controller: "welcome", action: "greeting"
+ mail(to: recipient, subject: "[Signed up] Welcome #{recipient}",
+ from: "system@loudthinking.com", date: Time.local(2004, 12, 12))
end
end
@@ -58,7 +58,7 @@ def test_signed_up_with_url
AppRoutes.draw do
get ':controller(/:action(/:id))'
- get '/welcome' => "foo#bar", :as => "welcome"
+ get '/welcome' => "foo#bar", as: "welcome"
end
expected = new_mail
Please sign in to comment.
Something went wrong with that request. Please try again.