Skip to content

Instantly share code, notes, and snippets.

@kdabir
Created December 12, 2012 05:49
Show Gist options
  • Save kdabir/4265161 to your computer and use it in GitHub Desktop.
Save kdabir/4265161 to your computer and use it in GitHub Desktop.
rspec/shoulda validate only positive values (numericality)

for something like this in rails model

...  
validates :points, :numericality => {:greater_than_or_equal_to => 0}, :allow_nil => true
...

test can be :

it { should validate_numericality_of(:points) }
it { should_not allow_value(-1).for(:points) }
it { should allow_value(0).for(:points) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment