Permalink
Browse files

Query#fields now get normalized.

  • Loading branch information...
1 parent 3dd8178 commit 53a22b4b8f309f624ee2e2730cde96df3457a711 @jnunemaker jnunemaker committed May 3, 2010
Showing with 7 additions and 2 deletions.
  1. +3 −2 lib/plucky/query.rb
  2. +4 −0 test/test_query.rb
View
5 lib/plucky/query.rb
@@ -40,7 +40,7 @@ def limit(count=0)
end
def fields(fields)
- @options[:fields] = fields
+ @options[:fields] = normalized_fields(fields)
self
end
@@ -135,7 +135,8 @@ def normalized_sort(sort)
end
def normalized_fields(fields)
- return if fields.nil? || fields.empty?
+ return if fields.nil? || fields.empty?
+ return fields if fields.is_a?(Hash)
if fields.respond_to?(:flatten, :compact)
fields.flatten.compact
View
4 test/test_query.rb
@@ -169,6 +169,10 @@ class QueryTest < Test::Unit::TestCase
should "update options (with hash)" do
Query.new.fields(:foo => 1, :bar => 0).options[:fields].should == {:foo => 1, :bar => 0}
end
+
+ should "normalize fields" do
+ Query.new.fields('foo, bar').options[:fields].should == %w(foo bar)
+ end
end
context "#limit" do

0 comments on commit 53a22b4

Please sign in to comment.