aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rw-r--r--activerecord/test/pk_test.rb11
2 files changed, 6 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 2f954eddc1..e6ccfd4659 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1451,7 +1451,7 @@ module ActiveRecord #:nodoc:
cast_code = column.type_cast_code('v')
access_code = cast_code ? "(v=@attributes['#{attr_name}']) && #{cast_code}" : "@attributes['#{attr_name}']"
- unless symbol == :id
+ unless attr_name.to_s == self.class.primary_key.to_s
access_code = access_code.insert(0, "raise NoMethodError, 'missing attribute: #{attr_name}', caller unless @attributes.has_key?('#{attr_name}'); ")
end
diff --git a/activerecord/test/pk_test.rb b/activerecord/test/pk_test.rb
index 0ee27f969b..13adc7eb76 100644
--- a/activerecord/test/pk_test.rb
+++ b/activerecord/test/pk_test.rb
@@ -1,4 +1,4 @@
-require 'abstract_unit'
+require "#{File.dirname(__FILE__)}/abstract_unit"
require 'fixtures/topic'
require 'fixtures/subscriber'
require 'fixtures/movie'
@@ -16,7 +16,7 @@ class PrimaryKeysTest < Test::Unit::TestCase
topic = Topic.new
topic.title = "New Topic"
assert_equal(nil, topic.id)
- assert_nothing_raised{ topic.save }
+ assert_nothing_raised { topic.save! }
id = topic.id
topicReloaded = Topic.find(id)
@@ -25,15 +25,14 @@ class PrimaryKeysTest < Test::Unit::TestCase
def test_customized_primary_key_auto_assigns_on_save
keyboard = Keyboard.new(:name => 'HHKB')
- assert_nothing_raised { keyboard.save }
- assert keyboard.id
+ assert_nothing_raised { keyboard.save! }
assert_equal keyboard.id, Keyboard.find_by_name('HHKB').id
end
def test_customized_primary_key_can_be_get_before_saving
keyboard = Keyboard.new
- assert_respond_to(keyboard, :key_number)
- assert_nothing_raised { keyboard.key_number }
+ assert_nil keyboard.id
+ assert_nothing_raised { assert_nil keyboard.key_number }
end
def test_customized_string_primary_key_settable_before_save