Permalink
Browse files

to_key on a destroyed model should return nil

  • Loading branch information...
1 parent bc364af commit c5448721b5054b8a467958d60427fdee15eac604 @spastorino spastorino committed Jul 9, 2011
@@ -7,7 +7,7 @@ module PrimaryKey
# the record is not persisted? or has just been destroyed.
def to_key
key = send(self.class.primary_key)
- [key] if key
+ persisted? && key ? [key] : nil
end
module ClassMethods
@@ -26,7 +26,7 @@ def test_to_key_with_customized_primary_key
def test_to_key_with_primary_key_after_destroy
topic = Topic.find(1)
topic.destroy
- assert_equal [1], topic.to_key
+ assert_equal nil, topic.to_key
end
def test_integer_key

0 comments on commit c544872

Please sign in to comment.