Commit Graph

32 Commits

Author SHA1 Message Date
Gannon McGibbon
f5050d998d Add MailDeliveryJob for unified mail delivery
Add `MailDeliveryJob` for delivering both regular and parameterized mail.
Deprecate using `DeliveryJob` and `Parameterized::DeliveryJob`.
2018-12-04 11:00:34 -05:00
Gannon McGibbon
60339da5bc Deliver parameterized mail with DeliveryJob
Deliver parameterized mail with `ActionMailer::DeliveryJob`
and remove `ActionMailer::Parameterized::DeliveryJob`.
2018-11-22 18:37:53 -05:00
Ryuta Kamizono
2b35826389 Enable Layout/SpaceBeforeComma rubocop rule, and fixed more
Follow up of #31390.
2017-12-12 20:00:50 +09:00
yuuji.yaginuma
2f469dc308 Clear mail after test
If clear it before the test, the mail of the last executed test will not
be correctly cleared.

Therefore, executing the test with seed below will result in an error.

```
./bin/test -w --seed 55480
Run options: --seed 55480

# Running:

...........................................................................................................................................................F

Failure:
MailDeliveryTest#test_does_not_increment_the_deliveries_collection_on_error [/home/yaginuma/program/rails/master_y_yagi/rails/actionmailer/test/delivery_methods_test.rb:221]:
--- expected
+++ actual
@@ -1 +1 @@
-[]
+[#<Mail::Message:47011389364640, Multipart: false, Headers: <Date: Mon, 14 Aug 2017 07:48:40 +0900>, <From: test-sender@test.com>, <To: test-receiver@test.com>, <Message-ID: <5990d748ea5b2_29342ac1af8bcf40886f7@yaginuma.mail>>, <Subject: Test Subject>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>]

bin/test test/delivery_methods_test.rb:216
```
2017-08-14 07:49:13 +09:00
Kir Shatrov
82df8c2ca5 Use frozen string literal in actionmailer/ 2017-07-23 18:17:19 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Matthew Mongeau
d9bbde09fc Allow mailers to configure their delivery job
Setting delivery_job on a mailer class will cause MessageDelivery to use
the specified job instead of ActionMailer::DeliveryJob:

    class MyMailer < ApplicationMailer
      self.delivery_job = MyCustomDeliveryJob

      ...
    end
2017-06-15 16:41:23 +09:00
Andrew White
c7135d2c8e Use better duration aliases in tests 2017-03-15 14:56:27 +00:00
Andrew White
ef28b68496 Don't cast to float unnecessarily
Adding durations to `Time` instances is perfectly okay.
2017-03-15 08:19:27 +00:00
Andrew White
75924c4517 Deprecate implicit coercion of ActiveSupport::Duration
Currently `ActiveSupport::Duration` implicitly converts to a seconds
value when used in a calculation except for the explicit examples of
addition and subtraction where the duration is the receiver, e.g:

    >> 2 * 1.day
    => 172800

This results in lots of confusion especially when using durations
with dates because adding/subtracting a value from a date treats
integers as a day and not a second, e.g:

    >> Date.today
    => Wed, 01 Mar 2017
    >> Date.today + 2 * 1.day
    => Mon, 10 Apr 2490

To fix this we're implementing `coerce` so that we can provide a
deprecation warning with the intent of removing the implicit coercion
in Rails 5.2, e.g:

    >> 2 * 1.day
    DEPRECATION WARNING: Implicit coercion of ActiveSupport::Duration
    to a Numeric is deprecated and will raise a TypeError in Rails 5.2.
    => 172800

In Rails 5.2 it will raise `TypeError`, e.g:

    >> 2 * 1.day
    TypeError: ActiveSupport::Duration can't be coerced into Integer

This is the same behavior as with other types in Ruby, e.g:

    >> 2 * "foo"
    TypeError: String can't be coerced into Integer
    >> "foo" * 2
    => "foofoo"

As part of this deprecation add `*` and `/` methods to `AS::Duration`
so that calculations that keep the duration as the receiver work
correctly whether the final receiver is a `Date` or `Time`, e.g:

    >> Date.today
    => Wed, 01 Mar 2017
    >> Date.today + 1.day * 2
    => Fri, 03 Mar 2017

Fixes #27457.
2017-03-02 08:00:22 +00:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Xavier Noria
b91ff557ef applies new string literal convention in actionmailer/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 19:03:39 +02:00
Jeremy Daer
e35b98e6f5
Action Mailer: Declarative exception handling with rescue_from.
Follows the same pattern as controllers and jobs. Exceptions raised in
delivery jobs (enqueued by `#deliver_later`) are also delegated to the
mailer's rescue_from handlers, so you can handle the DeserializationError
raised by delivery jobs:

