Skip to content
Permalink
Browse files

Mention that Action Mailer methods are not deferred [ci skip]

Closes #17965, #17968

[Godfrey Chan, Miklós Fazekas]
  • Loading branch information
chancancode committed Dec 13, 2014
1 parent 4a19b3d commit ba58478727581423f060740ec0589159b6743d33
Showing with 35 additions and 0 deletions.
  1. +35 −0 guides/source/upgrading_ruby_on_rails.md
@@ -207,12 +207,47 @@ gem 'rails-deprecated_sanitizer'
```

### Rails DOM Testing

The [`TagAssertions` module](http://api.rubyonrails.org/classes/ActionDispatch/Assertions/TagAssertions.html) (containing methods such as `assert_tag`), [has been deprecated](https://github.com/rails/rails/blob/6061472b8c310158a2a2e8e9a6b81a1aef6b60fe/actionpack/lib/action_dispatch/testing/assertions/dom.rb) in favor of the `assert_select` methods from the `SelectorAssertions` module, which has been extracted into the [rails-dom-testing gem](https://github.com/rails/rails-dom-testing).


### Masked Authenticity Tokens

In order to mitigate SSL attacks, `form_authenticity_token` is now masked so that it varies with each request. Thus, tokens are validated by unmasking and then decrypting. As a result, any strategies for verifying requests from non-rails forms that relied on a static session CSRF token have to take this into account.

### Action Mailer

Previously, calling a mailer method on a mailer class will result in the
corresponding instance method being executed directly. With the introduction of
Active Job and `#deliver_later`, this is no longer true. In Rails 4.2, the
invocation of the instance methods are deferred until either `deliver_now` or
`deliver_later` is called. For example:

```ruby
class Notifier < ActionMailer::Base
def notify(user, ...)
puts "Called"
mail(to: user.email, ...)
end
end
mail = Notifier.notify(user, ...) # Notifier#welcome is not yet called at this point
mail = mail.deliver_now # Prints "Called"
```

This should not result in any noticible differnces for most applications.
However, if you need some non-mailer methods to be exectuted synchronously, and
you were previously relying on the synchronous proxying behavior, you should
define them as class methods on the mailer class directly:

```ruby
class Notifier < ActionMailer::Base
def self.broadcast_notifications(users, ...)
users.each { |user| Notifier.notify(user, ...) }
end
end
```

Upgrading from Rails 4.0 to Rails 4.1
-------------------------------------

1 comment on commit ba58478

@chancancode

This comment has been minimized.

Copy link
Member Author

chancancode commented on ba58478 Dec 13, 2014

UH, EPIC FAIL.

The commit message is supposed to read "Mention that Action Mailer methods are now deferred" 🙈

Please sign in to comment.
You can’t perform that action at this time.