Skip to content
This repository
Browse code

Update actionmailer with new hash syntax.

  • Loading branch information...
commit 96f290eac03e1241fc1e57f119eaca72b682c5af 1 parent 918f703
Kirill Nikitin Locke23rus authored
4 actionmailer/Rakefile
@@ -3,7 +3,7 @@ require 'rake/packagetask'
3 3 require 'rubygems/package_task'
4 4
5 5 desc "Default Task"
6   -task :default => [ :test ]
  6 +task default: [ :test ]
7 7
8 8 # Run the unit tests
9 9 Rake::TestTask.new { |t|
@@ -29,7 +29,7 @@ Gem::PackageTask.new(spec) do |p|
29 29 end
30 30
31 31 desc "Release to gemcutter"
32   -task :release => :package do
  32 +task release: :package do
33 33 require 'rake/gemcutter'
34 34 Rake::Gemcutter::Tasks.new(spec).define
35 35 Rake::Task['gem:push'].invoke
84 actionmailer/lib/action_mailer/base.rb
@@ -23,13 +23,13 @@ module ActionMailer
23 23 # Examples:
24 24 #
25 25 # class Notifier < ActionMailer::Base
26   - # default :from => 'no-reply@example.com',
27   - # :return_path => 'system@example.com'
  26 + # default from: 'no-reply@example.com',
  27 + # return_path: 'system@example.com'
28 28 #
29 29 # def welcome(recipient)
30 30 # @account = recipient
31   - # mail(:to => recipient.email_address_with_name,
32   - # :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"])
  31 + # mail(to: recipient.email_address_with_name,
  32 + # bcc: ["bcc@example.com", "Order Watcher <watcher@example.com>"])
33 33 # end
34 34 # end
35 35 #
@@ -62,21 +62,21 @@ module ActionMailer
62 62 #
63 63 # If you want to explicitly render only certain templates, pass a block:
64 64 #
65   - # mail(:to => user.email) do |format|
  65 + # mail(to: user.email) do |format|
66 66 # format.text
67 67 # format.html
68 68 # end
69 69 #
70 70 # The block syntax is also useful in providing information specific to a part:
71 71 #
72   - # mail(:to => user.email) do |format|
  72 + # mail(to: user.email) do |format|
73 73 # format.text(:content_transfer_encoding => "base64")
74 74 # format.html
75 75 # end
76 76 #
77 77 # Or even to render a special view:
78 78 #
79   - # mail(:to => user.email) do |format|
  79 + # mail(to: user.email) do |format|
80 80 # format.text
81 81 # format.html { render "some_other_template" }
82 82 # end
@@ -100,12 +100,12 @@ module ActionMailer
100 100 # You can even use Action Pack helpers in these views. For example:
101 101 #
102 102 # You got a new note!
103   - # <%= truncate(@note.body, :length => 25) %>
  103 + # <%= truncate(@note.body, length: 25) %>
104 104 #
105 105 # If you need to access the subject, from or the recipients in the view, you can do that through message object:
106 106 #
107 107 # You got a new note from <%= message.from %>!
108   - # <%= truncate(@note.body, :length => 25) %>
  108 + # <%= truncate(@note.body, length: 25) %>
109 109 #
110 110 #
111 111 # = Generating URLs
@@ -116,11 +116,11 @@ module ActionMailer
116 116 #
117 117 # When using <tt>url_for</tt> you'll need to provide the <tt>:host</tt>, <tt>:controller</tt>, and <tt>:action</tt>:
118 118 #
119   - # <%= url_for(:host => "example.com", :controller => "welcome", :action => "greeting") %>
  119 + # <%= url_for(host: "example.com", controller: "welcome", action: "greeting") %>
120 120 #
121 121 # When using named routes you only need to supply the <tt>:host</tt>:
122 122 #
123   - # <%= users_url(:host => "example.com") %>
  123 + # <%= users_url(host: "example.com") %>
124 124 #
125 125 # You should use the <tt>named_route_url</tt> style (which generates absolute URLs) and avoid using the
126 126 # <tt>named_route_path</tt> style (which generates relative URLs), since clients reading the mail will
@@ -176,7 +176,7 @@ module ActionMailer
176 176 # class ApplicationMailer < ActionMailer::Base
177 177 # def welcome(recipient)
178 178 # attachments['free_book.pdf'] = File.read('path/to/file.pdf')
179   - # mail(:to => recipient, :subject => "New account information")
  179 + # mail(to: recipient, subject: "New account information")
180 180 # end
181 181 # end
182 182 #
@@ -192,7 +192,7 @@ module ActionMailer
192 192 # class ApplicationMailer < ActionMailer::Base
193 193 # def welcome(recipient)
194 194 # attachments['free_book.pdf'] = File.read('path/to/file.pdf')
195   - # mail(:to => recipient, :subject => "New account information", :body => "")
  195 + # mail(to: recipient, subject: "New account information", body: "")
196 196 # end
197 197 # end
198 198 #
@@ -204,7 +204,7 @@ module ActionMailer
204 204 # class ApplicationMailer < ActionMailer::Base
205 205 # def welcome(recipient)
206 206 # attachments.inline['photo.png'] = File.read('path/to/photo.png')
207   - # mail(:to => recipient, :subject => "Here is what we look like")
  207 + # mail(to: recipient, subject: "Here is what we look like")
208 208 # end
209 209 # end
210 210 #
@@ -220,7 +220,7 @@ module ActionMailer
220 220 #
221 221 # <h1>Please Don't Cringe</h1>
222 222 #
223   - # <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%>
  223 + # <%= image_tag attachments['photo.png'].url, alt: 'Our Photo', class: 'photo' -%>
224 224 #
225 225 # = Observing and Intercepting Mails
226 226 #
@@ -241,7 +241,7 @@ module ActionMailer
241 241 # default method inside the class definition:
242 242 #
243 243 # class Notifier < ActionMailer::Base
244   - # default :sender => 'system@example.com'
  244 + # default sender: 'system@example.com'
245 245 # end
246 246 #
247 247 # You can pass in any header value that a <tt>Mail::Message</tt> accepts. Out of the box,
@@ -260,7 +260,7 @@ module ActionMailer
260 260 #
261 261 # class Notifier < ActionMailer::Base
262 262 # default 'Content-Transfer-Encoding' => '7bit',
263   - # :content_description => 'This is a description'
  263 + # content_description: 'This is a description'
264 264 # end
265 265 #
266 266 # Finally, Action Mailer also supports passing <tt>Proc</tt> objects into the default hash, so you
@@ -386,10 +386,10 @@ class Base < AbstractController::Base
386 386
387 387 class_attribute :default_params
388 388 self.default_params = {
389   - :mime_version => "1.0",
390   - :charset => "UTF-8",
391   - :content_type => "text/plain",
392   - :parts_order => [ "text/plain", "text/enriched", "text/html" ]
  389 + mime_version: "1.0",
  390 + charset: "UTF-8",
  391 + content_type: "text/plain",
  392 + parts_order: [ "text/plain", "text/enriched", "text/html" ]
393 393 }.freeze
394 394
395 395 class_attribute :queue
@@ -549,17 +549,17 @@ def headers(args=nil)
549 549 #
550 550 # You can also specify overrides if you want by passing a hash instead of a string:
551 551 #
552   - # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
553   - # :content => File.read('/path/to/filename.jpg')}
  552 + # mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
  553 + # content: File.read('/path/to/filename.jpg')}
554 554 #
555 555 # If you want to use a different encoding than Base64, you can pass an encoding in,
556 556 # but then it is up to you to pass in the content pre-encoded, and don't expect
557 557 # Mail to know how to decode this data:
558 558 #
559 559 # file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
560   - # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
561   - # :encoding => 'SpecialEncoding',
562   - # :content => file_content }
  560 + # mail.attachments['filename.jpg'] = {mime_type: 'application/x-gzip',
  561 + # encoding: 'SpecialEncoding',
  562 + # content: file_content }
563 563 #
564 564 # You can also search for specific attachments:
565 565 #
@@ -597,9 +597,9 @@ def attachments
597 597 # class method:
598 598 #
599 599 # class Notifier < ActionMailer::Base
600   - # self.default :from => 'no-reply@test.lindsaar.net',
601   - # :bcc => 'email_logger@test.lindsaar.net',
602   - # :reply_to => 'bounces@test.lindsaar.net'
  600 + # self.default from: 'no-reply@test.lindsaar.net',
  601 + # bcc: 'email_logger@test.lindsaar.net',
  602 + # reply_to: 'bounces@test.lindsaar.net'
603 603 # end
604 604 #
605 605 # If you need other headers not listed above, you can either pass them in
@@ -621,10 +621,10 @@ def attachments
621 621 # For example:
622 622 #
623 623 # class Notifier < ActionMailer::Base
624   - # default :from => 'no-reply@test.lindsaar.net',
  624 + # default from: 'no-reply@test.lindsaar.net',
625 625 #
626 626 # def welcome
627   - # mail(:to => 'mikel@test.lindsaar.net')
  627 + # mail(to: 'mikel@test.lindsaar.net')
628 628 # end
629 629 # end
630 630 #
@@ -633,22 +633,22 @@ def attachments
633 633 #
634 634 # However, those can be customized:
635 635 #
636   - # mail(:template_path => 'notifications', :template_name => 'another')
  636 + # mail(template_path: 'notifications', template_name: 'another')
637 637 #
638 638 # And now it will look for all templates at "app/views/notifications" with name "another".
639 639 #
640 640 # If you do pass a block, you can render specific templates of your choice:
641 641 #
642   - # mail(:to => 'mikel@test.lindsaar.net') do |format|
  642 + # mail(to: 'mikel@test.lindsaar.net') do |format|
643 643 # format.text
644 644 # format.html
645 645 # end
646 646 #
647 647 # You can even render text directly without using a template:
648 648 #
649   - # mail(:to => 'mikel@test.lindsaar.net') do |format|
650   - # format.text { render :text => "Hello Mikel!" }
651   - # format.html { render :text => "<h1>Hello Mikel!</h1>" }
  649 + # mail(to: 'mikel@test.lindsaar.net') do |format|
  650 + # format.text { render text: "Hello Mikel!" }
  651 + # format.html { render text: "<h1>Hello Mikel!</h1>" }
652 652 # end
653 653 #
654 654 # Which will render a <tt>multipart/alternative</tt> email with <tt>text/plain</tt> and
@@ -657,7 +657,7 @@ def attachments
657 657 # The block syntax also allows you to customize the part headers if desired:
658 658 #
659 659 # mail(:to => 'mikel@test.lindsaar.net') do |format|
660   - # format.text(:content_transfer_encoding => "base64")
  660 + # format.text(content_transfer_encoding: "base64")
661 661 # format.html
662 662 # end
663 663 #
@@ -730,7 +730,7 @@ def set_content_type(m, user_content_type, class_default)
730 730 # humanized version of the <tt>action_name</tt>.
731 731 def default_i18n_subject #:nodoc:
732 732 mailer_scope = self.class.mailer_name.tr('/', '.')
733   - I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize)
  733 + I18n.t(:subject, scope: [mailer_scope, action_name], default: action_name.humanize)
