New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #31483 to 5-1-stable #31516

merged 1 commit into from Dec 19, 2017


None yet
4 participants

yhirano55 commented Dec 19, 2017

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

Backport `Fix to working before/after validation callbacks on multipl…
…e contexts.`

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

So I regarded this as the bug and fixed.


class Dog
  include ActiveModel::Validations
  include ActiveModel::Validations::Callbacks

  attr_accessor :history

  def initialize
    @history = []

  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


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


d =
d.valid?([:a, :b])
d.history # ["before_validation on a", "before_validation on b", "after_validation on a", "after_validation on b"]

This comment has been minimized.

rails-bot commented Dec 19, 2017

r? @rafaelfranca

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


This comment has been minimized.

rails-bot commented Dec 19, 2017

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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed

@yhirano55 yhirano55 deleted the yhirano55:backport-31483 branch Dec 19, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment