1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activemodel/lib/active_model
Yoshiyuki Hirano 470d0e459f 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"]
```
2017-12-20 00:27:19 +09:00
..
attribute Move Attribute and AttributeSet to ActiveModel 2017-11-09 14:29:39 -05:00
attribute_set Change how AttributeSet::Builder receives its defaults 2017-11-27 14:06:51 -07:00
locale
serializers Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
type [Active Model] require => require_relative 2017-10-21 22:48:27 +09:00
validations Fix validation callbacks on multiple context 2017-12-20 00:27:19 +09:00
attribute.rb Add missing autoload Type (#31123) 2017-11-11 06:43:54 +09:00
attribute_assignment.rb
attribute_methods.rb Merge pull request #29788 from kamipo/remove_unused_mutex_m 2017-07-17 13:54:37 -04:00
attribute_mutation_tracker.rb Add missing require "active_support/core_ext/hash/indifferent_access" 2017-11-10 23:48:53 +09:00
attribute_set.rb Change how AttributeSet::Builder receives its defaults 2017-11-27 14:06:51 -07:00
attributes.rb Add missing autoload Type (#31123) 2017-11-11 06:43:54 +09:00
callbacks.rb Use tt in doc for ActiveRecord [ci skip] 2017-08-27 14:01:29 +09:00
conversion.rb Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
dirty.rb Fix "warning: instance variable @attributes not initialized" 2017-11-10 14:02:28 +09:00
errors.rb fix bug on added? method 2017-11-13 17:27:47 +01:00
forbidden_attributes_protection.rb Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
gem_version.rb Preparing for 5.2.0.beta2 release 2017-11-28 14:41:02 -05:00
lint.rb Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
model.rb Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
naming.rb Clarify intentions around method redefinitions 2017-09-01 14:27:13 +09:30
railtie.rb Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
secure_password.rb Talk about bytes not characters 2017-07-31 17:42:43 -04:00
serialization.rb Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
translation.rb Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
type.rb Fix doc typo [ci skip] 2017-12-12 16:34:19 -05:00
validations.rb Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
validator.rb Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00
version.rb Use frozen string literal in activemodel/ 2017-07-16 20:11:16 +03:00