mirror of https://github.com/rails/rails
Merge pull request #51758 from taketo1113/fix-changed-cidr2
PostgreSQL Cidr#change? raise an error of NoMethodError: undefined method `prefix' for nil, when creating a record with an empty value of inet/cidr column.
This commit is contained in:
commit
0be846c893
|
@ -31,7 +31,7 @@ module ActiveRecord
|
|||
# TODO: Remove when IPAddr#== compares IPAddr#prefix. See
|
||||
# https://github.com/ruby/ipaddr/issues/21
|
||||
def changed?(old_value, new_value, _new_value_before_type_cast)
|
||||
super || old_value.prefix != new_value.prefix
|
||||
super || !old_value.nil? && old_value.prefix != new_value.prefix
|
||||
end
|
||||
|
||||
def cast_value(value)
|
||||
|
|
|
@ -21,6 +21,15 @@ module ActiveRecord
|
|||
|
||||
assert_equal "foo", type.serialize("foo")
|
||||
end
|
||||
|
||||
test "changed? with nil values" do
|
||||
type = OID::Cidr.new
|
||||
|
||||
assert_not type.changed?(nil, nil, "")
|
||||
assert type.changed?("192.168.0.0/24", nil, "")
|
||||
assert type.changed?(nil, "192.168.0.0/24", "")
|
||||
assert type.changed?("192.168.0.0/24", "192.168.0.0/25", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue