Skip to content

Commit

Permalink
Mention that Action Mailer methods are not deferred [ci skip]
Browse files Browse the repository at this point in the history
Closes #17965, #17968

[Godfrey Chan, Miklós Fazekas]
  • Loading branch information
chancancode committed Dec 13, 2014
1 parent 54def10 commit a072aa3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions guides/source/upgrading_ruby_on_rails.md
Expand Up @@ -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
-------------------------------------

Expand Down

0 comments on commit a072aa3

Please sign in to comment.