734 734 end
735 735
736 736 def collect_responses_and_parts_order(headers) #:nodoc:
@@ -743,8 +743,8 @@ def collect_responses_and_parts_order(headers) #:nodoc:
743 743 responses = collector.responses
744 744 elsif headers[:body]
745 745 responses << {
746   - :body => headers.delete(:body),
747   - :content_type => self.class.default[:content_type] || "text/plain"
  746 + body: headers.delete(:body),
  747 + content_type: self.class.default[:content_type] || "text/plain"
748 748 }
749 749 else
750 750 templates_path = headers.delete(:template_path) || self.class.mailer_name
@@ -754,8 +754,8 @@ def collect_responses_and_parts_order(headers) #:nodoc:
754 754 self.formats = template.formats
755 755
756 756 responses << {
757   - :body => render(:template => template),
758   - :content_type => template.type.to_s
  757 + body: render(template: template),
  758 + content_type: template.type.to_s
759 759 }
760 760 end
761 761 end
2  actionmailer/lib/action_mailer/collector.rb
@@ -21,7 +21,7 @@ def any(*args, &block)
21 21 alias :all :any
22 22
23 23 def custom(mime, options={})
24   - options.reverse_merge!(:content_type => mime.to_s)
  24 + options.reverse_merge!(content_type: mime.to_s)
25 25 @context.formats = [mime.to_sym]
26 26 options[:body] = block_given? ? yield : @default_render.call
27 27 @responses << options
22 actionmailer/lib/action_mailer/delivery_methods.rb
@@ -20,27 +20,27 @@ module DeliveryMethods
20 20 self.delivery_method = :smtp
21 21
22 22 add_delivery_method :smtp, Mail::SMTP,
23   - :address => "localhost",
24   - :port => 25,
25   - :domain => 'localhost.localdomain',
26   - :user_name => nil,
27   - :password => nil,
28   - :authentication => nil,
29   - :enable_starttls_auto => true
  23 + address: "localhost",
  24 + port: 25,
  25 + domain: 'localhost.localdomain',
  26 + user_name: nil,
  27 + password: nil,
  28 + authentication: nil,
  29 + enable_starttls_auto: true
30 30
31 31 add_delivery_method :file, Mail::FileDelivery,
32   - :location => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
  32 + location: defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
33 33
34 34 add_delivery_method :sendmail, Mail::Sendmail,
35   - :location => '/usr/sbin/sendmail',
36   - :arguments => '-i -t'
  35 + location: '/usr/sbin/sendmail',
  36 + arguments: '-i -t'
37 37
38 38 add_delivery_method :test, Mail::TestMailer
39 39 end
40 40
41 41 module ClassMethods
42 42 # Provides a list of emails that have been delivered by Mail::TestMailer
43   - delegate :deliveries, :deliveries=, :to => Mail::TestMailer
  43 + delegate :deliveries, :deliveries=, to: Mail::TestMailer
44 44
45 45 # Adds a new delivery method through the given class using the given
46 46 # symbol as alias and the default options supplied.
2  actionmailer/lib/rails/generators/mailer/mailer_generator.rb
@@ -3,7 +3,7 @@ module Generators
3 3 class MailerGenerator < NamedBase
4 4 source_root File.expand_path("../templates", __FILE__)
5 5
6   - argument :actions, :type => :array, :default => [], :banner => "method method"
  6 + argument :actions, type: :array, default: [], banner: "method method"
7 7 check_class_collision
8 8
9 9 def create_mailer_file
6 actionmailer/test/asset_host_test.rb
@@ -3,9 +3,9 @@
3 3
4 4 class AssetHostMailer < ActionMailer::Base
5 5 def email_with_asset
6   - mail :to => 'test@localhost',
7   - :subject => 'testing email containing asset path while asset_host is set',
8   - :from => 'tester@example.com'
  6 + mail to: 'test@localhost',
  7 + subject: 'testing email containing asset path while asset_host is set',
  8 + from: 'tester@example.com'
9 9 end
10 10 end
11 11
64 actionmailer/test/base_test.rb
@@ -30,21 +30,21 @@ def teardown
30 30 end
31 31
32 32 test "mail() with from overwrites the class level default" do
33   - email = BaseMailer.welcome(:from => 'someone@example.com',
34   - :to => 'another@example.org')
  33 + email = BaseMailer.welcome(from: 'someone@example.com',
  34 + to: 'another@example.org')
