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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
the second function should be it "should require max_width to be numeric" do instead of repeating: it "should require max_height to be numeric" do that''s something rspec does not like very much -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I forgot to note this is on Edge Rails, and trunk of Rspec. -Dave On Nov 16, 2007 10:24 AM, Dave <dhoefler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 17, 2007 3:24 AM, Dave <dhoefler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have an Rspec test that looks like this: > > describe ImageCollection, "validations" do > it "should require max_height to be numeric" do > ... > end > > it "should require max_height to be numeric" do > ... > end > end > > Has anyone experienced these types of ''bugs''/''errors'' before? Maybe > I''m missing something obvious here.I don''t know if it''s the cause, but you probably don''t want two specs named the same thing here.> 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''.And there''s a similar bug in the above paragraph... ;-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I changed the specs to be named something different, but that still
didn''t fix it.
describe ImageCollection, "validations" do
it "should require max_height to be numeric" do
collection = ImageCollection.create(:max_height => nil, :max_width
=> 100, :is_active => false)
puts "Errors: #{collection.errors.inspect}"
collection.should have(1).error_on(:max_height)
end
it "should require max_width to be numeric" do
collection = ImageCollection.create(:max_width => nil, :max_height
=> 100, :is_active => false)
puts "Errors: #{collection.errors.inspect}"
collection.should have(1).error_on(:max_width)
end
end
I''m still getting duplicate errors.
1)
''ImageCollection validations should require max_width to be
numeric'' FAILED
expected 1 error on :max_width, got 2
./spec/models/image_collection_spec.rb:32:
script/spec:4:
2)
''ImageCollection validations should require max_height to be
numeric'' FAILED
expected 1 error on :max_height, got 2
./spec/models/image_collection_spec.rb:26:
script/spec:4:
One of the other guys that I work with checked out the project on his
Red Hat box and all the tests pass. I went to check out a fresh copy
on Leopard and I get these 2 errors. How odd!
Thanks,
Dave
On Nov 16, 2007 10:34 AM, Thorsten Muller
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> the second function should be
> it "should require max_width to be numeric" do
>
> instead of repeating:
> it "should require max_height to be numeric" do
>
> that''s something rspec does not like very much
> --
> Posted via http://www.ruby-forum.com/.
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---