actionmailer 4.2.0.beta1 → 4.2.0.beta2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionmailer might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b645b4249222f8f9158e506e7ce6f9896b94ffb1
4
- data.tar.gz: c37159e974453b38edeb571c2a7856520c80bd40
3
+ metadata.gz: 0bc83dd8e3d6e0dc2a2c465cec4353f5b5f38b21
4
+ data.tar.gz: 2d58f9767f0129b86e0b55e8efbc5de107e0e198
5
5
  SHA512:
6
- metadata.gz: b7be91503097c551664c180a89064411f1a0e0caedcb57568b72a952dbb1ba416e1b0cdb6921caa23eda9cd7cf35cdb7838dfe22e8885805d7bfbe385afbb5e1
7
- data.tar.gz: b5f6483b59c93b59c7f290ece2214e96def84c552255f5365b2cf5fe0a02eeb94ace98e024ec223e2f6aaa74dff81d62332dbf1fd85acb2f5cf6fffa23d0eebc
6
+ metadata.gz: c256f706c7a3e161616067951e18fe8b40492d80888aedcee325063042602e06b807ce3cb780fe278e6d17a4d5bdae371d2687ebe37f6483a02f035588db1cfe
7
+ data.tar.gz: 38e1ad4db887bf5b561b40a8dceefadee960c1f1f1ac6c427bba146cfd8e21720257789569e9c901740171135e4a230ec542cf2454332c637d5c4adad21453be
@@ -1,11 +1,19 @@
1
- * Added #deliver_later in addition to #deliver, which will enqueue a job to render and
2
- deliver the mail instead of delivering it right at that moment. The job is enqueued
3
- using the new Active Job framework in Rails, and will use whatever queue is configured for Rails.
4
-
1
+ * Attachments can be added while rendering the mail template.
2
+
3
+ Fixes #16974.
4
+
5
+ *Christian Felder*
6
+
7
+ * Added `#deliver_later`, `#deliver_now` and deprecate `#deliver` in favour of
8
+ `#deliver_now`. `#deliver_later` will enqueue a job to render and deliver
9
+ the mail instead of delivering it right at that moment. The job is enqueued
10
+ using the new Active Job framework in Rails, and will use whatever queue is
11
+ configured for Rails.
12
+
5
13
  *DHH/Abdelkader Boudih/Cristian Bica*
6
14
 
7
- * Make ActionMailer::Previews methods class methods. Previously they were
8
- instance methods and ActionMailer tries to render a message when they
15
+ * Make `ActionMailer::Previews` methods class methods. Previously they were
16
+ instance methods and `ActionMailer` tries to render a message when they
9
17
  are called.
10
18
 
11
19
  *Cristian Bica*
@@ -65,12 +65,12 @@ In order to send mails, you simply call the method and then call +deliver+ on th
65
65
 
66
66
  Calling the method returns a Mail Message object:
67
67
 
68
- message = Notifier.welcome("david@loudthinking.com") # => Returns a Mail::Message object
69
- message.deliver # => delivers the email
68
+ message = Notifier.welcome("david@loudthinking.com") # => Returns a Mail::Message object
69
+ message.deliver_now # => delivers the email
70
70
 
71
71
  Or you can just chain the methods together like:
72
72
 
73
- Notifier.welcome("david@loudthinking.com").deliver # Creates the email and sends it immediately
73
+ Notifier.welcome("david@loudthinking.com").deliver_now # Creates the email and sends it immediately
74
74
 
75
75
  == Setting defaults
76
76
 
@@ -138,9 +138,20 @@ module ActionMailer
138
138
  # Once a mailer action and template are defined, you can deliver your message or create it and save it
139
139
  # for delivery later:
140
140
  #