35 35 assert_equal(['someone@example.com'], email.from)
36 36 assert_equal(['another@example.org'], email.to)
37 37 end
38 38
39 39 test "mail() with bcc, cc, content_type, charset, mime_version, reply_to and date" do
40 40 time = Time.now.beginning_of_day.to_datetime
41   - email = BaseMailer.welcome(:bcc => 'bcc@test.lindsaar.net',
42   - :cc => 'cc@test.lindsaar.net',
43   - :content_type => 'multipart/mixed',
44   - :charset => 'iso-8559-1',
45   - :mime_version => '2.0',
46   - :reply_to => 'reply-to@test.lindsaar.net',
47   - :date => time)
  41 + email = BaseMailer.welcome(bcc: 'bcc@test.lindsaar.net',
  42 + cc: 'cc@test.lindsaar.net',
  43 + content_type: 'multipart/mixed',
  44 + charset: 'iso-8559-1',
  45 + mime_version: '2.0',
  46 + reply_to: 'reply-to@test.lindsaar.net',
  47 + date: time)
48 48 assert_equal(['bcc@test.lindsaar.net'], email.bcc)
49 49 assert_equal(['cc@test.lindsaar.net'], email.cc)
50 50 assert_equal('multipart/mixed; charset=iso-8559-1', email.content_type)
@@ -60,7 +60,7 @@ def teardown
60 60 end
61 61
62 62 test "can pass in :body to the mail method hash" do
63   - email = BaseMailer.welcome(:body => "Hello there")
  63 + email = BaseMailer.welcome(body: "Hello there")
64 64 assert_equal("text/plain", email.mime_type)
65 65 assert_equal("Hello there", email.body.encoded)
66 66 end
@@ -142,7 +142,7 @@ def teardown
142 142 end
143 143
144 144 test "adds the given :body as part" do
145   - email = BaseMailer.attachment_with_content(:body => "I'm the eggman")
  145 + email = BaseMailer.attachment_with_content(body: "I'm the eggman")
146 146 assert_equal(2, email.parts.length)
147 147 assert_equal("multipart/mixed", email.mime_type)
148 148 assert_equal("text/plain", email.parts[0].mime_type)
@@ -165,31 +165,31 @@ def teardown
165 165
166 166 # Defaults values
167 167 test "uses default charset from class" do
168   - with_default BaseMailer, :charset => "US-ASCII" do
  168 + with_default BaseMailer, charset: "US-ASCII" do
169 169 email = BaseMailer.welcome
170 170 assert_equal("US-ASCII", email.charset)
171 171
172   - email = BaseMailer.welcome(:charset => "iso-8559-1")
  172 + email = BaseMailer.welcome(charset: "iso-8559-1")
173 173 assert_equal("iso-8559-1", email.charset)
174 174 end
175 175 end
176 176
177 177 test "uses default content type from class" do
178   - with_default BaseMailer, :content_type => "text/html" do
  178 + with_default BaseMailer, content_type: "text/html" do
179 179 email = BaseMailer.welcome
180 180 assert_equal("text/html", email.mime_type)
181 181
182   - email = BaseMailer.welcome(:content_type => "text/plain")
  182 + email = BaseMailer.welcome(content_type: "text/plain")
183 183 assert_equal("text/plain", email.mime_type)
184 184 end
185 185 end
186 186
187 187 test "uses default mime version from class" do
188   - with_default BaseMailer, :mime_version => "2.0" do
  188 + with_default BaseMailer, mime_version: "2.0" do
189 189 email = BaseMailer.welcome
190 190 assert_equal("2.0", email.mime_version)
191 191
192   - email = BaseMailer.welcome(:mime_version => "1.0")
  192 + email = BaseMailer.welcome(mime_version: "1.0")
193 193 assert_equal("1.0", email.mime_version)
194 194 end
195 195 end
@@ -202,17 +202,17 @@ def teardown
202 202 end
203 203
204 204 test "subject gets default from I18n" do
205   - BaseMailer.default :subject => nil
206   - email = BaseMailer.welcome(:subject => nil)
  205 + BaseMailer.default subject: nil
  206 + email = BaseMailer.welcome(subject: nil)
207 207 assert_equal "Welcome", email.subject
208 208
209   - I18n.backend.store_translations('en', :base_mailer => {:welcome => {:subject => "New Subject!"}})
210   - email = BaseMailer.welcome(:subject => nil)
  209 + I18n.backend.store_translations('en', base_mailer: {welcome: {subject: "New Subject!"}})
  210 + email = BaseMailer.welcome(subject: nil)
211 211 assert_equal "New Subject!", email.subject
212 212 end
213 213
214 214 test "translations are scoped properly" do
215   - I18n.backend.store_translations('en', :base_mailer => {:email_with_translations => {:greet_user => "Hello %{name}!"}})
  215 + I18n.backend.store_translations('en', base_mailer: {email_with_translations: {greet_user: "Hello %{name}!"}})
216 216 email = BaseMailer.email_with_translations
217 217 assert_equal 'Hello lifo!', email.body.encoded
218 218 end
@@ -230,19 +230,19 @@ def teardown
230 230
231 231 test "implicit multipart with sort order" do
232 232 order = ["text/html", "text/plain"]
233   - with_default BaseMailer, :parts_order => order do
  233 + with_default BaseMailer, parts_order: order do
