Permalink
Browse files

[#281] Fixed the problem with composite keys (such as highlight resul…

…ts) in `Results::Item`

    @document = Results::Item.new :highlight => { 'name.ngrams' => 'abc' }
    assert_not_nil @document.highlight['name.ngrams']

Reported in thedeeno@0bd1a67.

Closes #281.
  • Loading branch information...
1 parent 829d47a commit dcfb1dac56d8a6911b76d1dc66a5bdc3bd33d3c3 @karmi committed Mar 22, 2012
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/tire/results/item.rb
  2. +8 −0 test/unit/results_item_test.rb
View
@@ -28,7 +28,7 @@ def method_missing(method_name, *arguments)
end
def [](key)
- @attributes[key]
+ @attributes[key.to_sym]
end
def id
@@ -60,6 +60,14 @@ class AlmostHash < Hash; end
assert_equal 'Test', @document.title
end
+ should "not care about symbols or strings in composite keys" do
+ @document = Results::Item.new :highlight => { 'name.ngrams' => 'abc' }
+
+ assert_not_nil @document.highlight['name.ngrams']
+ assert_equal 'abc', @document.highlight['name.ngrams']
+ assert_equal @document.highlight['name.ngrams'], @document.highlight['name.ngrams'.to_sym]
+ end
+
should "allow to retrieve values from nested hashes" do
assert_not_nil @document.author.name
assert_equal 'Kafka', @document.author.name

0 comments on commit dcfb1da

Please sign in to comment.