1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

v_n_o no longer treats numbers as floats

Essentially validate_numericality_of when used with a comparison
qualifier required you to use only_integer when the validation itself
had only_integer on it, because the boundaries of the comparison were
tested using small decimal numbers rather than whole numbers. This
change was introduced in bc110f7, but is obviously is a backward
incompatible change, so we are reverting it.
This commit is contained in:
Elliot Winkler 2014-04-26 11:13:57 -04:00
parent 01c9d08c8e
commit 23ff55ff5d
4 changed files with 8 additions and 12 deletions

View file

@ -8,8 +8,12 @@
## Bug fixes
* Fix `ComparisonMatcher` so that `validate_numericality_of` comparison matchers
work with large numbers.
* Revert changes to `validate_numericality_of` made in the last release, which
made it so that comparison qualifiers specified on the validation are tested
using a very small decimal number offset rather than a whole number by
default, except if the matcher was qualified with `only_integer`. This means
that prior to 2.6.0, if your validation specified `only_integer` and you did
not, then after 2.6.0 that test now fails.
* Fix so that ActiveRecord matchers aren't included when ActiveRecord
isn't defined (i.e. if you are using ActiveModel only).

View file

@ -7,8 +7,6 @@ module Shoulda # :nodoc:
# is_greater_than(6).
# less_than(20)...(and so on) }
class ComparisonMatcher < ValidationMatcher
DIFF_TO_COMPARE_PRECISION_CHANGE_NUMBER = 2**34
attr_reader :diff_to_compare
def initialize(numericality_matcher, value, operator)
unless numericality_matcher.respond_to? :diff_to_compare
@ -18,7 +16,6 @@ module Shoulda # :nodoc:
@value = value
@operator = operator
@message = nil
@diff_to_compare = value.abs < DIFF_TO_COMPARE_PRECISION_CHANGE_NUMBER ? 0.000_001 : 1
end
def for(attribute)

View file

@ -26,7 +26,8 @@ module Shoulda # :nodoc:
class ValidateNumericalityOfMatcher
NUMERIC_NAME = 'numbers'
NON_NUMERIC_VALUE = 'abcd'
DEFAULT_DIFF_TO_COMPARE = 0.000_000_000_001
DEFAULT_DIFF_TO_COMPARE = 1
attr_reader :diff_to_compare
def initialize(attribute)

View file

@ -5,12 +5,6 @@ describe Shoulda::Matchers::ActiveModel::NumericalityMatchers::ComparisonMatcher
it_behaves_like 'a numerical submatcher'
describe '#diff_to_compare' do
it { expect(subject.diff_to_compare).to eq 0.000_001 }
it { expect(described_class.new(matcher, 2**34, :>).diff_to_compare).to eq 1 }
it { expect(described_class.new(matcher, -2**34, :>).diff_to_compare).to eq 1 }
end
context 'when initialized without correct numerical matcher' do
it 'raises an argument error' do
fake_matcher = matcher