Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add tests to ensure numericality validator with greater_than and less_then options works (currently failing) #171

Closed
wants to merge 2 commits into from

2 participants

@starim

When using money-rails 0.9.0 in a project, the numericality validator with the greater_than option didn't appear to be doing any validation, so I checked out the money-rails project and examined the tests. The existing tests only check that numericality validation is rejecting non-numeric values, so I added tests to check that the greater_than and less_than options are working on monetized fields as described in the readme.

These tests are currently failing. It looks like the numericality validator on monetized fields is ignoring the greater_than or less_than options.

Ideally I wouldn't dump failing tests on you, but I don't have enough familiarity with money-rails to fix the issue myself.

Brent Houghton added some commits
Brent Houghton Add a test for a currency value of 0 passing validation, even with a …
…greater_than validator requiring a value greater than zero.
8f71053
Brent Houghton Add tests that the greater_than and less_than numericality validation…
…s work on monetized model properties.
52f76df
@semmons99
Owner

I'd gladly merge once you figure out the build failures.

@semmons99 semmons99 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 24, 2014
  1. Add a test for a currency value of 0 passing validation, even with a …

    Brent Houghton authored
    …greater_than validator requiring a value greater than zero.
  2. Add tests that the greater_than and less_than numericality validation…

    Brent Houghton authored
    …s work on monetized model properties.
This page is out of date. Refresh to see the latest.
View
19 spec/active_record/monetizable_spec.rb
@@ -66,6 +66,21 @@ class Sub < Product; end
product.save.should be_true
end
+ it "should enforce greater_than numericality validations" do
+ product.price_cents = 80
+ product.save.should be_false
+ end
+
+ it "should enforce less_than numericality validations" do
+ product.price_cents = 100000
+ product.save.should be_false
+ end
+
+ it "shouldn't let 0 pass a greater_than validation requiring a minimum of 1" do
+ product.price_cents = 0
+ product.save.should be_false
+ end
+
it "skips numericality validation when disabled" do
product.invalid_price_cents = 'not_valid'
product.save.should be_true
@@ -196,11 +211,11 @@ class Sub < Product; end
it "fails validation with the proper error message on the cents field " do
product.price_in_a_range = "-12"
product.valid?.should be_false
- product.errors[:price_in_a_range_cents].first.should match(/greater than 0/)
+ product.errors[:price_in_a_range_cents].first.should match(/greater than 1/)
product.price_in_a_range = "0"
product.valid?.should be_false
- product.errors[:price_in_a_range_cents].first.should match(/greater than 0/)
+ product.errors[:price_in_a_range_cents].first.should match(/greater than 1/)
product.price_in_a_range = "12"
product.valid?.should be_true
View
4 spec/dummy/app/models/product.rb
@@ -27,11 +27,11 @@ class Product < ActiveRecord::Base
monetize :price_in_a_range_cents, :allow_nil => true,
:subunit_numericality => {
- :greater_than => 0,
+ :greater_than => 100,
:less_than_or_equal_to => 10000,
},
:numericality => {
- :greater_than => 0,
+ :greater_than => 1,
:less_than_or_equal_to => 100,
:message => "Must be greater than zero and less than $100"
}
Something went wrong with that request. Please try again.