Permalink
Browse files

r2726@asus: jeremy | 2005-10-24 14:11:59 -0700

 correct primary key semantics: foo.id and foo.real_pk_column should both exist and return nil if foo.new_record?


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2718 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 8ac9638 commit 0e4c5b0288c3fab5ec8bdc4d7448be2b72e55e58 @jeremy jeremy committed Oct 24, 2005
Showing with 6 additions and 7 deletions.
  1. +1 −1 activerecord/lib/active_record/base.rb
  2. +5 −6 activerecord/test/pk_test.rb
@@ -1451,7 +1451,7 @@ def define_read_method(symbol, attr_name, column)
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
@@ -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 @@ def test_integer_key
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 @@ def test_integer_key
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

0 comments on commit 0e4c5b0

Please sign in to comment.