141
- # Notifier.welcome(david).deliver # sends the email
142
- # mail = Notifier.welcome(david) # => a Mail::Message object
143
- # mail.deliver # sends the email
141
+ # Notifier.welcome(User.first).deliver_now # sends the email
142
+ # mail = Notifier.welcome(User.first) # => an ActionMailer::MessageDelivery object
143
+ # mail.deliver_now # sends the email
144
+ #
145
+ # The <tt>ActionMailer::MessageDelivery</tt> class is a wrapper around a <tt>Mail::Message</tt> object. If
146
+ # you want direct access to the <tt>Mail::Message</tt> object you can call the <tt>message</tt> method on
147
+ # the <tt>ActionMailer::MessageDelivery</tt> object.
148
+ #
149
+ # Notifier.welcome(User.first).message # => a Mail::Message object
150
+ #
151
+ # Action Mailer is nicely integrated with Active Job so you can send emails in the background (example: outside
152
+ # of the request-response cycle, so the user doesn't have to wait on it):
153
+ #
154
+ # Notifier.welcome(User.first).deliver_later # enqueue the email sending to Active Job
144
155
  #
145
156
  # You never instantiate your mailer class. Rather, you just call the method you defined on the class itself.
146
157
  #
@@ -322,8 +333,8 @@ module ActionMailer
322
333
  # end
323
334
  #
324
335
  # Methods must return a <tt>Mail::Message</tt> object which can be generated by calling the mailer
325
- # method without the additional <tt>deliver</tt>. The location of the mailer previews
326
- # directory can be configured using the <tt>preview_path</tt> option which has a default
336
+ # method without the additional <tt>deliver_now</tt> / <tt>deliver_later</tt>. The location of the
337
+ # mailer previews directory can be configured using the <tt>preview_path</tt> option which has a default
327
338
  # of <tt>test/mailers/previews</tt>:
328
339
  #
329
340
  # config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
@@ -764,7 +775,6 @@ module ActionMailer
764
775
  def mail(headers = {}, &block)
765
776
  return @_message if @_mail_was_called && headers.blank? && !block
766
777
 
767
- @_mail_was_called = true
768
778
  m = @_message
769
779
 
770
780
  # At the beginning, do not consider class default for content_type
@@ -792,6 +802,8 @@ module ActionMailer
792
802
 
793
803
  # Render the templates and blocks
794
804
  responses = collect_responses(headers, &block)
805
+ @_mail_was_called = true
806
+
795
807
  create_parts_from_responses(m, responses)
796
808
 
797
809
  # Setup content type, reapply charset and handle parts order
@@ -1,10 +1,10 @@
1
1
  require 'active_job'
2
2
 
3
3
  module ActionMailer
4
- class DeliveryJob < ActiveJob::Base
4
+ class DeliveryJob < ActiveJob::Base #:nodoc:
5
5
  queue_as :mailers
6
6
 
7
- def perform(mailer, mail_method, delivery_method, *args)
7
+ def perform(mailer, mail_method, delivery_method, *args) #:nodoc#
8
8
  mailer.constantize.public_send(mail_method, *args).send(delivery_method)
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  module ActionMailer
2
- # Returns the version of the currently loaded ActionMailer as a <tt>Gem::Version</tt>
2
+ # Returns the version of the currently loaded Action Mailer as a <tt>Gem::Version</tt>
3
3
  def self.gem_version
4
4
  Gem::Version.new VERSION::STRING
5
5
  end
@@ -8,7 +8,7 @@ module ActionMailer
8
8
  MAJOR = 4
9
9
  MINOR = 2
10
10
  TINY = 0
11
- PRE = "beta1"
11
+ PRE = "beta2"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -29,7 +29,7 @@ module ActionMailer
29
29
 
30
30
  # Access the message attachments list.
31
31
  def attachments
32
- @_message.attachments
32
+ mailer.attachments
33
33
  end
34
34
 
35
35
  # Returns +text+ wrapped at +len+ columns and indented +indent+ spaces.
@@ -1,45 +1,104 @@
1
1
  require 'delegate'
2
2
 
3
3
  module ActionMailer
