From 0550945aa451930a8c57d5eac86bfd1e7d490203 Mon Sep 17 00:00:00 2001 From: Adrian Madrid Date: Thu, 18 Dec 2008 14:03:33 -0700 Subject: [PATCH] Made tests that were different same as upstream --- tests/test_db_api.rb | 53 +++++++++++-------------------------- tests/test_db_connection.rb | 2 +- 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/tests/test_db_api.rb b/tests/test_db_api.rb index 8931038..237249f 100644 --- a/tests/test_db_api.rb +++ b/tests/test_db_api.rb @@ -1,5 +1,4 @@ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib') - require 'mongo' require 'test/unit' @@ -12,7 +11,7 @@ class DBAPITest < Test::Unit::TestCase @db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test') @coll = @db.collection('test') @coll.clear - @r1 = @coll.insert('_id' => new_oid, 'a' => 1) # collection not created until it's used + @r1 = @coll.insert('a' => 1) # collection not created until it's used @coll_full_name = 'ruby-mongo-test.test' end @@ -27,8 +26,8 @@ class DBAPITest < Test::Unit::TestCase end def test_insert - @coll.insert('_id' => new_oid, 'a' => 2) - @coll.insert('_id' => new_oid, 'b' => 3) + @coll.insert('a' => 2) + @coll.insert('b' => 3) assert_equal 3, @coll.count docs = @coll.find().collect @@ -43,30 +42,14 @@ class DBAPITest < Test::Unit::TestCase assert docs.detect { |row| row['b'] == 4 } end - def test_inserted_id - doc = @coll.find().collect.first - assert_equal @r1['_id'], doc['_id'] - end - def test_find_simple - @r2 = @coll.insert('_id' => new_oid, 'a' => 2) - @r3 = @coll.insert('_id' => new_oid, 'b' => 3) + @r2 = @coll.insert('a' => 2) + @r3 = @coll.insert('b' => 3) # Check sizes docs = @coll.find().map assert_equal 3, docs.size assert_equal 3, @coll.count - # Find by id - docs = @coll.find('_id' => @r1['_id']).map - assert_equal 1, docs.size - doc = docs.first - assert_equal doc['_id'], @r1['_id'] - assert_equal doc['a'], @r1['a'] - # Find by id (same id again) - docs = @coll.find('_id' => @r1['_id']).map - assert_equal 1, docs.size - doc = docs.first - assert_equal doc['_id'], @r1['_id'] - assert_equal doc['a'], @r1['a'] + # Find by other value docs = @coll.find('a' => @r1['a']).map assert_equal 1, docs.size @@ -74,33 +57,33 @@ class DBAPITest < Test::Unit::TestCase assert_equal doc['_id'], @r1['_id'] assert_equal doc['a'], @r1['a'] end - + def test_find_advanced - @r2 = @coll.insert('_id' => new_oid, 'a' => 2) - @r3 = @coll.insert('_id' => new_oid, 'b' => 3) - + @coll.insert('a' => 2) + @coll.insert('b' => 3) + # Find by advanced query (less than) docs = @coll.find('a' => { '$lt' => 10 }).map assert_equal 2, docs.size assert docs.detect { |row| row['a'] == 1 } assert docs.detect { |row| row['a'] == 2 } - + # Find by advanced query (greater than) docs = @coll.find('a' => { '$gt' => 1 }).map assert_equal 1, docs.size assert docs.detect { |row| row['a'] == 2 } - + # Find by advanced query (less than or equal to) docs = @coll.find('a' => { '$lte' => 1 }).map assert_equal 1, docs.size assert docs.detect { |row| row['a'] == 1 } - + # Find by advanced query (greater than or equal to) docs = @coll.find('a' => { '$gte' => 1 }).map assert_equal 2, docs.size assert docs.detect { |row| row['a'] == 1 } assert docs.detect { |row| row['a'] == 2 } - + # Find by advanced query (between) docs = @coll.find('a' => { '$gt' => 1, '$lt' => 3 }).map assert_equal 1, docs.size @@ -150,8 +133,6 @@ class DBAPITest < Test::Unit::TestCase assert_equal 2, docs.size assert_equal 2, docs.first['a'] end - - # def test_ def test_close @db.close @@ -218,6 +199,7 @@ class DBAPITest < Test::Unit::TestCase @db.create_index(@coll.name, 'index_name', ['a']) list = @db.index_information(@coll.name) assert_equal 1, list.length + info = list[0] assert_equal 'index_name', info[:name] assert_equal 1, info[:keys]['a'] @@ -284,9 +266,4 @@ class DBAPITest < Test::Unit::TestCase assert @db.master? end - private - - def new_oid - XGen::Mongo::Driver::ObjectID.new - end end diff --git a/tests/test_db_connection.rb b/tests/test_db_connection.rb index 9743489..ea3e419 100644 --- a/tests/test_db_connection.rb +++ b/tests/test_db_connection.rb @@ -8,7 +8,7 @@ class DBConnectionTest < Test::Unit::TestCase def test_no_exceptions host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT - db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test') + db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-demo') coll = db.collection('test') coll.clear end