```ruby
class MyMailer < ApplicationMailer
  rescue_from ActiveJob::DeserializationError do
    …
  end
```

ActiveSupport::Rescuable polish:
* Add the `rescue_with_handler` class method so exceptions may be
  handled at the class level without requiring an instance.
* Rationalize `exception.cause` handling. If no handler matches the
  exception, fall back to the handler that matches its cause.
* Handle exceptions raised elsewhere. Pass `object: …` to execute
  the `rescue_from` handler (e.g. a method call or a block to
  instance_exec) against a different object. Defaults to `self`.
2016-05-15 18:44:16 -07:00
Jeremy Daer
95e06e6682 Disallow calling #deliver_later after local message modifications.
They would be lost when the delivery job is enqueued, otherwise.
Prevents a common, hard-to-find bug like:

```ruby
message = Notifier.welcome(user, foo)
message.message_id = my_generated_message_id
message.deliver_later
```

The message_id is silently lost here! *Only the mailer arguments are
passed to the delivery job.*

This raises an exception now.

Make modifications to the message within the mailer method or use a
custom Active Job to manage delivery instead of using #deliver_later.
2016-04-07 13:36:50 -07:00
Ronak Jangir
8d7bf97798 Removed duplicate requiring minitest/mock as it is already required in method_call_assertions 2015-08-26 19:43:54 +05:30
Kasper Timm Hansen
062cbd18dd Revert "Merge pull request #20758 from xijo/action_mailer_message_delivery_respects_i18n_locale"
This reverts commit f2a8c23654d69dd8f294971487b5abf0e5d891c3, reversing
changes made to 3046c9bbe154aa717a5147091be8b495ed8969c4.
2015-07-07 22:11:20 +02:00
Johannes Opper
ca2387eb01 ActionMailer::MessageDelivery respects current I18n.locale
When #deliver_now is called all translations within the
generated email will be looked up for the current I18n
locale.

    I18n.locale = ‘de’
    mail.deliver_now # Generates german email, correct

In #enqueue_delivery the locale was not considered and
the resulting job uses the default locale.

    I18n.locale = ‘de’
    mail.deliver_later # Generate english email, incorrect

In order to achieve a consistent behaviour the current locale
is now always passed to `ActionMailer::DeliveryJob`.
2015-07-05 20:21:25 +02:00
Rafael Mendonça França
cecbf9ed32 Merge pull request #18587 from chrismcg/allow_deliver_later_queue_name_to_be_configured
Allow configuration of ActionMailer queue name
2015-06-03 13:25:32 -03:00
Chris McGrath
f5a131aaea Allow configuration of ActionMailer queue name 2015-06-02 10:49:49 +01:00
Ankit Gupta
0e6a67644a not needed require's
- as core_ext is not used and test pass locally
- mail is already required in abstract_unit
2015-05-10 08:42:30 -04:00
Vipul A M
6eced6a1fe Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 onwards. 2015-02-03 20:51:40 +05:30
claudiob
755dcd0691 Remove deprecated ActionMailer deliver & deliver!
These methods were deprecated in Rails 4.2 (see f4ee1147) so they can
be safely removed in Rails 5.0.
2015-01-04 11:58:41 -03:00
Cristian Bica
15ddf60e05 Rename remaining :in / :at to :wait / :wait_until 2014-09-04 08:08:06 +03:00
Cristian Bica
1e237b4e44 Active Job refactoring 2014-09-03 23:01:46 +03:00
Robin Dupret
a548e2ba16 Make test:isolated run without bundler for Action Mailer
Action Mailer tests weren't able to run in isolation without the bundle
exec prefix since we were requiring gems before requiring abstract_unit.

We don't need the `gem` call thus and the require_relative since the
test directory should be present in the load path when we run any test.
2014-08-29 12:41:37 +02:00
Akira Matsuda
31abbe5154 Fix SyntaxError 2014-08-21 06:40:00 +09:00
Cristian Bica
f4ee114746 Deprecated .deliver / .deliver! to .deliver_now / .deliver_now! 2014-08-20 17:48:34 +03:00
Akira Matsuda
0df2a83b7f Clear deliveries in order not to affect other tests 2014-08-20 19:07:03 +09:00
Abdelkader Boudih
299d1f2626 [ActionMailer] Rename ActionMailer::DelayedDeliveryJob to ActionMailer::DeliveryJob 2014-08-17 23:10:08 +00:00
Abdelkader Boudih
6a2ca149fd [ActiveJob] Fix test syntax 2014-08-17 23:09:42 +00:00
Abdelkader Boudih
18303f6e82 Refactor DeliverLater into MessageDelivery 2014-08-14 11:05:35 +00:00