diff options
author | Yoshiyuki Hirano <yhirano@me.com> | 2017-12-16 10:55:52 +0900 |
---|---|---|
committer | Yoshiyuki Hirano <yhirano@me.com> | 2017-12-20 00:27:19 +0900 |
commit | 470d0e459f2d1cb8e6d5c0a8a2fe3282ca65690e (patch) | |
tree | 100a0689006c2b7c59b95d9150702169345eef8f /activesupport/test/xml_mini_test.rb | |
parent | 011f76e57b145b9e5ef1fd520df7d7096cf8896a (diff) | |
download | rails-470d0e459f2d1cb8e6d5c0a8a2fe3282ca65690e.tar.gz rails-470d0e459f2d1cb8e6d5c0a8a2fe3282ca65690e.tar.bz2 rails-470d0e459f2d1cb8e6d5c0a8a2fe3282ca65690e.zip |
Fix validation callbacks on multiple context
I found a bug that validation callbacks don't fire on multiple context.
So I've fixed it.
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"]
```
Diffstat (limited to 'activesupport/test/xml_mini_test.rb')
0 files changed, 0 insertions, 0 deletions