Skip to content

Commit

Permalink
Added more defensive way of checking the @attributes in Item#respond_to?
Browse files Browse the repository at this point in the history
Closes karmi#944
  • Loading branch information
fabn authored and karmi committed Apr 12, 2014
1 parent 58ab10a commit 1016449
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tire/results/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/unit/results_item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1016449

Please sign in to comment.