aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2010-12-02 15:36:05 +1300
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-02 08:40:34 -0800
commit96eec090dfd50326146b2f690408fefec50c5111 (patch)
tree55bef0491b1bca2679bd6e3defe8174b637b4b99
parent0afebd5b31bdc6edc1399c77153e65f5ea156fe1 (diff)
downloadrails-96eec090dfd50326146b2f690408fefec50c5111.tar.gz
rails-96eec090dfd50326146b2f690408fefec50c5111.tar.bz2
rails-96eec090dfd50326146b2f690408fefec50c5111.zip
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.
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb2
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb11
2 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 67f70c434e..4f4a0a5fee 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -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
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index bb0166a60c..3df8197e0d 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -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