4
+
5
+ # The <tt>ActionMailer::MessageDelivery</tt> class is used by
6
+ # <tt>ActionMailer::Base</tt> when creating a new mailer.
7
+ # <tt>MessageDelivery</tt> is a wrapper (+Delegator+ subclass) around a lazy
8
+ # created <tt>Mail::Message</tt>. You can get direct access to the
9
+ # <tt>Mail::Message</tt>, deliver the email or schedule the email to be sent
10
+ # through Active Job.
11
+ #
12
+ # Notifier.welcome(User.first) # an ActionMailer::MessageDelivery object
13
+ # Notifier.welcome(User.first).deliver_now # sends the email
14
+ # Notifier.welcome(User.first).deliver_later # enqueue email delivery as a job through Active Job
15
+ # Notifier.welcome(User.first).message # a Mail::Message object
4
16
  class MessageDelivery < Delegator
5
- def initialize(mailer, mail_method, *args)
17
+ def initialize(mailer, mail_method, *args) #:nodoc:
6
18
  @mailer = mailer
7
19
  @mail_method = mail_method
8
20
  @args = args
9
21
  end
10
22
 
11
- def __getobj__
23
+ def __getobj__ #:nodoc:
12
24
  @obj ||= @mailer.send(:new, @mail_method, *@args).message
13
25
  end
14
26
 
15
- def __setobj__(obj)
27
+ def __setobj__(obj) #:nodoc:
16
28
  @obj = obj
17
29
  end
18
30
 
19
- def message #:nodoc:
31
+ # Returns the Mail::Message object
32
+ def message
20
33
  __getobj__
21
34
  end
22
35
 
36
+ # Enqueues the email to be delivered through Active Job. When the
37
+ # job runs it will send the email using +deliver_now!+. That means
38
+ # that the message will be sent bypassing checking +perform_deliveries+
39
+ # and +raise_delivery_errors+, so use with caution.
40
+ #
41
+ # Notifier.welcome(User.first).deliver_later!
42
+ # Notifier.welcome(User.first).deliver_later!(wait: 1.hour)
43
+ # Notifier.welcome(User.first).deliver_later!(wait_until: 10.hours.from_now)
44
+ #
45
+ # Options:
46
+ #
47
+ # * <tt>:wait</tt> - Enqueue the email to be delivered with a delay
48
+ # * <tt>:wait_until</tt> - Enqueue the email to be delivered at (after) a specific date / time
23
49
  def deliver_later!(options={})
24
- enqueue_delivery :deliver!, options
50
+ enqueue_delivery :deliver_now!, options
25
51
  end
26
52
 
53
+ # Enqueues the email to be delivered through Active Job. When the
54
+ # job runs it will send the email using +deliver_now+.
55
+ #
56
+ # Notifier.welcome(User.first).deliver_later
57
+ # Notifier.welcome(User.first).deliver_later(wait: 1.hour)
58
+ # Notifier.welcome(User.first).deliver_later(wait_until: 10.hours.from_now)
59
+ #
60
+ # Options:
61
+ #
62
+ # * <tt>:wait</tt> - Enqueue the email to be delivered with a delay
63
+ # * <tt>:wait_until</tt> - Enqueue the email to be delivered at (after) a specific date / time
27
64
  def deliver_later(options={})
28
- enqueue_delivery :deliver, options
65
+ enqueue_delivery :deliver_now, options
66
+ end
67
+
68
+ # Delivers an email without checking +perform_deliveries+ and +raise_delivery_errors+,
69
+ # so use with caution.
70
+ #
71
+ # Notifier.welcome(User.first).deliver_now!
72
+ #
73
+ def deliver_now!
74
+ message.deliver!
75
+ end
76
+
77
+ # Delivers an email:
78
+ #
79
+ # Notifier.welcome(User.first).deliver_now
80
+ #
81
+ def deliver_now
82
+ message.deliver
83
+ end
84
+
85
+ def deliver! #:nodoc:
86
+ ActiveSupport::Deprecation.warn "#deliver! is deprecated and will be removed in Rails 5. " \
87
+ "Use #deliver_now! to deliver immediately or #deliver_later! to deliver through Active Job."
88
+ deliver_now!
89
+ end
90
+
91
+ def deliver #:nodoc:
92
+ ActiveSupport::Deprecation.warn "#deliver is deprecated and will be removed in Rails 5. " \
93
+ "Use #deliver_now to deliver immediately or #deliver_later to deliver through Active Job."
94
+ deliver_now
29
95
  end
