Work around a strange piece of Syck behaviour where it checks Model#respond_to? before initializing the object.

Things like YAML.load(YAML.dump(@post)) won't work without this.
This commit is contained in:
Michael Koziarski
2010-12-02 15:36:05 +13:00
committed by Aaron Patterson
parent 0afebd5b31
commit 96eec090df
2 changed files with 12 additions and 1 deletions

View File

@@ -54,7 +54,7 @@ module ActiveRecord
protected
def attribute_method?(attr_name)
attr_name == 'id' || @attributes.include?(attr_name)
attr_name == 'id' || (defined?(@attributes) && @attributes.include?(attr_name))
end
end
end

View File

@@ -85,6 +85,17 @@ class AttributeMethodsTest < ActiveRecord::TestCase
assert !topic.respond_to?("nothingness")
assert !topic.respond_to?(:nothingness)
end
# Syck calls respond_to? before actually calling initialize
def test_respond_to_with_allocated_object
topic = Topic.allocate
assert !topic.respond_to?("nothingness")
assert !topic.respond_to?(:nothingness)
assert_respond_to topic, "title"
assert_respond_to topic, :title
end
def test_array_content
topic = Topic.new