From 1e21fc8c9a43ba58314e1737d01ae80facdcb325 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 5 Nov 2013 10:32:35 +1100 Subject: [PATCH] fix regression in Rails 4 --- app/models/screened_ip_address.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/screened_ip_address.rb b/app/models/screened_ip_address.rb index 2d5ce4bf402..2199768955a 100644 --- a/app/models/screened_ip_address.rb +++ b/app/models/screened_ip_address.rb @@ -14,6 +14,15 @@ class ScreenedIpAddress < ActiveRecord::Base match_for_ip_address(ip_address) || create(opts.slice(:action_type).merge(ip_address: ip_address)) end + # @Neil please review, in rails 4 when setting an ip address attribute a conversion takes place + # this may explode meaning you will never even reach the validator + # We can work around the issue like so, but I wonder if the spec is valid + def ip_address=(val) + write_attribute(:ip_address, val) + rescue IPAddr::InvalidAddressError + self.errors.add(:ip_address, :invalid) + end + def self.match_for_ip_address(ip_address) # The <<= operator on inet columns means "is contained within or equal to". #