234 234 email = BaseMailer.implicit_multipart
235 235 assert_equal("text/html", email.parts[0].mime_type)
236 236 assert_equal("text/plain", email.parts[1].mime_type)
237 237
238   - email = BaseMailer.implicit_multipart(:parts_order => order.reverse)
  238 + email = BaseMailer.implicit_multipart(parts_order: order.reverse)
239 239 assert_equal("text/plain", email.parts[0].mime_type)
240 240 assert_equal("text/html", email.parts[1].mime_type)
241 241 end
242 242 end
243 243
244 244 test "implicit multipart with attachments creates nested parts" do
245   - email = BaseMailer.implicit_multipart(:attachments => true)
  245 + email = BaseMailer.implicit_multipart(attachments: true)
246 246 assert_equal("application/pdf", email.parts[0].mime_type)
247 247 assert_equal("multipart/alternative", email.parts[1].mime_type)
248 248 assert_equal("text/plain", email.parts[1].parts[0].mime_type)
@@ -253,8 +253,8 @@ def teardown
253 253
254 254 test "implicit multipart with attachments and sort order" do
255 255 order = ["text/html", "text/plain"]
256   - with_default BaseMailer, :parts_order => order do
257   - email = BaseMailer.implicit_multipart(:attachments => true)
  256 + with_default BaseMailer, parts_order: order do
  257 + email = BaseMailer.implicit_multipart(attachments: true)
258 258 assert_equal("application/pdf", email.parts[0].mime_type)
259 259 assert_equal("multipart/alternative", email.parts[1].mime_type)
260 260 assert_equal("text/plain", email.parts[1].parts[1].mime_type)
@@ -273,7 +273,7 @@ def teardown
273 273 end
274 274
275 275 test "implicit multipart with other locale" do
276   - swap I18n, :locale => :pl do
  276 + swap I18n, locale: :pl do
277 277 email = BaseMailer.implicit_with_locale
278 278 assert_equal(2, email.parts.size)
279 279 assert_equal("multipart/alternative", email.mime_type)
@@ -324,19 +324,19 @@ def teardown
324 324
325 325 test "explicit multipart does not sort order" do
326 326 order = ["text/html", "text/plain"]
327   - with_default BaseMailer, :parts_order => order do
  327 + with_default BaseMailer, parts_order: order do
328 328 email = BaseMailer.explicit_multipart
329 329 assert_equal("text/plain", email.parts[0].mime_type)
330 330 assert_equal("text/html", email.parts[1].mime_type)
331 331
332   - email = BaseMailer.explicit_multipart(:parts_order => order.reverse)
  332 + email = BaseMailer.explicit_multipart(parts_order: order.reverse)
333 333 assert_equal("text/plain", email.parts[0].mime_type)
334 334 assert_equal("text/html", email.parts[1].mime_type)
335 335 end
336 336 end
337 337
338 338 test "explicit multipart with attachments creates nested parts" do
339   - email = BaseMailer.explicit_multipart(:attachments => true)
  339 + email = BaseMailer.explicit_multipart(attachments: true)
340 340 assert_equal("application/pdf", email.parts[0].mime_type)
341 341 assert_equal("multipart/alternative", email.parts[1].mime_type)
342 342 assert_equal("text/plain", email.parts[1].parts[0].mime_type)
@@ -651,7 +651,7 @@ def welcome
651 651
652 652 test "default_from can be set" do
653 653 class DefaultFromMailer < ActionMailer::Base
654   - default :to => 'system@test.lindsaar.net'
  654 + default to: 'system@test.lindsaar.net'
655 655 self.default_options = {from: "robert.pankowecki@gmail.com"}
656 656
657 657 def welcome
52 actionmailer/test/delivery_methods_test.rb
@@ -22,24 +22,24 @@ def deliver!(mail)
22 22
23 23 class DefaultsDeliveryMethodsTest < ActiveSupport::TestCase
24 24 test "default smtp settings" do
25   - settings = { :address => "localhost",
26   - :port => 25,
27   - :domain => 'localhost.localdomain',
28   - :user_name => nil,
29   - :password => nil,
30   - :authentication => nil,
31   - :enable_starttls_auto => true }
  25 + settings = { address: "localhost",
  26 + port: 25,
  27 + domain: 'localhost.localdomain',
  28 + user_name: nil,
  29 + password: nil,
  30 + authentication: nil,
  31 + enable_starttls_auto: true }
32 32 assert_equal settings, ActionMailer::Base.smtp_settings
33 33 end
34 34
35 35 test "default file delivery settings" do
36   - settings = {:location => "#{Dir.tmpdir}/mails"}
  36 + settings = {location: "#{Dir.tmpdir}/mails"}
37 37 assert_equal settings, ActionMailer::Base.file_settings
38 38 end
39 39
40 40 test "default sendmail settings" do
41   - settings = {:location => '/usr/sbin/sendmail',
42   - :arguments => '-i -t'}
  41 + settings = {location: '/usr/sbin/sendmail',
  42 + arguments: '-i -t'}
43 43 assert_equal settings, ActionMailer::Base.sendmail_settings
44 44 end
45 45 end
@@ -63,8 +63,8 @@ def teardown
63 63 end
64 64
65 65 test "allow to customize custom settings" do
66   - ActionMailer::Base.custom_settings = { :foo => :bar }
67   - assert_equal Hash[:foo => :bar], ActionMailer::Base.custom_settings
  66 + ActionMailer::Base.custom_settings = { foo: :bar }
  67 + assert_equal Hash[foo: :bar], ActionMailer::Base.custom_settings