30
96
 
31
97
  private
32
- def enqueue_delivery(delivery_method, options={})
33
- args = @mailer.name, @mail_method.to_s, delivery_method.to_s, *@args
34
- enqueue_method = :enqueue
35
- if options[:at]
36
- enqueue_method = :enqueue_at
37
- args.unshift options[:at]
38
- elsif options[:in]
39
- enqueue_method = :enqueue_in
40
- args.unshift options[:in]
98
+
99
+ def enqueue_delivery(delivery_method, options={})
100
+ args = @mailer.name, @mail_method.to_s, delivery_method.to_s, *@args
101
+ ActionMailer::DeliveryJob.set(options).perform_later(*args)
41
102
  end
42
- ActionMailer::DeliveryJob.send enqueue_method, *args
43
- end
44
103
  end
45
104
  end
@@ -1,3 +1,4 @@
1
+ require 'active_job/railtie'
1
2
  require "action_mailer"
2
3
  require "rails"
3
4
  require "abstract_controller/railties/routes_helpers"
@@ -6,9 +6,9 @@ module ActionMailer
6
6
  #
7
7
  # def test_emails
8
8
  # assert_emails 0
9
- # ContactMailer.welcome.deliver
9
+ # ContactMailer.welcome.deliver_now
10
10
  # assert_emails 1
11
- # ContactMailer.welcome.deliver
11
+ # ContactMailer.welcome.deliver_now
12
12
  # assert_emails 2
13
13
  # end
14
14
  #
@@ -17,12 +17,12 @@ module ActionMailer
17
17
  #
18
18
  # def test_emails_again
19
19
  # assert_emails 1 do
20
- # ContactMailer.welcome.deliver
20
+ # ContactMailer.welcome.deliver_now
21
21
  # end
22
22
  #
23
23
  # assert_emails 2 do
24
- # ContactMailer.welcome.deliver
25
- # ContactMailer.welcome.deliver
24
+ # ContactMailer.welcome.deliver_now
25
+ # ContactMailer.welcome.deliver_now
26
26
  # end
27
27
  # end
28
28
  def assert_emails(number)
@@ -40,7 +40,7 @@ module ActionMailer
40
40
  #
41
41
  # def test_emails
42
42
  # assert_no_emails
43
- # ContactMailer.welcome.deliver
43
+ # ContactMailer.welcome.deliver_now
44
44
  # assert_emails 1
45
45
  # end
46
46
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0.beta1
4
+ version: 4.2.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-20 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0.beta1
19
+ version: 4.2.0.beta2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.0.beta1
26
+ version: 4.2.0.beta2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionview
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 4.2.0.beta1
33
+ version: 4.2.0.beta2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 4.2.0.beta1
40
+ version: 4.2.0.beta2
41
+ - !ruby/object:Gem::Dependency
42
+ name: activejob
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 4.2.0.beta2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 4.2.0.beta2
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: mail
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +81,7 @@ dependencies:
67
81
  version: '1.0'
68
82
  - - ">="
69
83
  - !ruby/object:Gem::Version
70
- version: 1.0.2
84
+ version: 1.0.3
71
85
  type: :runtime
72
86
  prerelease: false
73
87
  version_requirements: !ruby/object:Gem::Requirement
@@ -77,7 +91,7 @@ dependencies:
77
91
  version: '1.0'
78
92
  - - ">="
79
93
  - !ruby/object:Gem::Version
80
- version: 1.0.2
94
+ version: 1.0.3
81
95
  description: Email on Rails. Compose, deliver, receive, and test emails using the
82
96
  familiar controller/view pattern. First-class support for multipart email and attachments.
83
97
  email: david@loudthinking.com