Merged wpiekutowski's commits to enable warnings
on test suite and clean up some code. Conflicts: test/cursor_test.rb
This commit is contained in:
commit
2bfe205c51
8
Rakefile
8
Rakefile
|
@ -77,41 +77,49 @@ namespace :test do
|
||||||
Rake::TestTask.new(:rs) do |t|
|
Rake::TestTask.new(:rs) do |t|
|
||||||
t.test_files = FileList['test/replica_sets/*_test.rb']
|
t.test_files = FileList['test/replica_sets/*_test.rb']
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
|
t.ruby_opts << '-w'
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::TestTask.new(:unit) do |t|
|
Rake::TestTask.new(:unit) do |t|
|
||||||
t.test_files = FileList['test/unit/*_test.rb']
|
t.test_files = FileList['test/unit/*_test.rb']
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
|
t.ruby_opts << '-w'
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::TestTask.new(:functional) do |t|
|
Rake::TestTask.new(:functional) do |t|
|
||||||
t.test_files = FileList['test/*_test.rb']
|
t.test_files = FileList['test/*_test.rb']
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
|
t.ruby_opts << '-w'
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::TestTask.new(:pooled_threading) do |t|
|
Rake::TestTask.new(:pooled_threading) do |t|
|
||||||
t.test_files = FileList['test/threading/*_test.rb']
|
t.test_files = FileList['test/threading/*_test.rb']
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
|
t.ruby_opts << '-w'
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::TestTask.new(:auto_reconnect) do |t|
|
Rake::TestTask.new(:auto_reconnect) do |t|
|
||||||
t.test_files = FileList['test/auxillary/autoreconnect_test.rb']
|
t.test_files = FileList['test/auxillary/autoreconnect_test.rb']
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
|
t.ruby_opts << '-w'
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::TestTask.new(:authentication) do |t|
|
Rake::TestTask.new(:authentication) do |t|
|
||||||
t.test_files = FileList['test/auxillary/authentication_test.rb']
|
t.test_files = FileList['test/auxillary/authentication_test.rb']
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
|
t.ruby_opts << '-w'
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::TestTask.new(:new_features) do |t|
|
Rake::TestTask.new(:new_features) do |t|
|
||||||
t.test_files = FileList['test/auxillary/1.4_features.rb']
|
t.test_files = FileList['test/auxillary/1.4_features.rb']
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
|
t.ruby_opts << '-w'
|
||||||
end
|
end
|
||||||
|
|
||||||
Rake::TestTask.new(:bson) do |t|
|
Rake::TestTask.new(:bson) do |t|
|
||||||
t.test_files = FileList['test/bson/*_test.rb']
|
t.test_files = FileList['test/bson/*_test.rb']
|
||||||
t.verbose = true
|
t.verbose = true
|
||||||
|
t.ruby_opts << '-w'
|
||||||
end
|
end
|
||||||
|
|
||||||
task :drop_databases do |t|
|
task :drop_databases do |t|
|
||||||
|
|
|
@ -245,7 +245,6 @@ module BSON
|
||||||
end
|
end
|
||||||
|
|
||||||
def dump
|
def dump
|
||||||
i = 0
|
|
||||||
@str.each_byte do |c, i|
|
@str.each_byte do |c, i|
|
||||||
$stderr.puts "#{'%04d' % i}: #{'%02x' % c} #{'%03o' % c} #{'%s' % c.chr} #{'%3d' % c}"
|
$stderr.puts "#{'%04d' % i}: #{'%02x' % c} #{'%03o' % c} #{'%s' % c.chr} #{'%3d' % c}"
|
||||||
i += 1
|
i += 1
|
||||||
|
|
|
@ -98,9 +98,9 @@ module BSON
|
||||||
|
|
||||||
# Check equality of this object id with another.
|
# Check equality of this object id with another.
|
||||||
#
|
#
|
||||||
# @param [Mongo::ObjectId] object_id
|
# @param [BSON::ObjectId] object_id
|
||||||
def eql?(object_id)
|
def eql?(object_id)
|
||||||
@data == object_id.instance_variable_get("@data")
|
object_id.kind_of?(BSON::ObjectId) and self.data == object_id.data
|
||||||
end
|
end
|
||||||
alias_method :==, :eql?
|
alias_method :==, :eql?
|
||||||
|
|
||||||
|
@ -119,13 +119,6 @@ module BSON
|
||||||
@data.dup
|
@data.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the array representation without cloning.
|
|
||||||
#
|
|
||||||
# @return [Array]
|
|
||||||
def data
|
|
||||||
@data
|
|
||||||
end
|
|
||||||
|
|
||||||
# Given a string representation of an ObjectId, return a new ObjectId
|
# Given a string representation of an ObjectId, return a new ObjectId
|
||||||
# with that value.
|
# with that value.
|
||||||
#
|
#
|
||||||
|
|
|
@ -34,6 +34,8 @@ module Mongo
|
||||||
#
|
#
|
||||||
# @core cursors constructor_details
|
# @core cursors constructor_details
|
||||||
def initialize(collection, opts={})
|
def initialize(collection, opts={})
|
||||||
|
@cursor_id = nil
|
||||||
|
|
||||||
@db = collection.db
|
@db = collection.db
|
||||||
@collection = collection
|
@collection = collection
|
||||||
@connection = @db.connection
|
@connection = @db.connection
|
||||||
|
@ -313,8 +315,8 @@ module Mongo
|
||||||
def query_options_hash
|
def query_options_hash
|
||||||
{ :selector => @selector,
|
{ :selector => @selector,
|
||||||
:fields => @fields,
|
:fields => @fields,
|
||||||
:skip => @skip_num,
|
:skip => @skip,
|
||||||
:limit => @limit_num,
|
:limit => @limit,
|
||||||
:order => @order,
|
:order => @order,
|
||||||
:hint => @hint,
|
:hint => @hint,
|
||||||
:snapshot => @snapshot,
|
:snapshot => @snapshot,
|
||||||
|
|
|
@ -335,8 +335,8 @@ module Mongo
|
||||||
@files_id = opts.delete(:_id) || BSON::ObjectId.new
|
@files_id = opts.delete(:_id) || BSON::ObjectId.new
|
||||||
@content_type = opts.delete(:content_type) || (defined? MIME) && get_content_type || DEFAULT_CONTENT_TYPE
|
@content_type = opts.delete(:content_type) || (defined? MIME) && get_content_type || DEFAULT_CONTENT_TYPE
|
||||||
@chunk_size = opts.delete(:chunk_size) || DEFAULT_CHUNK_SIZE
|
@chunk_size = opts.delete(:chunk_size) || DEFAULT_CHUNK_SIZE
|
||||||
@metadata = opts.delete(:metadata) if opts[:metadata]
|
@metadata = opts.delete(:metadata)
|
||||||
@aliases = opts.delete(:aliases) if opts[:aliases]
|
@aliases = opts.delete(:aliases)
|
||||||
@file_length = 0
|
@file_length = 0
|
||||||
opts.each {|k, v| self[k] = v}
|
opts.each {|k, v| self[k] = v}
|
||||||
check_existing_file if @safe
|
check_existing_file if @safe
|
||||||
|
|
|
@ -168,10 +168,6 @@ module Mongo
|
||||||
return socket
|
return socket
|
||||||
else
|
else
|
||||||
# Otherwise, wait
|
# Otherwise, wait
|
||||||
if @logger
|
|
||||||
@logger.warn "MONGODB Waiting for available connection; " +
|
|
||||||
"#{@checked_out.size} of #{@size} connections checked out."
|
|
||||||
end
|
|
||||||
@queue.wait(@connection_mutex)
|
@queue.wait(@connection_mutex)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Mongo
|
||||||
class URIParser
|
class URIParser
|
||||||
|
|
||||||
DEFAULT_PORT = 27017
|
DEFAULT_PORT = 27017
|
||||||
MONGODB_URI_MATCHER = /(([-_.\w\d]+):([^@]+)@)?([-.\w\d]+)(:([\w\d]+))?(\/([-\d\w]+))?/
|
MONGODB_URI_MATCHER = /(([-.\w]+):([^@]+)@)?([-.\w]+)(:([\w]+))?(\/([-\w]+))?/
|
||||||
MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]"
|
MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]"
|
||||||
SPEC_ATTRS = [:nodes, :auths]
|
SPEC_ATTRS = [:nodes, :auths]
|
||||||
OPT_ATTRS = [:connect, :replicaset, :slaveok, :safe, :w, :wtimeout, :fsync]
|
OPT_ATTRS = [:connect, :replicaset, :slaveok, :safe, :w, :wtimeout, :fsync]
|
||||||
|
@ -142,7 +142,11 @@ module Mongo
|
||||||
# This method uses the lambdas defined in OPT_VALID and OPT_CONV to validate
|
# This method uses the lambdas defined in OPT_VALID and OPT_CONV to validate
|
||||||
# and convert the given options.
|
# and convert the given options.
|
||||||
def parse_options(opts)
|
def parse_options(opts)
|
||||||
|
# initialize instance variables for available options
|
||||||
|
OPT_VALID.keys.each { |k| instance_variable_set("@#{k}", nil) }
|
||||||
|
|
||||||
return unless opts
|
return unless opts
|
||||||
|
|
||||||
separator = opts.include?('&') ? '&' : ';'
|
separator = opts.include?('&') ? '&' : ';'
|
||||||
opts.split(separator).each do |attr|
|
opts.split(separator).each do |attr|
|
||||||
key, value = attr.split('=')
|
key, value = attr.split('=')
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
# encoding:utf-8
|
# encoding:utf-8
|
||||||
require './test/test_helper'
|
require './test/test_helper'
|
||||||
require 'complex'
|
|
||||||
|
if RUBY_VERSION < '1.9'
|
||||||
|
require 'complex'
|
||||||
|
require 'rational'
|
||||||
|
end
|
||||||
require 'bigdecimal'
|
require 'bigdecimal'
|
||||||
require 'rational'
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'active_support/core_ext'
|
require 'active_support/core_ext'
|
||||||
|
@ -134,14 +137,14 @@ class BSONTest < Test::Unit::TestCase
|
||||||
str = "壁に耳あり、障子に目あり"
|
str = "壁に耳あり、障子に目あり"
|
||||||
bson = BSON::BSON_CODER.serialize("x" => str)
|
bson = BSON::BSON_CODER.serialize("x" => str)
|
||||||
|
|
||||||
Encoding.default_internal = 'EUC-JP'
|
silently { Encoding.default_internal = 'EUC-JP' }
|
||||||
out = BSON::BSON_CODER.deserialize(bson)["x"]
|
out = BSON::BSON_CODER.deserialize(bson)["x"]
|
||||||
|
|
||||||
assert_equal Encoding.default_internal, out.encoding
|
assert_equal Encoding.default_internal, out.encoding
|
||||||
assert_equal str.encode('EUC-JP'), out
|
assert_equal str.encode('EUC-JP'), out
|
||||||
assert_equal str, out.encode(str.encoding)
|
assert_equal str, out.encode(str.encoding)
|
||||||
ensure
|
ensure
|
||||||
Encoding.default_internal = before_enc
|
silently { Encoding.default_internal = before_enc }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -161,12 +164,12 @@ class BSONTest < Test::Unit::TestCase
|
||||||
assert_doc_pass(doc)
|
assert_doc_pass(doc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_double
|
def test_double
|
||||||
doc = {'doc' => 41.25}
|
doc = {'doc' => 41.25}
|
||||||
assert_doc_pass(doc)
|
assert_doc_pass(doc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_int
|
def test_int
|
||||||
doc = {'doc' => 42}
|
doc = {'doc' => 42}
|
||||||
assert_doc_pass(doc)
|
assert_doc_pass(doc)
|
||||||
|
|
||||||
|
@ -283,7 +286,7 @@ class BSONTest < Test::Unit::TestCase
|
||||||
ensure
|
ensure
|
||||||
if !invalid_date.is_a? Time
|
if !invalid_date.is_a? Time
|
||||||
assert_equal InvalidDocument, e.class
|
assert_equal InvalidDocument, e.class
|
||||||
assert_match /UTC Time/, e.message
|
assert_match(/UTC Time/, e.message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -445,7 +448,7 @@ class BSONTest < Test::Unit::TestCase
|
||||||
rescue => e
|
rescue => e
|
||||||
ensure
|
ensure
|
||||||
assert_equal InvalidDocument, e.class
|
assert_equal InvalidDocument, e.class
|
||||||
assert_match /Cannot serialize/, e.message
|
assert_match(/Cannot serialize/, e.message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -373,8 +373,8 @@ class TestCollection < Test::Unit::TestCase
|
||||||
|
|
||||||
docs = [{"hello" => "world"}, {"hello" => "world"}]
|
docs = [{"hello" => "world"}, {"hello" => "world"}]
|
||||||
@@test.insert(docs)
|
@@test.insert(docs)
|
||||||
docs.each do |doc|
|
docs.each do |d|
|
||||||
assert(doc.include?(:_id))
|
assert(d.include?(:_id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class TestConnection < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_server_version
|
def test_server_version
|
||||||
assert_match /\d\.\d+(\.\d+)?/, @conn.server_version.to_s
|
assert_match(/\d\.\d+(\.\d+)?/, @conn.server_version.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_database_names
|
def test_invalid_database_names
|
||||||
|
|
|
@ -40,11 +40,11 @@ class ConversionsTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_negative_one
|
def test_sort_value_when_value_is_negative_one
|
||||||
assert_equal -1, sort_value(-1)
|
assert_equal(-1, sort_value(-1))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_negative_one_as_a_string
|
def test_sort_value_when_value_is_negative_one_as_a_string
|
||||||
assert_equal -1, sort_value("-1")
|
assert_equal(-1, sort_value("-1"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_ascending
|
def test_sort_value_when_value_is_ascending
|
||||||
|
@ -80,35 +80,35 @@ class ConversionsTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_descending
|
def test_sort_value_when_value_is_descending
|
||||||
assert_equal -1, sort_value("descending")
|
assert_equal(-1, sort_value("descending"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_desc
|
def test_sort_value_when_value_is_desc
|
||||||
assert_equal -1, sort_value("desc")
|
assert_equal(-1, sort_value("desc"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_uppercase_descending
|
def test_sort_value_when_value_is_uppercase_descending
|
||||||
assert_equal -1, sort_value("DESCENDING")
|
assert_equal(-1, sort_value("DESCENDING"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_uppercase_desc
|
def test_sort_value_when_value_is_uppercase_desc
|
||||||
assert_equal -1, sort_value("DESC")
|
assert_equal(-1, sort_value("DESC"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_symbol_descending
|
def test_sort_value_when_value_is_symbol_descending
|
||||||
assert_equal -1, sort_value(:descending)
|
assert_equal(-1, sort_value(:descending))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_symbol_desc
|
def test_sort_value_when_value_is_symbol_desc
|
||||||
assert_equal -1, sort_value(:desc)
|
assert_equal(-1, sort_value(:desc))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_uppercase_symbol_descending
|
def test_sort_value_when_value_is_uppercase_symbol_descending
|
||||||
assert_equal -1, sort_value(:DESCENDING)
|
assert_equal(-1, sort_value(:DESCENDING))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_uppercase_symbol_desc
|
def test_sort_value_when_value_is_uppercase_symbol_desc
|
||||||
assert_equal -1, sort_value(:DESC)
|
assert_equal(-1, sort_value(:DESC))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sort_value_when_value_is_invalid
|
def test_sort_value_when_value_is_invalid
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require './test/test_helper'
|
require './test/test_helper'
|
||||||
require 'logger'
|
require 'logger'
|
||||||
|
|
||||||
class CursorTest < Test::Unit::TestCase
|
class CursorFailTest < Test::Unit::TestCase
|
||||||
|
|
||||||
include Mongo
|
include Mongo
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require './test/test_helper'
|
require './test/test_helper'
|
||||||
require 'logger'
|
require 'logger'
|
||||||
|
|
||||||
class CursorTest < Test::Unit::TestCase
|
class CursorMessageTest < Test::Unit::TestCase
|
||||||
|
|
||||||
include Mongo
|
include Mongo
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ class CursorTest < Test::Unit::TestCase
|
||||||
results = @@coll.find.sort([:n, :asc]).to_a
|
results = @@coll.find.sort([:n, :asc]).to_a
|
||||||
|
|
||||||
assert_equal MinKey.new, results[0]['n']
|
assert_equal MinKey.new, results[0]['n']
|
||||||
assert_equal -1000000, results[1]['n']
|
assert_equal(-1000000, results[1]['n'])
|
||||||
assert_equal 1000000, results[2]['n']
|
assert_equal 1000000, results[2]['n']
|
||||||
assert_equal MaxKey.new, results[3]['n']
|
assert_equal MaxKey.new, results[3]['n']
|
||||||
end
|
end
|
||||||
|
@ -171,8 +171,8 @@ class CursorTest < Test::Unit::TestCase
|
||||||
cursor = Cursor.new(@@coll, :timeout => false)
|
cursor = Cursor.new(@@coll, :timeout => false)
|
||||||
assert_equal false, cursor.timeout
|
assert_equal false, cursor.timeout
|
||||||
|
|
||||||
@@coll.find({}, :timeout => false) do |cursor|
|
@@coll.find({}, :timeout => false) do |c|
|
||||||
assert_equal false, cursor.timeout
|
assert_equal false, c.timeout
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -239,7 +239,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
names = @@db.collection_names
|
names = @@db.collection_names
|
||||||
assert names.length >= 2
|
assert names.length >= 2
|
||||||
assert names.include?(@@coll.name)
|
assert names.include?(@@coll.name)
|
||||||
assert names.include?('mongo-ruby-test.test2')
|
assert names.include?('test2')
|
||||||
ensure
|
ensure
|
||||||
@@db.drop_collection('test2')
|
@@db.drop_collection('test2')
|
||||||
end
|
end
|
||||||
|
@ -621,7 +621,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
assert_equal("mike", @@coll.find_one()["hello"])
|
assert_equal("mike", @@coll.find_one()["hello"])
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_collection_names
|
def test_collection_names_errors
|
||||||
assert_raise TypeError do
|
assert_raise TypeError do
|
||||||
@@db.collection(5)
|
@@db.collection(5)
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ class DBTest < Test::Unit::TestCase
|
||||||
@@db.collection('test').insert('a' => 1)
|
@@db.collection('test').insert('a' => 1)
|
||||||
fail "expected 'NilClass' exception"
|
fail "expected 'NilClass' exception"
|
||||||
rescue => ex
|
rescue => ex
|
||||||
assert_match /NilClass/, ex.to_s
|
assert_match(/NilClass/, ex.to_s)
|
||||||
ensure
|
ensure
|
||||||
@@db = standard_connection.db(MONGO_TEST_DB)
|
@@db = standard_connection.db(MONGO_TEST_DB)
|
||||||
@@users = @@db.collection('system.users')
|
@@users = @@db.collection('system.users')
|
||||||
|
@ -104,7 +104,7 @@ class DBTest < Test::Unit::TestCase
|
||||||
db.pk_factory = Object.new
|
db.pk_factory = Object.new
|
||||||
fail "error: expected exception"
|
fail "error: expected exception"
|
||||||
rescue => ex
|
rescue => ex
|
||||||
assert_match /Cannot change/, ex.to_s
|
assert_match(/Cannot change/, ex.to_s)
|
||||||
ensure
|
ensure
|
||||||
conn.close
|
conn.close
|
||||||
end
|
end
|
||||||
|
@ -280,7 +280,7 @@ class DBTest < Test::Unit::TestCase
|
||||||
assert_not_nil doc
|
assert_not_nil doc
|
||||||
result = doc['result']
|
result = doc['result']
|
||||||
assert_not_nil result
|
assert_not_nil result
|
||||||
assert_match /firstExtent/, result
|
assert_match(/firstExtent/, result)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
require './test/test_helper'
|
require './test/test_helper'
|
||||||
include Mongo
|
include Mongo
|
||||||
|
|
||||||
|
def read_and_write_stream(filename, read_length, opts={})
|
||||||
|
io = File.open(File.join(File.dirname(__FILE__), 'data', filename), 'r')
|
||||||
|
id = @grid.put(io, opts.merge!(:filename => filename + read_length.to_s))
|
||||||
|
file = @grid.get(id)
|
||||||
|
io.rewind
|
||||||
|
data = io.read
|
||||||
|
if data.respond_to?(:force_encoding)
|
||||||
|
data.force_encoding("binary")
|
||||||
|
end
|
||||||
|
read_data = ""
|
||||||
|
while(chunk = file.read(read_length))
|
||||||
|
read_data << chunk
|
||||||
|
end
|
||||||
|
assert_equal data.length, read_data.length
|
||||||
|
end
|
||||||
|
|
||||||
class GridTest < Test::Unit::TestCase
|
class GridTest < Test::Unit::TestCase
|
||||||
context "Tests:" do
|
context "Tests:" do
|
||||||
setup do
|
setup do
|
||||||
|
@ -161,22 +177,6 @@ class GridTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "Streaming: " do || {}
|
context "Streaming: " do || {}
|
||||||
setup do
|
setup do
|
||||||
def read_and_write_stream(filename, read_length, opts={})
|
|
||||||
io = File.open(File.join(File.dirname(__FILE__), 'data', filename), 'r')
|
|
||||||
id = @grid.put(io, opts.merge!(:filename => filename + read_length.to_s))
|
|
||||||
file = @grid.get(id)
|
|
||||||
io.rewind
|
|
||||||
data = io.read
|
|
||||||
if data.respond_to?(:force_encoding)
|
|
||||||
data.force_encoding("binary")
|
|
||||||
end
|
|
||||||
read_data = ""
|
|
||||||
while(chunk = file.read(read_length))
|
|
||||||
read_data << chunk
|
|
||||||
end
|
|
||||||
assert_equal data.length, read_data.length
|
|
||||||
end
|
|
||||||
|
|
||||||
@grid = Grid.new(@db, 'test-fs')
|
@grid = Grid.new(@db, 'test-fs')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,19 +38,6 @@ class Hash
|
||||||
|
|
||||||
alias_method :to_options, :symbolize_keys
|
alias_method :to_options, :symbolize_keys
|
||||||
#alias_method :to_options!, :symbolize_keys!
|
#alias_method :to_options!, :symbolize_keys!
|
||||||
|
|
||||||
# Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch.
|
|
||||||
# Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols
|
|
||||||
# as keys, this will fail.
|
|
||||||
#
|
|
||||||
# ==== Examples
|
|
||||||
# { :name => "Rob", :years => "28" }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key(s): years"
|
|
||||||
# { :name => "Rob", :age => "28" }.assert_valid_keys("name", "age") # => raises "ArgumentError: Unknown key(s): name, age"
|
|
||||||
# { :name => "Rob", :age => "28" }.assert_valid_keys(:name, :age) # => passes, raises nothing
|
|
||||||
def assert_valid_keys(*valid_keys)
|
|
||||||
unknown_keys = keys - [valid_keys].flatten
|
|
||||||
raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module ActiveSupport
|
module ActiveSupport
|
||||||
|
|
|
@ -3,12 +3,20 @@ require 'rubygems' if ENV['C_EXT']
|
||||||
require 'mongo'
|
require 'mongo'
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
|
def silently
|
||||||
|
warn_level = $VERBOSE
|
||||||
|
$VERBOSE = nil
|
||||||
|
result = yield
|
||||||
|
$VERBOSE = warn_level
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'shoulda'
|
silently { require 'shoulda' }
|
||||||
require 'mocha'
|
require 'mocha'
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
puts <<MSG
|
puts <<MSG
|
||||||
|
|
||||||
This test suite requires shoulda and mocha.
|
This test suite requires shoulda and mocha.
|
||||||
You can install them as follows:
|
You can install them as follows:
|
||||||
|
@ -16,7 +24,8 @@ You can install them as follows:
|
||||||
gem install mocha
|
gem install mocha
|
||||||
|
|
||||||
MSG
|
MSG
|
||||||
exit
|
|
||||||
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'bson_ext/cbson' if !(RUBY_PLATFORM =~ /java/) && ENV['C_EXT']
|
require 'bson_ext/cbson' if !(RUBY_PLATFORM =~ /java/) && ENV['C_EXT']
|
||||||
|
@ -69,6 +78,16 @@ class Test::Unit::TestCase
|
||||||
self.class.mongo_port
|
self.class.mongo_port
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new_mock_socket(host='localhost', port=27017)
|
||||||
|
socket = Object.new
|
||||||
|
socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
||||||
|
socket.stubs(:close)
|
||||||
|
socket
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_mock_db
|
||||||
|
db = Object.new
|
||||||
|
end
|
||||||
|
|
||||||
def assert_raise_error(klass, message)
|
def assert_raise_error(klass, message)
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path('./test/test_helper.rb')
|
require './test/test_helper'
|
||||||
|
|
||||||
class CollectionTest < Test::Unit::TestCase
|
class CollectionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
|
|
|
@ -3,19 +3,6 @@ include Mongo
|
||||||
|
|
||||||
class ConnectionTest < Test::Unit::TestCase
|
class ConnectionTest < Test::Unit::TestCase
|
||||||
context "Initialization: " do
|
context "Initialization: " do
|
||||||
setup do
|
|
||||||
def new_mock_socket(host='localhost', port=27017)
|
|
||||||
socket = Object.new
|
|
||||||
socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
|
||||||
socket.stubs(:close)
|
|
||||||
socket
|
|
||||||
end
|
|
||||||
|
|
||||||
def new_mock_db
|
|
||||||
db = Object.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "given a single node" do
|
context "given a single node" do
|
||||||
setup do
|
setup do
|
||||||
@conn = Connection.new('localhost', 27017, :connect => false)
|
@conn = Connection.new('localhost', 27017, :connect => false)
|
||||||
|
|
|
@ -12,28 +12,32 @@ class CursorTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set timeout" do
|
should "set timeout" do
|
||||||
assert_equal true, @cursor.timeout
|
assert @cursor.timeout
|
||||||
|
assert @cursor.query_options_hash[:timeout]
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set selector" do
|
should "set selector" do
|
||||||
assert @cursor.selector == {}
|
assert_equal({}, @cursor.selector)
|
||||||
|
|
||||||
@cursor = Cursor.new(@collection, :selector => {:name => "Jones"})
|
@cursor = Cursor.new(@collection, :selector => {:name => "Jones"})
|
||||||
assert @cursor.selector == {:name => "Jones"}
|
assert_equal({:name => "Jones"}, @cursor.selector)
|
||||||
|
assert_equal({:name => "Jones"}, @cursor.query_options_hash[:selector])
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set fields" do
|
should "set fields" do
|
||||||
assert_nil @cursor.fields
|
assert_nil @cursor.fields
|
||||||
|
|
||||||
@cursor = Cursor.new(@collection, :fields => [:name, :date])
|
@cursor = Cursor.new(@collection, :fields => [:name, :date])
|
||||||
assert @cursor.fields == {:name => 1, :date => 1}
|
assert_equal({:name => 1, :date => 1}, @cursor.fields)
|
||||||
|
assert_equal({:name => 1, :date => 1}, @cursor.query_options_hash[:fields])
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set mix fields 0 and 1" do
|
should "set mix fields 0 and 1" do
|
||||||
assert_nil @cursor.fields
|
assert_nil @cursor.fields
|
||||||
|
|
||||||
@cursor = Cursor.new(@collection, :fields => {:name => 1, :date => 0})
|
@cursor = Cursor.new(@collection, :fields => {:name => 1, :date => 0})
|
||||||
assert @cursor.fields == {:name => 1, :date => 0}
|
assert_equal({:name => 1, :date => 0}, @cursor.fields)
|
||||||
|
assert_equal({:name => 1, :date => 0}, @cursor.query_options_hash[:fields])
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set limit" do
|
should "set limit" do
|
||||||
|
@ -41,6 +45,7 @@ class CursorTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@cursor = Cursor.new(@collection, :limit => 10)
|
@cursor = Cursor.new(@collection, :limit => 10)
|
||||||
assert_equal 10, @cursor.limit
|
assert_equal 10, @cursor.limit
|
||||||
|
assert_equal 10, @cursor.query_options_hash[:limit]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,6 +54,7 @@ class CursorTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@cursor = Cursor.new(@collection, :skip => 5)
|
@cursor = Cursor.new(@collection, :skip => 5)
|
||||||
assert_equal 5, @cursor.skip
|
assert_equal 5, @cursor.skip
|
||||||
|
assert_equal 5, @cursor.query_options_hash[:skip]
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set sort order" do
|
should "set sort order" do
|
||||||
|
@ -56,6 +62,7 @@ class CursorTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@cursor = Cursor.new(@collection, :order => "last_name")
|
@cursor = Cursor.new(@collection, :order => "last_name")
|
||||||
assert_equal "last_name", @cursor.order
|
assert_equal "last_name", @cursor.order
|
||||||
|
assert_equal "last_name", @cursor.query_options_hash[:order]
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set hint" do
|
should "set hint" do
|
||||||
|
@ -63,6 +70,7 @@ class CursorTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@cursor = Cursor.new(@collection, :hint => "name")
|
@cursor = Cursor.new(@collection, :hint => "name")
|
||||||
assert_equal "name", @cursor.hint
|
assert_equal "name", @cursor.hint
|
||||||
|
assert_equal "name", @cursor.query_options_hash[:hint]
|
||||||
end
|
end
|
||||||
|
|
||||||
should "cache full collection name" do
|
should "cache full collection name" do
|
||||||
|
@ -72,7 +80,9 @@ class CursorTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "Query fields" do
|
context "Query fields" do
|
||||||
setup do
|
setup do
|
||||||
@connection = stub(:class => Collection, :logger => @logger)
|
@logger = mock()
|
||||||
|
@logger.stubs(:debug)
|
||||||
|
@connection = stub(:class => Connection, :logger => @logger)
|
||||||
@db = stub(:slave_ok? => true, :name => "testing", :connection => @connection)
|
@db = stub(:slave_ok? => true, :name => "testing", :connection => @connection)
|
||||||
@collection = stub(:db => @db, :name => "items")
|
@collection = stub(:db => @db, :name => "items")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
require './test/test_helper'
|
require './test/test_helper'
|
||||||
|
|
||||||
|
def insert_message(db, documents)
|
||||||
|
documents = [documents] unless documents.is_a?(Array)
|
||||||
|
message = ByteBuffer.new
|
||||||
|
message.put_int(0)
|
||||||
|
Mongo::BSON_CODER.serialize_cstr(message, "#{db.name}.test")
|
||||||
|
documents.each { |doc| message.put_array(Mongo::BSON_CODER.new.serialize(doc, true).to_a) }
|
||||||
|
message = db.add_message_headers(Mongo::Constants::OP_INSERT, message)
|
||||||
|
end
|
||||||
|
|
||||||
class DBTest < Test::Unit::TestCase
|
class DBTest < Test::Unit::TestCase
|
||||||
context "DBTest: " do
|
context "DBTest: " do
|
||||||
setup do
|
|
||||||
def insert_message(db, documents)
|
|
||||||
documents = [documents] unless documents.is_a?(Array)
|
|
||||||
message = ByteBuffer.new
|
|
||||||
message.put_int(0)
|
|
||||||
Mongo::BSON_CODER..serialize_cstr(message, "#{db.name}.test")
|
|
||||||
documents.each { |doc| message.put_array(Mongo::BSON_CODER.new.serialize(doc, true).to_a) }
|
|
||||||
message = db.add_message_headers(Mongo::Constants::OP_INSERT, message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "DB commands" do
|
context "DB commands" do
|
||||||
setup do
|
setup do
|
||||||
@conn = stub()
|
@conn = stub()
|
||||||
|
|
|
@ -3,19 +3,6 @@ include Mongo
|
||||||
|
|
||||||
class ReplSetConnectionTest < Test::Unit::TestCase
|
class ReplSetConnectionTest < Test::Unit::TestCase
|
||||||
context "Initialization: " do
|
context "Initialization: " do
|
||||||
setup do
|
|
||||||
def new_mock_socket(host='localhost', port=27017)
|
|
||||||
socket = Object.new
|
|
||||||
socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
|
|
||||||
socket.stubs(:close)
|
|
||||||
socket
|
|
||||||
end
|
|
||||||
|
|
||||||
def new_mock_db
|
|
||||||
db = Object.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "connecting to a replica set" do
|
context "connecting to a replica set" do
|
||||||
setup do
|
setup do
|
||||||
TCPSocket.stubs(:new).returns(new_mock_socket('localhost', 27017))
|
TCPSocket.stubs(:new).returns(new_mock_socket('localhost', 27017))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require File.expand_path('./test/test_helper.rb')
|
require './test/test_helper'
|
||||||
|
|
||||||
class SafeTest < Test::Unit::TestCase
|
class SafeTest < Test::Unit::TestCase
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue