Fixed :sort values in tests. Commented out one test that failes due to a known Mongo bug.

This commit is contained in:
Jim Menard 2009-01-07 10:11:30 -05:00
parent 2bde6b4029
commit e4b19ec8f4
1 changed files with 23 additions and 14 deletions

View File

@ -43,7 +43,7 @@ class DBAPITest < Test::Unit::TestCase
assert_equal 4, docs.length
assert docs.detect { |row| row['b'] == 4 }
end
def test_find_simple
@r2 = @coll.insert('a' => 2)
@r3 = @coll.insert('b' => 3)
@ -112,7 +112,7 @@ class DBAPITest < Test::Unit::TestCase
@coll.insert('a' => 4, 'b' => 1)
# Sorting (ascending)
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => [{'a' => 1}]).map{ |x| x }
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => {'a' => 1}).map{ |x| x }
assert_equal 4, docs.size
assert_equal 1, docs[0]['a']
assert_equal 2, docs[1]['a']
@ -120,7 +120,7 @@ class DBAPITest < Test::Unit::TestCase
assert_equal 4, docs[3]['a']
# Sorting (descending)
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => [{'a' => -1}]).map{ |x| x }
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => {'a' => -1}).map{ |x| x }
assert_equal 4, docs.size
assert_equal 4, docs[0]['a']
assert_equal 3, docs[1]['a']
@ -134,7 +134,15 @@ class DBAPITest < Test::Unit::TestCase
assert_equal 2, docs[1]['a']
assert_equal 3, docs[2]['a']
assert_equal 4, docs[3]['a']
# Sorting using single name; assumes ascending order.
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => 'a').map{ |x| x }
assert_equal 4, docs.size
assert_equal 1, docs[0]['a']
assert_equal 2, docs[1]['a']
assert_equal 3, docs[2]['a']
assert_equal 4, docs[3]['a']
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => ['b', 'a']).map{ |x| x }
assert_equal 4, docs.size
assert_equal 2, docs[0]['a']
@ -157,22 +165,23 @@ class DBAPITest < Test::Unit::TestCase
assert_equal 2, docs[2]['a']
assert_equal 1, docs[3]['a']
oh = OrderedHash.new
oh['b'] = -1
oh['a'] = 1
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => oh).map{ |x| x }
assert_equal 4, docs.size
assert_equal 1, docs[0]['a']
assert_equal 3, docs[1]['a']
assert_equal 2, docs[2]['a']
assert_equal 4, docs[3]['a']
# TODO this will not pass due to known Mongo bug #898
# oh = OrderedHash.new
# oh['b'] = -1
# oh['a'] = 1
# docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => oh).map{ |x| x }
# assert_equal 4, docs.size
# assert_equal 1, docs[0]['a']
# assert_equal 3, docs[1]['a']
# assert_equal 2, docs[2]['a']
# assert_equal 4, docs[3]['a']
end
def test_find_limits
@coll.insert('b' => 2)
@coll.insert('c' => 3)
@coll.insert('d' => 4)
docs = @coll.find({}, :limit => 1).map{ |x| x }
assert_equal 1, docs.size
docs = @coll.find({}, :limit => 2).map{ |x| x }