Skip to content

Backport #31483 to 5-1-stable - #31516

Merged
kamipo merged 1 commit into
rails:5-1-stablefrom
yhirano55:backport-31483
Dec 19, 2017
Merged

kamipo merged 1 commit into
rails:5-1-stablefrom
yhirano55:backport-31483

Conversation

@yhirano55

Copy link
Copy Markdown
Contributor

This is a bug fix. So I think we should backport to 5-1-stable.

…e contexts.`

Though the validation have supported multiple context since rails#21069,
its callbacks don't support multiple context currently.

So I regarded this as the bug and fixed.

Example:

```ruby
class Dog
  include ActiveModel::Validations
  include ActiveModel::Validations::Callbacks

  attr_accessor :history

  def initialize
    @history = []
  end

  before_validation :set_before_validation_on_a, on: :a
  before_validation :set_before_validation_on_b, on: :b
  after_validation :set_after_validation_on_a, on: :a
  after_validation :set_after_validation_on_b, on: :b

  def set_before_validation_on_a; history << "before_validation on a"; end
  def set_before_validation_on_b; history << "before_validation on b"; end
  def set_after_validation_on_a;  history << "after_validation on a" ; end
  def set_after_validation_on_b;  history << "after_validation on b" ; end
end
```

Before:

```
d = Dog.new
d.valid?([:a, :b])
d.history # []
```

After:

```
d = Dog.new
d.valid?([:a, :b])
d.history # ["before_validation on a", "before_validation on b", "after_validation on a", "after_validation on b"]
```
@rails-bot

Copy link
Copy Markdown

r? @rafaelfranca

(@rails-bot has picked a reviewer for you, use r? to override)

@rails-bot

Copy link
Copy Markdown

warning Warning warning

  • Pull requests are usually filed against the master branch for this repo, but this one is against 5-1-stable. Please double check that you specified the right target!

@kamipo
kamipo merged commit 35b8f0f into rails:5-1-stable Dec 19, 2017
@yhirano55
yhirano55 deleted the backport-31483 branch December 19, 2017 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants