Hi there,
I’m getting duplicate errors when I should only be receiving one error
in the @errors array.
I have an Rspec test that looks like this:
describe ImageCollection, “validations” do
it “should require max_height to be numeric” do
collection = ImageCollection.create(:max_height => “xxx”)
puts “Errors: #{collection.errors.inspect}”
collection.should have(1).error_on(:max_height)
end
it “should require max_height to be numeric” do
collection = ImageCollection.create(:max_width => “xxx”)
puts “Errors: #{collection.errors.inspect}”
collection.should have(1).error_on(:max_width)
end
end
class ImageCollection < ActiveRecord::Base
validates_numericality_of :max_height, :max_width
end
Nothing too fancy about that setup. When I run ‘autotest’ and print
out what those errors are I see duplicate errors in the array for the
same attribute.
Errors: #<ActiveRecord::Errors:0x3f0c780 @base=#<ImageCollection id:
nil, page_type: nil, name: nil, created_at: nil, updated_at: nil,
page_id: nil, max_height: nil, max_width: 0, label: nil, type: nil,
is_active: false>, @errors={“max_width”=>[[“is not a number”, nil],
[“is not a number”, nil]], “max_height”=>[[“is not a number”, nil],
[“is not a number”, nil]]}>
Errors: #<ActiveRecord::Errors:0x3f05d68 @base=#<ImageCollection id:
nil, page_type: nil, name: nil, created_at: nil, updated_at: nil,
page_id: nil, max_height: 0, max_width: nil, label: nil, type: nil,
is_active: false>, @errors={“max_width”=>[[“is not a number”, nil],
[“is not a number”, nil]], “max_height”=>[[“is not a number”, nil],
[“is not a number”, nil]]}>
Notice how the ‘max_height’ attribute errors array has 2 entries for
“is not a number”. I’m only expecting 1 error, but I’m getting 2. Same
goes for ‘max_height’.
Has anyone experienced these types of ‘bugs’/‘errors’ before? Maybe
I’m missing something obvious here.
Thoughts?
Thanks!
-Dave