Fix PostgreSQL Cidr#change?: NoMethodError: undefined method `prefix` for nil

This commit is contained in:
Taketo Takashima 2024-05-14 08:43:51 +09:00
parent 59064f88d8
commit c395b99f11
2 changed files with 10 additions and 1 deletions

View File

@ -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)

View File

@ -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