Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Closes #69

Empty strings are converted to nil by string_to_cidr_address
  • Loading branch information...
commit b2db0d3a273da5318df9d0b883adea49067d13e9 1 parent dd03b08
@danmcclain danmcclain authored
View
5 lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb
@@ -92,7 +92,10 @@ def type_cast_code_with_extended_types(var_name)
class << self
def string_to_cidr_address(string)
return string unless String === string
- return IPAddr.new(string)
+
+ if string.present?
+ IPAddr.new(string)
+ end
end
end
View
9 spec/dummy/db/schema.rb
@@ -13,10 +13,6 @@
ActiveRecord::Schema.define(:version => 20120501163758) do
- add_extension "hstore"
- add_extension "pg_trgm"
- add_extension "citext"
-
create_table "people", :force => true do |t|
t.inet "ip"
t.cidr "subnet"
@@ -26,9 +22,4 @@
t.datetime "updated_at", :null => false
end
- create_table "sanity_tests", :force => true do |t|
- t.string "tags", :array => true
- t.integer "tag_ids", :array => true
- end
-
end
View
9 spec/models/inet_spec.rb
@@ -50,6 +50,15 @@ class Address < ActiveRecord::Base
address.ip_address.should eq IPAddr.new('192.168.1.2')
end
+ it 'converts empty strings to nil' do
+ address = Address.create
+ address.ip_address = ''
+ address.save
+
+ address.reload
+ address.ip_address.should eq nil
+ end
+
it 'updates an address with an IPAddr' do
ip_addr_1 = IPAddr.new('192.168.0.1')
ip_addr_2 = IPAddr.new('192.168.1.2')
Please sign in to comment.
Something went wrong with that request. Please try again.