mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
making sure primary key is set on the columns
This commit is contained in:
@@ -85,7 +85,15 @@ module ActiveRecord
|
||||
|
||||
@columns = Hash.new do |h, table_name|
|
||||
h[table_name] = with_connection do |conn|
|
||||
conn.columns(table_name, "#{table_name} Columns")
|
||||
|
||||
# Fetch a list of columns
|
||||
conn.columns(table_name, "#{table_name} Columns").tap do |columns|
|
||||
|
||||
# set primary key information
|
||||
columns.each do |column|
|
||||
column.primary = column.name == primary_keys[table_name]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -38,6 +38,15 @@ module ActiveRecord
|
||||
assert_equal 'id', @pool.primary_keys['omgponies']
|
||||
end
|
||||
|
||||
def test_primary_key_is_set_on_columns
|
||||
posts_columns = @pool.columns_hash['posts']
|
||||
assert posts_columns['id'].primary
|
||||
|
||||
(posts_columns.keys - ['id']).each do |key|
|
||||
assert !posts_columns[key].primary
|
||||
end
|
||||
end
|
||||
|
||||
def test_clear_stale_cached_connections!
|
||||
pool = ConnectionPool.new ActiveRecord::Base.connection_pool.spec
|
||||
|
||||
|
||||
Reference in New Issue
Block a user