This project is archived and is in readonly mode.
model.errors.empty? broken
Reported by Mathieu Arnold | April 9th, 2010 @ 12:05 PM
In the rails 2.3 docs, we can see in the ActiveRecord::Errors documentation :
empty?()
Returns true if no errors have been added.
Which is quite nice to have, but now, there's a regression, with rails 3 :
> model.errors
=> #<OrderedHash {}>
> model.errors.empty?
=> true
> model.errors.on :id
=> nil
> model.errors
=> #<OrderedHash {:id=>[]}>
> model.errors.empty?
=> false
It's all right until I call errors.on something, then the hash is not empty any more, and empty? does not do the right thing.
Comments and changes to this ticket
-
Ryan Bigg April 10th, 2010 @ 08:06 AM
I can only duplicate this by having an invalid object first and then checking the errors:
irb(main):002:0> board = Board.new
=> # irb(main):003:0> board.save
=> false irb(main):004:0> board.errors.empty?
=> false irb(main):005:0> board.errors
=> {:title=>["can't be blank"]} irb(main):006:0> board.title = "Some title"
=> "Some title" irb(main):007:0> board.errors.empty?
=> false irb(main):008:0> board.save
=> true irb(main):009:0> board.errors.empty?
=> trueOther than that, this is behaving as expected.
-
Ryan Bigg April 10th, 2010 @ 08:07 AM
Bah, sorry, I made up what your example was doing and I just tried the real-world one. I see now.
-
Repository April 10th, 2010 @ 12:21 PM
- State changed from new to resolved
(from [d748cc3cd07c6931e5ebc5242f268f1f7ec3d906]) Re-define empty? for errors to check if the values inside the OrderedHash are empty rather than the OrderedHash itself. [#4356 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/d748cc3cd07c6931e5ebc5242f268f...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 4356 model.errors.empty? broken (from [d748cc3cd07c6931e5ebc5242f268f1f7ec3d906]) Re-defi...