Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate_numericality_of 'property quantity, :type => Fixnum' not as expected #9

Open
michaelkirk opened this issue Dec 12, 2010 · 1 comment

Comments

@michaelkirk
Copy link

I have a form with a text field, for which I'd like to validate the contents as numerical.

Unfortunately, properties defined with a type are typecast on assignment (this is couch_potato behavoir, I believe). So if I assign a string to a property of type Fixnum, the value is typecast (meaninglessly) to 0.

class Product 
  include SimplyStored::Couch
  include Validatable
  property :quantity, :type => Fixnum
  validates_numericality_of :quantity
end

p= Product.new(:quantity => "not a number")
p.valid? # => true
p.quantity # => 0

Has anyone else come across this? Any advice on how to handle this? It seems like it might be reasonable behavior from the perspective of couch_potato, which has something like 'statically typed' attributes. But it certainly doesn't make sense in the context of validations.

@jweiss
Copy link
Collaborator

jweiss commented Dec 12, 2010

I've recently also run into this and the problem is as you said that CouchPotato casts on assignment. I'll see that I talk to Alex of CouchPotato. The only good place to fix this is in CouchPotato.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants