Fixes for postgresql inet columns in Rails 4. They're backed by an IPAddr class now, which breaks sql parameter marker support, and automatically sets the attribute to nil when trying to assign an invalid ip address.

This commit is contained in:
Neil Lalonde
2013-10-22 18:55:30 -04:00
parent 6394d924c8
commit c1008f4359
5 changed files with 21 additions and 7 deletions

View File

@ -6,7 +6,7 @@ describe IpAddressFormatValidator do
let(:validator) { described_class.new({attributes: :ip_address}) }
subject(:validate) { validator.validate_each(record, :ip_address, record.ip_address) }
[nil, '99.232.23.123', '99.232.0.0/16', 'fd12:db8::ff00:42:8329', 'fc00::/7'].each do |arg|
['99.232.23.123', '99.232.0.0/16', 'fd12:db8::ff00:42:8329', 'fc00::/7'].each do |arg|
it "should not add an error for #{arg}" do
record.ip_address = arg
validate
@ -14,6 +14,12 @@ describe IpAddressFormatValidator do
end
end
it 'should add an error for nil IP address' do
record.ip_address = nil
validate
record.errors[:ip_address].should be_present
end
it 'should add an error for invalid IP address' do
record.ip_address = '99.99.99'
validate