bcardarella / valid_attribute

Minimalist validation BDD for ActiveModel specs
178 stars 18 forks source link

Multiple when not working #7

Closed mhenrixon closed 13 years ago

mhenrixon commented 13 years ago

I am trying something like below but it seems to choke on the float value.

it { should      have_valid(:min_sphere).when(1, 4.5) }
comparison of Float with nil failed

The actual code for this one looks like

  validates_numericality_of :min_sphere,
    less_than: Proc.new { |frame| frame.nil? ? 60 : frame.max_sphere },
    greater_than_or_equal_to: -60,
    only_integer: false,
    message: "must be smaller than max sphere"

I do however get this for some other specs as well where I supply strings. as an alternative. Am I using it wrongly?

bcardarella commented 13 years ago

Do you have validations on your model? Because all this gem does with the value is assign it then call #valid?.

mhenrixon commented 13 years ago

You are right, it was the validations. Can't compare nil with 0 it's usually not a problem but when using the proc like that I had to make sure there is always a value for the less_than and the greater_than.

Might solve the client_side_validations bug as well.

edit no it didn't solve that but it solved the bug I had with formtastic html5 validators