1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activemodel/CHANGELOG.md
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

1.6 KiB

  • Fix to working before/after validation callbacks on multiple contexts.

    Yoshiyuki Hirano

Rails 5.2.0.beta2 (November 28, 2017)

  • No changes.

Rails 5.2.0.beta1 (November 27, 2017)

  • Execute ConfirmationValidator validation when _confirmation's value is false.

    bogdanvlviv

  • Allow passing a Proc or Symbol to length validator options.

    Matt Rohrer

  • Add method #merge! for ActiveModel::Errors.

    Jahfer Husain

  • Fix regression in numericality validator when comparing Decimal and Float input values with more scale than the schema.

    Bradley Priest

  • Fix methods #keys, #values in ActiveModel::Errors.

    Change #keys to only return the keys that don't have empty messages.

    Change #values to only return the not empty values.

    Example:

    # Before
    person = Person.new
    person.errors.keys     # => []
    person.errors.values   # => []
    person.errors.messages # => {}
    person.errors[:name]   # => []
    person.errors.messages # => {:name => []}
    person.errors.keys     # => [:name]
    person.errors.values   # => [[]]
    
    # After
    person = Person.new
    person.errors.keys     # => []
    person.errors.values   # => []
    person.errors.messages # => {}
    person.errors[:name]   # => []
    person.errors.messages # => {:name => []}
    person.errors.keys     # => []
    person.errors.values   # => []
    

    bogdanvlviv

Please check 5-1-stable for previous changes.