1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #24835 from christianblais/activemodel/rangeerror

Change RangeError to a more specific ActiveModel::RangeError
This commit is contained in:
Rafael França 2016-05-03 14:06:30 -05:00
commit 83a8682c1d
4 changed files with 12 additions and 7 deletions

View file

@ -49,6 +49,7 @@ module ActiveModel
eager_autoload do
autoload :Errors
autoload :RangeError, 'active_model/errors'
autoload :StrictValidationFailed, 'active_model/errors'
autoload :UnknownAttributeError, 'active_model/errors'
end

View file

@ -526,6 +526,10 @@ module ActiveModel
class StrictValidationFailed < StandardError
end
# Raised when attribute values are out of range.
class RangeError < ::RangeError
end
# Raised when unknown attributes are supplied via mass assignment.
class UnknownAttributeError < NoMethodError
attr_reader :record, :attribute

View file

@ -46,7 +46,7 @@ module ActiveModel
def ensure_in_range(value)
unless range.cover?(value)
raise RangeError, "#{value} is out of range for #{self.class} with limit #{_limit}"
raise ActiveModel::RangeError, "#{value} is out of range for #{self.class} with limit #{_limit}"
end
end

View file

@ -53,25 +53,25 @@ module ActiveModel
end
test "values below int min value are out of range" do
assert_raises(::RangeError) do
assert_raises(ActiveModel::RangeError) do
Integer.new.serialize(-2147483649)
end
end
test "values above int max value are out of range" do
assert_raises(::RangeError) do
assert_raises(ActiveModel::RangeError) do
Integer.new.serialize(2147483648)
end
end
test "very small numbers are out of range" do
assert_raises(::RangeError) do
assert_raises(ActiveModel::RangeError) do
Integer.new.serialize(-9999999999999999999999999999999)
end
end
test "very large numbers are out of range" do
assert_raises(::RangeError) do
assert_raises(ActiveModel::RangeError) do
Integer.new.serialize(9999999999999999999999999999999)
end
end
@ -96,10 +96,10 @@ module ActiveModel
assert_equal(9223372036854775807, type.serialize(9223372036854775807))
assert_equal(-9223372036854775808, type.serialize(-9223372036854775808))
assert_raises(::RangeError) do
assert_raises(ActiveModel::RangeError) do
type.serialize(-9999999999999999999999999999999)
end
assert_raises(::RangeError) do
assert_raises(ActiveModel::RangeError) do
type.serialize(9999999999999999999999999999999)
end
end