68 68 end
69 69
70 70 test "respond to custom settings" do
@@ -82,8 +82,8 @@ def teardown
82 82 class MailDeliveryTest < ActiveSupport::TestCase
83 83 class DeliveryMailer < ActionMailer::Base
84 84 DEFAULT_HEADERS = {
85   - :to => 'mikel@test.lindsaar.net',
86   - :from => 'jose@test.plataformatec.com'
  85 + to: 'mikel@test.lindsaar.net',
  86 + from: 'jose@test.plataformatec.com'
87 87 }
88 88
89 89 def welcome(hash={})
@@ -110,7 +110,7 @@ def teardown
110 110 test "delivery method can be customized per instance" do
111 111 email = DeliveryMailer.welcome.deliver
112 112 assert_instance_of Mail::SMTP, email.delivery_method
113   - email = DeliveryMailer.welcome(:delivery_method => :test).deliver
  113 + email = DeliveryMailer.welcome(delivery_method: :test).deliver
114 114 assert_instance_of Mail::TestMailer, email.delivery_method
115 115 end
116 116
@@ -125,7 +125,7 @@ def teardown
125 125 test "delivery method options default to class level options" do
126 126 default_options = {a: "b"}
127 127 ActionMailer::Base.add_delivery_method :optioned, MyOptionedDelivery, default_options
128   - mail_instance = DeliveryMailer.welcome(:delivery_method => :optioned)
  128 + mail_instance = DeliveryMailer.welcome(delivery_method: :optioned)
129 129 assert_equal default_options, mail_instance.delivery_method.options
130 130 end
131 131
@@ -133,21 +133,21 @@ def teardown
133 133 default_options = {a: "b"}
134 134 ActionMailer::Base.add_delivery_method :optioned, MyOptionedDelivery, default_options
135 135 overridden_options = {a: "a"}
136   - mail_instance = DeliveryMailer.welcome(:delivery_method => :optioned, :delivery_method_options => overridden_options)
  136 + mail_instance = DeliveryMailer.welcome(delivery_method: :optioned, delivery_method_options: overridden_options)
137 137 assert_equal overridden_options, mail_instance.delivery_method.options
138 138 end
139 139
140 140 test "default delivery options can be overridden per mail instance" do
141   - settings = { :address => "localhost",
142   - :port => 25,
143   - :domain => 'localhost.localdomain',
144   - :user_name => nil,
145   - :password => nil,
146   - :authentication => nil,
147   - :enable_starttls_auto => true }
  141 + settings = { address: "localhost",
  142 + port: 25,
  143 + domain: 'localhost.localdomain',
  144 + user_name: nil,
  145 + password: nil,
  146 + authentication: nil,
  147 + enable_starttls_auto: true }
148 148 assert_equal settings, ActionMailer::Base.smtp_settings
149   - overridden_options = {user_name: "overridden", :password => "somethingobtuse"}
150   - mail_instance = DeliveryMailer.welcome(:delivery_method_options => overridden_options)
  149 + overridden_options = {user_name: "overridden", password: "somethingobtuse"}
  150 + mail_instance = DeliveryMailer.welcome(delivery_method_options: overridden_options)
151 151 delivery_method_instance = mail_instance.delivery_method
152 152 assert_equal "overridden", delivery_method_instance.settings[:user_name]
153 153 assert_equal "somethingobtuse", delivery_method_instance.settings[:password]
8 actionmailer/test/i18n_with_controller_test.rb
@@ -9,15 +9,15 @@ class I18nTestMailer < ActionMailer::Base
9 9 def mail_with_i18n_subject(recipient)
10 10 @recipient = recipient
11 11 I18n.locale = :de
12   - mail(:to => recipient, :subject => "#{I18n.t :email_subject} #{recipient}",
13   - :from => "system@loudthinking.com", :date => Time.local(2004, 12, 12))
  12 + mail(to: recipient, subject: "#{I18n.t :email_subject} #{recipient}",
  13 + from: "system@loudthinking.com", date: Time.local(2004, 12, 12))
14 14 end
15 15 end
16 16
17 17 class TestController < ActionController::Base
18 18 def send_mail
19 19 I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver
20   - render :text => 'Mail sent'
  20 + render text: 'Mail sent'
21 21 end
22 22 end
23 23
@@ -32,7 +32,7 @@ def app
32 32 end
33 33
34 34 def setup
35   - I18n.backend.store_translations('de', :email_subject => '[Signed up] Welcome')
  35 + I18n.backend.store_translations('de', email_subject: '[Signed up] Welcome')
36 36 end
37 37
38 38 def teardown
16 actionmailer/test/mail_helper_test.rb
@@ -10,7 +10,7 @@ def use_mail_helper
10 10 "it off!"
11 11
12 12 mail_with_defaults do |format|
13   - format.html { render(:inline => "<%= block_format @text %>") }
  13 + format.html { render(inline: "<%= block_format @text %>") }
