Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Commit

Permalink
Changed the Search#fields method to accept arguments as a splat or an…
Browse files Browse the repository at this point in the history
… Array
  • Loading branch information
karmi committed Jul 19, 2011
1 parent 7044f6b commit 70b30ed
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/tire/search.rb
Expand Up @@ -64,8 +64,8 @@ def size(value)
self
end

def fields(fields=[])
@fields = fields
def fields(*fields)
@fields = Array(fields.flatten)
self
end

Expand Down
11 changes: 11 additions & 0 deletions test/integration/results_test.rb
Expand Up @@ -21,6 +21,17 @@ class ResultsIntegrationTest < Test::Unit::TestCase
assert_nil s.results.first.tags
end

should "allow to retrieve multiple fields" do
q = 'title:one'
s = Tire.search('articles-test') do
query { string q }
fields 'title', 'tags'
end
assert_equal 'One', s.results.first.title
assert_equal 'ruby', s.results.first.tags[0]
assert_nil s.results.first.published_on
end

end

end
Expand Down
18 changes: 17 additions & 1 deletion test/unit/search_test.rb
Expand Up @@ -254,7 +254,23 @@ def foo; 'bar'; end
fields :title
end
hash = MultiJson.decode( s.to_json )
assert_equal 'title', hash['fields']
assert_equal ['title'], hash['fields']
end

should "take multiple fields as an Array" do
s = Search::Search.new('index') do
fields [:title, :tags]
end
hash = MultiJson.decode( s.to_json )
assert_equal ['title', 'tags'], hash['fields']
end

should "take multiple fields as splat argument" do
s = Search::Search.new('index') do
fields :title, :tags
end
hash = MultiJson.decode( s.to_json )
assert_equal ['title', 'tags'], hash['fields']
end

end
Expand Down

0 comments on commit 70b30ed

Please sign in to comment.