1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Generate inet columns for postgresql

This commit is contained in:
Adrian Pacała 2014-05-07 08:50:21 +02:00
parent a51036196a
commit 53504f7e28
2 changed files with 17 additions and 2 deletions

View file

@ -53,8 +53,8 @@ module ActiveRecord
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
t.#{ip_column} :current_sign_in_ip
t.#{ip_column} :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
@ -68,6 +68,15 @@ module ActiveRecord
# t.datetime :locked_at
RUBY
end
def ip_column
# Padded with spaces so it aligns nicely with the rest of the columns.
"%-8s" % (postgresql? ? "inet" : "string")
end
def postgresql?
ActiveRecord::Base.connection.adapter_name.downcase == "postgresql"
end
end
end
end

View file

@ -37,6 +37,12 @@ if DEVISE_ORM == :active_record
assert_no_file "app/models/monster.rb"
assert_no_migration "db/migrate/devise_create_monsters.rb"
end
test "use string column type for ip addresses" do
run_generator %w(monster)
assert_migration "db/migrate/devise_create_monsters.rb", /t.string :current_sign_in_ip/
assert_migration "db/migrate/devise_create_monsters.rb", /t.string :last_sign_in_ip/
end
end
module RailsEngine