From 9c1bac0b7fcb627640db6824dca3e6e829a3c3e6 Mon Sep 17 00:00:00 2001 From: Jaime Bellmyer Date: Mon, 9 Mar 2009 13:23:27 -0500 Subject: raises an exception on habtm join table inserts if join table contains a primary key. Caches this check to save time on subsequent inserts. [#2086 state:committed] Signed-off-by: Jeremy Kemper --- .../test/cases/associations/habtm_join_table_test.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'activerecord/test/cases/associations') diff --git a/activerecord/test/cases/associations/habtm_join_table_test.rb b/activerecord/test/cases/associations/habtm_join_table_test.rb index 0586df1716..bf3e04c3eb 100644 --- a/activerecord/test/cases/associations/habtm_join_table_test.rb +++ b/activerecord/test/cases/associations/habtm_join_table_test.rb @@ -8,7 +8,7 @@ class MyBook < ActiveRecord::Base has_and_belongs_to_many :my_readers end -class JoinTableTest < ActiveRecord::TestCase +class HabtmJoinTableTest < ActiveRecord::TestCase def setup ActiveRecord::Base.connection.create_table :my_books, :force => true do |t| t.string :name @@ -42,4 +42,15 @@ class JoinTableTest < ActiveRecord::TestCase end end end + + uses_transaction :test_should_cache_result_of_primary_key_check + def test_should_cache_result_of_primary_key_check + if ActiveRecord::Base.connection.supports_primary_key? + ActiveRecord::Base.connection.stubs(:primary_key).with('my_books_my_readers').returns(false).once + weaz = MyReader.create(:name=>'Weaz') + + weaz.my_books << MyBook.create(:name=>'Great Expectations') + weaz.my_books << MyBook.create(:name=>'Greater Expectations') + end + end end -- cgit v1.2.3