14 14 end
15 15 end
16 16
@@ -18,7 +18,7 @@ def use_format_paragraph
18 18 @text = "But soft! What light through yonder window breaks?"
19 19
20 20 mail_with_defaults do |format|
21   - format.html { render(:inline => "<%= format_paragraph @text, 15, 1 %>") }
  21 + format.html { render(inline: "<%= format_paragraph @text, 15, 1 %>") }
22 22 end
23 23 end
24 24
@@ -26,19 +26,19 @@ def use_format_paragraph_with_long_first_word
26 26 @text = "Antidisestablishmentarianism is very long."
27 27
28 28 mail_with_defaults do |format|
29   - format.html { render(:inline => "<%= format_paragraph @text, 10, 1 %>") }
  29 + format.html { render(inline: "<%= format_paragraph @text, 10, 1 %>") }
30 30 end
31 31 end
32 32
33 33 def use_mailer
34 34 mail_with_defaults do |format|
35   - format.html { render(:inline => "<%= mailer.message.subject %>") }
  35 + format.html { render(inline: "<%= mailer.message.subject %>") }
36 36 end
37 37 end
38 38
39 39 def use_message
40 40 mail_with_defaults do |format|
41   - format.html { render(:inline => "<%= message.subject %>") }
  41 + format.html { render(inline: "<%= message.subject %>") }
42 42 end
43 43 end
44 44
@@ -55,15 +55,15 @@ def use_block_format
55 55 TEXT
56 56
57 57 mail_with_defaults do |format|
58   - format.html { render(:inline => "<%= block_format @text %>") }
  58 + format.html { render(inline: "<%= block_format @text %>") }
59 59 end
60 60 end
61 61
62 62 protected
63 63
64 64 def mail_with_defaults(&block)
65   - mail(:to => "test@localhost", :from => "tester@example.com",
66   - :subject => "using helpers", &block)
  65 + mail(to: "test@localhost", from: "tester@example.com",
  66 + subject: "using helpers", &block)
67 67 end
68 68 end
69 69
20 actionmailer/test/mail_layout_test.rb
... ... @@ -1,9 +1,9 @@
1 1 require 'abstract_unit'
2 2
3 3 class AutoLayoutMailer < ActionMailer::Base
4   - default :to => 'test@localhost',
5   - :subject => "You have a mail",
6   - :from => "tester@example.com"
  4 + default to: 'test@localhost',
  5 + subject: "You have a mail",
  6 + from: "tester@example.com"
7 7
8 8 def hello
9 9 mail()
@@ -11,16 +11,16 @@ def hello
11 11
12 12 def spam
13 13 @world = "Earth"
14   - mail(:body => render(:inline => "Hello, <%= @world %>", :layout => 'spam'))
  14 + mail(body: render(inline: "Hello, <%= @world %>", layout: 'spam'))
15 15 end
16 16
17 17 def nolayout
18 18 @world = "Earth"
19   - mail(:body => render(:inline => "Hello, <%= @world %>", :layout => false))
  19 + mail(body: render(inline: "Hello, <%= @world %>", layout: false))
20 20 end
21 21
22 22 def multipart(type = nil)
23   - mail(:content_type => type) do |format|
  23 + mail(content_type: type) do |format|
24 24 format.text { render }
25 25 format.html { render }
26 26 end
@@ -28,11 +28,11 @@ def multipart(type = nil)
28 28 end
29 29
30 30 class ExplicitLayoutMailer < ActionMailer::Base
31   - layout 'spam', :except => [:logout]
  31 + layout 'spam', except: [:logout]
32 32
33   - default :to => 'test@localhost',
34   - :subject => "You have a mail",
35   - :from => "tester@example.com"
  33 + default to: 'test@localhost',
  34 + subject: "You have a mail",
  35 + from: "tester@example.com"
36 36
37 37 def signup
38 38 mail()
40 actionmailer/test/mailers/base_mailer.rb
... ... @@ -1,13 +1,13 @@
1 1 class BaseMailer < ActionMailer::Base
2 2 self.mailer_name = "base_mailer"
3 3
4   - default :to => 'system@test.lindsaar.net',
5   - :from => 'jose@test.plataformatec.com',
6   - :reply_to => 'mikel@test.lindsaar.net'
  4 + default to: 'system@test.lindsaar.net',
  5 + from: 'jose@test.plataformatec.com',
  6 + reply_to: 'mikel@test.lindsaar.net'
7 7
8 8 def welcome(hash = {})
9 9 headers['X-SPAM'] = "Not SPAM"
10   - mail({:subject => "The first email on new API!"}.merge!(hash))
  10 + mail({subject: "The first email on new API!"}.merge!(hash))
11 11 end
12 12
13 13 def welcome_with_headers(hash = {})
@@ -16,7 +16,7 @@ def welcome_with_headers(hash = {})
16 16 end
17 17
18 18 def welcome_from_another_path(path)
19   - mail(:template_name => "welcome", :template_path => path)
  19 + mail(template_name: "welcome", template_path: path)
20 20 end
21 21
22 22 def html_only(hash = {})
@@ -38,15 +38,15 @@ def attachment_with_content(hash = {})
38 38 end
39 39
40 40 def attachment_with_hash
41   - attachments['invoice.jpg'] = { :data => "\312\213\254\232)b",
42   - :mime_type => "image/x-jpg",
43   - :transfer_encoding => "base64" }
  41 + attachments['invoice.jpg'] = { data: "\312\213\254\232)b",
  42 + mime_type: "image/x-jpg",
  43 + transfer_encoding: "base64" }
