From ec13305b21d7146417b17a2cdf976bbc5cac2189 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 24 Dec 2010 22:15:41 -0700 Subject: stop redifining methods on every call to set_primary_key --- activerecord/test/cases/base_test.rb | 12 ++++++++---- activerecord/test/cases/inheritance_test.rb | 4 ++++ 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index e186b2aea7..09ef04a656 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1073,10 +1073,14 @@ class BasicsTest < ActiveRecord::TestCase end def test_define_attr_method_with_block - k = Class.new( ActiveRecord::Base ) - k.primary_key = "id" - k.send(:define_attr_method, :primary_key) { "sys_" + original_primary_key } - assert_equal "sys_id", k.primary_key + k = Class.new( ActiveRecord::Base ) do + class << self + attr_accessor :foo_key + end + end + k.foo_key = "id" + k.send(:define_attr_method, :foo_key) { "sys_" + original_foo_key } + assert_equal "sys_id", k.foo_key end def test_set_table_name_with_value diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index c3da9cdf53..6abbe45492 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -219,6 +219,10 @@ class InheritanceTest < ActiveRecord::TestCase switch_to_default_inheritance_column end + def test_inherits_custom_primary_key + assert_equal Subscriber.primary_key, SpecialSubscriber.primary_key + end + def test_inheritance_without_mapping assert_kind_of SpecialSubscriber, SpecialSubscriber.find("webster132") assert_nothing_raised { s = SpecialSubscriber.new("name" => "And breaaaaathe!"); s.id = 'roger'; s.save } -- cgit v1.2.3