QueryMessage now handles hashes inside sort array properly.

This commit is contained in:
Jim Menard 2009-01-15 12:33:20 -05:00
parent 08b1f64525
commit fc1e384e50
2 changed files with 15 additions and 4 deletions

View File

@ -27,7 +27,16 @@ module XGen
{query.order_by => 1}
when Array
h = OrderedHash.new
query.order_by.each { |ob| h[ob] = 1 }
query.order_by.each { |ob|
case ob
when String
h[ob] = 1
when Hash # should have one entry; will handle all
ob.each { |k,v| h[k] = v }
else
raise "illegal query order_by value #{query.order_by.inspect}"
end
}
h
when Hash # Should be an ordered hash, but this message doesn't care
query.order_by

View File

@ -153,12 +153,14 @@ class DBAPITest < Test::Unit::TestCase
assert_equal 1, docs[2]['a']
assert_equal 3, docs[3]['a']
# Sorting using empty array; no order guarantee but should not blow up.
# Sorting using empty array; no order guarantee (Mongo bug #898) but
# should not blow up.
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => []).to_a
assert_equal 4, docs.size
# Sorting using array of hashes; no order guarantee but should not blow up.
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => [{'b' => 1}, {'a' => 1}]).to_a
# Sorting using array of hashes; no order guarantee (Mongo bug #898) but
# should not blow up.
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => [{'b' => 1}, {'a' => -1}]).to_a
assert_equal 4, docs.size
# Sorting using ordered hash. You can use an unordered one, but then the