44 44 mail
45 45 end
46 46
47 47 def attachment_with_hash_default_encoding
48   - attachments['invoice.jpg'] = { :data => "\312\213\254\232)b",
49   - :mime_type => "image/x-jpg" }
  48 + attachments['invoice.jpg'] = { data: "\312\213\254\232)b",
  49 + mime_type: "image/x-jpg" }
50 50 mail
51 51 end
52 52
@@ -62,8 +62,8 @@ def implicit_with_locale(hash = {})
62 62 def explicit_multipart(hash = {})
63 63 attachments['invoice.pdf'] = 'This is test File content' if hash.delete(:attachments)
64 64 mail(hash) do |format|
65   - format.text { render :text => "TEXT Explicit Multipart" }
66   - format.html { render :text => "HTML Explicit Multipart" }
  65 + format.text { render text: "TEXT Explicit Multipart" }
  66 + format.html { render text: "HTML Explicit Multipart" }
67 67 end
68 68 end
69 69
@@ -76,13 +76,13 @@ def explicit_multipart_templates(hash = {})
76 76
77 77 def explicit_multipart_with_any(hash = {})
78 78 mail(hash) do |format|
79   - format.any(:text, :html){ render :text => "Format with any!" }
  79 + format.any(:text, :html){ render text: "Format with any!" }
80 80 end
81 81 end
82 82
83 83 def explicit_multipart_with_options(include_html = false)
84 84 mail do |format|
85   - format.text(:content_transfer_encoding => "base64"){ render "welcome" }
  85 + format.text(content_transfer_encoding: "base64"){ render "welcome" }
86 86 format.html{ render "welcome" } if include_html
87 87 end
88 88 end
@@ -95,24 +95,24 @@ def explicit_multipart_with_one_template(hash = {})
95 95 end
96 96
97 97 def implicit_different_template(template_name='')
98   - mail(:template_name => template_name)
  98 + mail(template_name: template_name)
99 99 end
100 100
101 101 def explicit_different_template(template_name='')
102 102 mail do |format|
103   - format.text { render :template => "#{mailer_name}/#{template_name}" }
104   - format.html { render :template => "#{mailer_name}/#{template_name}" }
  103 + format.text { render template: "#{mailer_name}/#{template_name}" }
  104 + format.html { render template: "#{mailer_name}/#{template_name}" }
105 105 end
106 106 end
107 107
108 108 def different_layout(layout_name='')
109 109 mail do |format|
110   - format.text { render :layout => layout_name }
111   - format.html { render :layout => layout_name }
  110 + format.text { render layout: layout_name }
  111 + format.html { render layout: layout_name }
112 112 end
113 113 end
114 114
115 115 def email_with_translations
116   - mail :body => render("email_with_translations", :formats => [:html])
  116 + mail body: render("email_with_translations", formats: [:html])
117 117 end
118 118 end
4 actionmailer/test/mailers/proc_mailer.rb
... ... @@ -1,7 +1,7 @@
1 1 class ProcMailer < ActionMailer::Base
2   - default :to => 'system@test.lindsaar.net',
  2 + default to: 'system@test.lindsaar.net',
3 3 'X-Proc-Method' => Proc.new { Time.now.to_i.to_s },
4   - :subject => Proc.new { give_a_greeting }
  4 + subject: Proc.new { give_a_greeting }
5 5
6 6 def welcome
7 7 mail
6 actionmailer/test/test_helper_test.rb
@@ -3,9 +3,9 @@
3 3 class TestHelperMailer < ActionMailer::Base
4 4 def test
5 5 @world = "Earth"
6   - mail :body => render(:inline => "Hello, <%= @world %>"),
7   - :to => "test@example.com",
8   - :from => "tester@example.com"
  6 + mail body: render(inline: "Hello, <%= @world %>"),
  7 + to: "test@example.com",
  8 + from: "tester@example.com"
9 9 end
10 10 end
11 11
8 actionmailer/test/url_test.rb
@@ -19,9 +19,9 @@ class UrlTestMailer < ActionMailer::Base
19 19
20 20 def signed_up_with_url(recipient)
21 21 @recipient = recipient
22   - @welcome_url = url_for :host => "example.com", :controller => "welcome", :action => "greeting"
23   - mail(:to => recipient, :subject => "[Signed up] Welcome #{recipient}",
24   - :from => "system@loudthinking.com", :date => Time.local(2004, 12, 12))
  22 + @welcome_url = url_for host: "example.com", controller: "welcome", action: "greeting"
  23 + mail(to: recipient, subject: "[Signed up] Welcome #{recipient}",
  24 + from: "system@loudthinking.com", date: Time.local(2004, 12, 12))
25 25 end
26 26 end
27 27
@@ -58,7 +58,7 @@ def test_signed_up_with_url
58 58
59 59 AppRoutes.draw do
60 60 get ':controller(/:action(/:id))'
61   - get '/welcome' => "foo#bar", :as => "welcome"
  61 + get '/welcome' => "foo#bar", as: "welcome"
62 62 end
63 63
64 64 expected = new_mail

0 comments on commit 96f290e

Please sign in to comment.
Something went wrong with that request. Please try again.