Permalink
Browse files

Added more defensive way of checking the @attributes in Item#respond_to?

Closes #944
  • Loading branch information...
1 parent 58ab10a commit 1016449cd5bcfd52853f1728452e26962c18790e @fabn fabn committed with Feb 25, 2014
Showing with 5 additions and 1 deletion.
  1. +1 −1 lib/tire/results/item.rb
  2. +4 −0 test/unit/results_item_test.rb
View
@@ -27,7 +27,7 @@ def method_missing(method_name, *arguments)
end
def respond_to?(method_name, include_private = false)
- @attributes.has_key?(method_name.to_sym) || super
+ (@attributes || {}).has_key?(method_name.to_sym) || super
end
def [](key)
@@ -82,6 +82,10 @@ class AlmostHash < Hash; end
assert @document.respond_to?(:title, true)
end
+ should "not raise errors when unserializing" do
+ assert_nothing_raised { YAML.load(YAML.dump(@document)) }
+ end
+
should "return nil for non-existing keys/methods" do
assert_nothing_raised { @document.whatever }
assert_nil @document.whatever

0 comments on commit 1016449

Please sign in to comment.