Permalink
Browse files

Work around a strange piece of Syck behaviour where it checks Model#r…

…espond_to? before initializing the object.

Things like YAML.load(YAML.dump(@post)) won't work without this.
  • Loading branch information...
NZKoz committed Dec 2, 2010
1 parent a5e7d9f commit 9381eb3dc36c0a1b2a7917f40c7bc302f987095f
@@ -54,7 +54,7 @@ def respond_to?(*args)
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
@@ -85,6 +85,17 @@ def test_respond_to?
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

0 comments on commit 9381eb3

Please sign in to comment.