Permalink
Browse files

primary keys should not be cleared on cache clear, fixing oracle tests

  • Loading branch information...
tenderlove committed Feb 9, 2011
1 parent 11061f4 commit 1c6f4562d788cd5b63889b9597bc1765a1bd75e0
@@ -56,6 +56,7 @@ def set_primary_key(value = nil, &block)
@primary_key ||= ''
self.original_primary_key = @primary_key
value &&= value.to_s
+ connection_pool.primary_keys[table_name] = value
self.primary_key = block_given? ? instance_eval(&block) : value
end
end
@@ -128,12 +128,10 @@ def table_exists?(name)
#
# * columns
# * columns_hash
- # * primary_keys
# * tables
def clear_cache!
@columns.clear
@columns_hash.clear
- @primary_keys.clear
@tables.clear
end
@@ -32,7 +32,14 @@ def initialize(klass, table)
def insert(values)
im = arel.compile_insert values
im.into @table
- primary_key_value = primary_key && Hash === values ? values[table[primary_key]] : nil
+
+ primary_key_value = nil
+
+ if primary_key && Hash === values
+ primary_key_value = values[values.keys.find { |k|
+ k.name == primary_key
+ }]
+ end
@klass.connection.insert(
im.to_sql,
@@ -50,6 +50,11 @@ class Boolean < ActiveRecord::Base; end
class BasicsTest < ActiveRecord::TestCase
fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things', :authors, :categorizations, :categories, :posts
+ def test_columns_should_obey_set_primary_key
+ pk = Subscriber.columns.find { |x| x.name == 'nick' }
+ assert pk.primary, 'nick should be primary key'
+ end
+
def test_primary_key_with_no_id
assert_nil Edge.primary_key
end
@@ -18,16 +18,14 @@ def test_pool_caches_columns_hash
assert_equal columns_hash, @pool.columns_hash['posts']
end
- def test_clearing_cache
+ def test_clearing_column_cache
@pool.columns['posts']
@pool.columns_hash['posts']
- @pool.primary_keys['posts']
@pool.clear_cache!
assert_equal 0, @pool.columns.size
assert_equal 0, @pool.columns_hash.size
- assert_equal 0, @pool.primary_keys.size
end
def test_primary_key

0 comments on commit 1c6f456

Please sign in to comment.