From 3ff4f75270b9f01cdea2821e9c9cad2e647bb9ae Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 15:33:33 +0100 Subject: [PATCH 01/34] Enable warnings in test:bson --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 65de58c..2abc332 100644 --- a/Rakefile +++ b/Rakefile @@ -112,6 +112,7 @@ namespace :test do Rake::TestTask.new(:bson) do |t| t.test_files = FileList['test/bson/*_test.rb'] t.verbose = true + t.ruby_opts << '-w' end task :drop_databases do |t| From e6b607491054904a55ae50e1da461beb2db96e52 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 15:34:11 +0100 Subject: [PATCH 02/34] Remove unneeded variable --- lib/bson/byte_buffer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/bson/byte_buffer.rb b/lib/bson/byte_buffer.rb index 26d1bea..e548cd4 100644 --- a/lib/bson/byte_buffer.rb +++ b/lib/bson/byte_buffer.rb @@ -245,7 +245,6 @@ module BSON end def dump - i = 0 @str.each_byte do |c, i| $stderr.puts "#{'%04d' % i}: #{'%02x' % c} #{'%03o' % c} #{'%s' % c.chr} #{'%3d' % c}" i += 1 From 730118539e00186258208e52b8406be2b229cb7b Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 15:35:22 +0100 Subject: [PATCH 03/34] Remove duplicated #data reader from BSON::ObjectId --- lib/bson/types/object_id.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/bson/types/object_id.rb b/lib/bson/types/object_id.rb index 8813598..fcb0e3a 100644 --- a/lib/bson/types/object_id.rb +++ b/lib/bson/types/object_id.rb @@ -105,13 +105,6 @@ module BSON @data.dup end - # Get the array representation without cloning. - # - # @return [Array] - def data - @data - end - # Given a string representation of an ObjectId, return a new ObjectId # with that value. # From b541972bdc77ac3f543ea2ab11ab40303e7941fa Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 15:36:15 +0100 Subject: [PATCH 04/34] Remove duplicating character classes from URI regexp in Mongo::URIParser --- lib/mongo/util/uri_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mongo/util/uri_parser.rb b/lib/mongo/util/uri_parser.rb index 3a76f8d..2be31f2 100644 --- a/lib/mongo/util/uri_parser.rb +++ b/lib/mongo/util/uri_parser.rb @@ -20,7 +20,7 @@ module Mongo class URIParser 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]" SPEC_ATTRS = [:nodes, :auths] OPT_ATTRS = [:connect, :replicaset, :slaveok, :safe, :w, :wtimeout, :fsync] From 57d95c9ab3a8a15d348cfc55a20a05d50e773189 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 15:37:31 +0100 Subject: [PATCH 05/34] Don't require 'complex' and 'rational' libs in Ruby 1.9 - they're in core already --- test/bson/bson_test.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/bson/bson_test.rb b/test/bson/bson_test.rb index bf652d7..869f638 100644 --- a/test/bson/bson_test.rb +++ b/test/bson/bson_test.rb @@ -1,8 +1,11 @@ # encoding:utf-8 require './test/test_helper' -require 'complex' + +if RUBY_VERSION < '1.9' + require 'complex' + require 'rational' +end require 'bigdecimal' -require 'rational' begin require 'active_support/core_ext' From 0f3fda805eb7d0db9107dd81d22ca2bfe1f3d0e9 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 15:38:21 +0100 Subject: [PATCH 06/34] Silence shoulda warnings --- test/test_helper.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index af35fc0..9f36955 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,9 +3,17 @@ require 'rubygems' if ENV['C_EXT'] require 'mongo' require 'test/unit' +def silently + warn_level = $VERBOSE + $VERBOSE = nil + result = yield + $VERBOSE = warn_level + result +end + begin require 'rubygems' - require 'shoulda' + silently { require 'shoulda' } require 'mocha' rescue LoadError puts < Date: Sun, 20 Feb 2011 15:39:09 +0100 Subject: [PATCH 07/34] Fix indentation --- test/test_helper.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 9f36955..83167a5 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,8 +15,8 @@ begin require 'rubygems' silently { require 'shoulda' } require 'mocha' - rescue LoadError - puts < Date: Sun, 20 Feb 2011 15:39:46 +0100 Subject: [PATCH 08/34] Silence Encoding.default_internal= warnings --- test/bson/bson_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/bson/bson_test.rb b/test/bson/bson_test.rb index 869f638..9800edd 100644 --- a/test/bson/bson_test.rb +++ b/test/bson/bson_test.rb @@ -137,14 +137,14 @@ class BSONTest < Test::Unit::TestCase 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"] assert_equal Encoding.default_internal, out.encoding assert_equal str.encode('EUC-JP'), out assert_equal str, out.encode(str.encoding) ensure - Encoding.default_internal = before_enc + silently { Encoding.default_internal = before_enc } end end From 08d99c08bbbd44228bc0760ad002694e1cbc5582 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 15:40:15 +0100 Subject: [PATCH 09/34] Fix indentation --- test/bson/bson_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/bson/bson_test.rb b/test/bson/bson_test.rb index 9800edd..e04871c 100644 --- a/test/bson/bson_test.rb +++ b/test/bson/bson_test.rb @@ -164,12 +164,12 @@ class BSONTest < Test::Unit::TestCase assert_doc_pass(doc) end - def test_double - doc = {'doc' => 41.25} - assert_doc_pass(doc) - end + def test_double + doc = {'doc' => 41.25} + assert_doc_pass(doc) + end - def test_int + def test_int doc = {'doc' => 42} assert_doc_pass(doc) From ea180939fd751cf82d44ac4d6027307ad5c4978a Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 15:40:54 +0100 Subject: [PATCH 10/34] Add parenthesis where Ruby thinks they're a good idea --- test/bson/bson_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/bson/bson_test.rb b/test/bson/bson_test.rb index e04871c..0359f0f 100644 --- a/test/bson/bson_test.rb +++ b/test/bson/bson_test.rb @@ -280,7 +280,7 @@ class BSONTest < Test::Unit::TestCase ensure if !invalid_date.is_a? Time assert_equal InvalidDocument, e.class - assert_match /UTC Time/, e.message + assert_match(/UTC Time/, e.message) end end end @@ -442,7 +442,7 @@ class BSONTest < Test::Unit::TestCase rescue => e ensure assert_equal InvalidDocument, e.class - assert_match /Cannot serialize/, e.message + assert_match(/Cannot serialize/, e.message) end end end From 479438469dc17f27c1ee2072869c32884efaadea Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 15:41:35 +0100 Subject: [PATCH 11/34] Remove duplicated Hash#assert_valid_keys --- test/support/hash_with_indifferent_access.rb | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/support/hash_with_indifferent_access.rb b/test/support/hash_with_indifferent_access.rb index 498254d..e3d5caf 100644 --- a/test/support/hash_with_indifferent_access.rb +++ b/test/support/hash_with_indifferent_access.rb @@ -38,19 +38,6 @@ class Hash 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 module ActiveSupport From 37f8ff2c9b2818d0ada9b6dade5dcfc480fa89d4 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sat, 19 Feb 2011 23:17:21 +0100 Subject: [PATCH 12/34] Enable warnings in test:rs --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 2abc332..a788c04 100644 --- a/Rakefile +++ b/Rakefile @@ -77,6 +77,7 @@ namespace :test do Rake::TestTask.new(:rs) do |t| t.test_files = FileList['test/replica_sets/*_test.rb'] t.verbose = true + t.ruby_opts << '-w' end Rake::TestTask.new(:unit) do |t| From c0b03251000b17cbb6e61b30a8964db7d909fae1 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 15:57:13 +0100 Subject: [PATCH 13/34] Enable warnings in test:unit --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index a788c04..68bc955 100644 --- a/Rakefile +++ b/Rakefile @@ -83,6 +83,7 @@ namespace :test do Rake::TestTask.new(:unit) do |t| t.test_files = FileList['test/unit/*_test.rb'] t.verbose = true + t.ruby_opts << '-w' end Rake::TestTask.new(:functional) do |t| From 6cdae6dc7e852443b4aada50cbad7467b978179c Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 16:00:06 +0100 Subject: [PATCH 14/34] Move helper methods away from tests setup to avoid redefinition on each test run --- test/test_helper.rb | 12 +++++++++++- test/unit/connection_test.rb | 13 ------------- test/unit/db_test.rb | 20 +++++++++----------- test/unit/repl_set_connection_test.rb | 13 ------------- 4 files changed, 20 insertions(+), 38 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 83167a5..6101e90 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -78,7 +78,17 @@ class Test::Unit::TestCase self.class.mongo_port 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) begin yield diff --git a/test/unit/connection_test.rb b/test/unit/connection_test.rb index 0491f40..ebb3068 100644 --- a/test/unit/connection_test.rb +++ b/test/unit/connection_test.rb @@ -3,19 +3,6 @@ include Mongo class ConnectionTest < Test::Unit::TestCase 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 setup do @conn = Connection.new('localhost', 27017, :connect => false) diff --git a/test/unit/db_test.rb b/test/unit/db_test.rb index e84086b..5b41808 100644 --- a/test/unit/db_test.rb +++ b/test/unit/db_test.rb @@ -1,18 +1,16 @@ 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 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 setup do @conn = stub() diff --git a/test/unit/repl_set_connection_test.rb b/test/unit/repl_set_connection_test.rb index 1c449f8..6290123 100644 --- a/test/unit/repl_set_connection_test.rb +++ b/test/unit/repl_set_connection_test.rb @@ -3,19 +3,6 @@ include Mongo class ReplSetConnectionTest < Test::Unit::TestCase 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 setup do TCPSocket.stubs(:new).returns(new_mock_socket('localhost', 27017)) From 27046e2b3aed6c0e82b0206440c1f4d87682cf00 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 16:03:05 +0100 Subject: [PATCH 15/34] Unify test_helper.rb loading code --- test/unit/collection_test.rb | 2 +- test/unit/safe_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/collection_test.rb b/test/unit/collection_test.rb index 0c3aa17..4c08a45 100644 --- a/test/unit/collection_test.rb +++ b/test/unit/collection_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('./test/test_helper.rb') +require './test/test_helper' class CollectionTest < Test::Unit::TestCase diff --git a/test/unit/safe_test.rb b/test/unit/safe_test.rb index 92ecf29..bf9f9f9 100644 --- a/test/unit/safe_test.rb +++ b/test/unit/safe_test.rb @@ -1,4 +1,4 @@ -require File.expand_path('./test/test_helper.rb') +require './test/test_helper' class SafeTest < Test::Unit::TestCase From 2644d2b27d261071246eb9396ac2bcfd70ff0c68 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 16:04:01 +0100 Subject: [PATCH 16/34] Mock and initialize logger --- test/unit/cursor_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unit/cursor_test.rb b/test/unit/cursor_test.rb index f7f7775..841468b 100644 --- a/test/unit/cursor_test.rb +++ b/test/unit/cursor_test.rb @@ -72,7 +72,9 @@ class CursorTest < Test::Unit::TestCase context "Query fields" 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) @collection = stub(:db => @db, :name => "items") end From e4867b542e9ddf13aaf342a20f33029dd6ff207a Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 16:12:30 +0100 Subject: [PATCH 17/34] Initialize instance variables for available options --- lib/mongo/util/uri_parser.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/mongo/util/uri_parser.rb b/lib/mongo/util/uri_parser.rb index 2be31f2..dcc089d 100644 --- a/lib/mongo/util/uri_parser.rb +++ b/lib/mongo/util/uri_parser.rb @@ -142,7 +142,11 @@ module Mongo # This method uses the lambdas defined in OPT_VALID and OPT_CONV to validate # and convert the given options. def parse_options(opts) + # initialize instance variables for available options + OPT_VALID.keys.each { |k| instance_variable_set("@#{k}", nil) } + return unless opts + separator = opts.include?('&') ? '&' : ';' opts.split(separator).each do |attr| key, value = attr.split('=') From 5dfac28dd41298bb012a5ea571516b6bd329811f Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 16:22:39 +0100 Subject: [PATCH 18/34] Fix Mongo::Cursor#query_options_hash --- lib/mongo/cursor.rb | 4 ++-- test/unit/cursor_test.rb | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index 370a355..0ed33d2 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -307,8 +307,8 @@ module Mongo def query_options_hash { :selector => @selector, :fields => @fields, - :skip => @skip_num, - :limit => @limit_num, + :skip => @skip, + :limit => @limit, :order => @order, :hint => @hint, :snapshot => @snapshot, diff --git a/test/unit/cursor_test.rb b/test/unit/cursor_test.rb index 841468b..14f36b5 100644 --- a/test/unit/cursor_test.rb +++ b/test/unit/cursor_test.rb @@ -12,28 +12,32 @@ class CursorTest < Test::Unit::TestCase end should "set timeout" do - assert_equal true, @cursor.timeout + assert @cursor.timeout + assert @cursor.query_options_hash[:timeout] end should "set selector" do - assert @cursor.selector == {} + assert_equal({}, @cursor.selector) @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 should "set fields" do assert_nil @cursor.fields @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 should "set mix fields 0 and 1" do assert_nil @cursor.fields @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 should "set limit" do @@ -41,6 +45,7 @@ class CursorTest < Test::Unit::TestCase @cursor = Cursor.new(@collection, :limit => 10) assert_equal 10, @cursor.limit + assert_equal 10, @cursor.query_options_hash[:limit] end @@ -49,6 +54,7 @@ class CursorTest < Test::Unit::TestCase @cursor = Cursor.new(@collection, :skip => 5) assert_equal 5, @cursor.skip + assert_equal 5, @cursor.query_options_hash[:skip] end should "set sort order" do @@ -56,6 +62,7 @@ class CursorTest < Test::Unit::TestCase @cursor = Cursor.new(@collection, :order => "last_name") assert_equal "last_name", @cursor.order + assert_equal "last_name", @cursor.query_options_hash[:order] end should "set hint" do @@ -63,6 +70,7 @@ class CursorTest < Test::Unit::TestCase @cursor = Cursor.new(@collection, :hint => "name") assert_equal "name", @cursor.hint + assert_equal "name", @cursor.query_options_hash[:hint] end should "cache full collection name" do From 5270b6ec0689450272b3485dfdb177a9ff1151e2 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 16:24:31 +0100 Subject: [PATCH 19/34] Enable warnings in test:functional --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 68bc955..df591b6 100644 --- a/Rakefile +++ b/Rakefile @@ -89,6 +89,7 @@ namespace :test do Rake::TestTask.new(:functional) do |t| t.test_files = FileList['test/*_test.rb'] t.verbose = true + t.ruby_opts << '-w' end Rake::TestTask.new(:pooled_threading) do |t| From 95911166f3056af12529faf6d52d68b59a282149 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:01:57 +0100 Subject: [PATCH 20/34] Avoid using instance_variable_get on objects of other class --- lib/bson/types/object_id.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bson/types/object_id.rb b/lib/bson/types/object_id.rb index fcb0e3a..5d72b72 100644 --- a/lib/bson/types/object_id.rb +++ b/lib/bson/types/object_id.rb @@ -84,9 +84,9 @@ module BSON # Check equality of this object id with another. # - # @param [Mongo::ObjectId] object_id + # @param [BSON::ObjectId] 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 alias_method :==, :eql? From 62900acb4bdbd31ba3612dbd1164ff928d57eca5 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:03:32 +0100 Subject: [PATCH 21/34] Initialize @cursor_id --- lib/mongo/cursor.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index 0ed33d2..42d84fd 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -34,6 +34,8 @@ module Mongo # # @core cursors constructor_details def initialize(collection, opts={}) + @cursor_id = nil + @db = collection.db @collection = collection @connection = @db.connection From d12987bf7abd41654d94ec3a0fa1f4d5c5036d5e Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:09:18 +0100 Subject: [PATCH 22/34] Always initialize @metadata and @aliases --- lib/mongo/gridfs/grid_io.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mongo/gridfs/grid_io.rb b/lib/mongo/gridfs/grid_io.rb index f8d4750..4000364 100644 --- a/lib/mongo/gridfs/grid_io.rb +++ b/lib/mongo/gridfs/grid_io.rb @@ -335,8 +335,8 @@ module Mongo @files_id = opts.delete(:_id) || BSON::ObjectId.new @content_type = opts.delete(:content_type) || (defined? MIME) && get_content_type || DEFAULT_CONTENT_TYPE @chunk_size = opts.delete(:chunk_size) || DEFAULT_CHUNK_SIZE - @metadata = opts.delete(:metadata) if opts[:metadata] - @aliases = opts.delete(:aliases) if opts[:aliases] + @metadata = opts.delete(:metadata) + @aliases = opts.delete(:aliases) @file_length = 0 opts.each {|k, v| self[k] = v} check_existing_file if @safe From 2971793b48f6356123d27e14ba0f5676aa16890d Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:12:46 +0100 Subject: [PATCH 23/34] Remove dead code --- lib/mongo/util/pool.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/mongo/util/pool.rb b/lib/mongo/util/pool.rb index 61cf394..fe25d11 100644 --- a/lib/mongo/util/pool.rb +++ b/lib/mongo/util/pool.rb @@ -156,10 +156,6 @@ module Mongo return socket else # Otherwise, wait - if @logger - @logger.warn "MONGODB Waiting for available connection; " + - "#{@checked_out.size} of #{@size} connections checked out." - end @queue.wait(@connection_mutex) end end From 80a44efb689acd73983adfa2c2a6dee816192d50 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:15:35 +0100 Subject: [PATCH 24/34] Prevent outer local variable shadowing --- test/collection_test.rb | 4 ++-- test/cursor_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/collection_test.rb b/test/collection_test.rb index f137679..6ae748d 100644 --- a/test/collection_test.rb +++ b/test/collection_test.rb @@ -373,8 +373,8 @@ class TestCollection < Test::Unit::TestCase docs = [{"hello" => "world"}, {"hello" => "world"}] @@test.insert(docs) - docs.each do |doc| - assert(doc.include?(:_id)) + docs.each do |d| + assert(d.include?(:_id)) end end diff --git a/test/cursor_test.rb b/test/cursor_test.rb index e7ae52d..a91f964 100644 --- a/test/cursor_test.rb +++ b/test/cursor_test.rb @@ -171,8 +171,8 @@ class CursorTest < Test::Unit::TestCase cursor = Cursor.new(@@coll, :timeout => false) assert_equal false, cursor.timeout - @@coll.find({}, :timeout => false) do |cursor| - assert_equal false, cursor.timeout + @@coll.find({}, :timeout => false) do |c| + assert_equal false, c.timeout end end From 4ea7a1460851b4b0eb956df2cfc9b17f2d48b023 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:19:14 +0100 Subject: [PATCH 25/34] Add parenthesis where Ruby thinks they're a good idea --- test/connection_test.rb | 2 +- test/conversions_test.rb | 20 ++++++++++---------- test/cursor_test.rb | 2 +- test/db_test.rb | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/test/connection_test.rb b/test/connection_test.rb index d66332b..f1962e6 100644 --- a/test/connection_test.rb +++ b/test/connection_test.rb @@ -35,7 +35,7 @@ class TestConnection < Test::Unit::TestCase end 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 def test_invalid_database_names diff --git a/test/conversions_test.rb b/test/conversions_test.rb index c001826..a3545bc 100644 --- a/test/conversions_test.rb +++ b/test/conversions_test.rb @@ -40,11 +40,11 @@ class ConversionsTest < Test::Unit::TestCase end def test_sort_value_when_value_is_negative_one - assert_equal -1, sort_value(-1) + assert_equal(-1, sort_value(-1)) end 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 def test_sort_value_when_value_is_ascending @@ -80,35 +80,35 @@ class ConversionsTest < Test::Unit::TestCase end def test_sort_value_when_value_is_descending - assert_equal -1, sort_value("descending") + assert_equal(-1, sort_value("descending")) end def test_sort_value_when_value_is_desc - assert_equal -1, sort_value("desc") + assert_equal(-1, sort_value("desc")) end def test_sort_value_when_value_is_uppercase_descending - assert_equal -1, sort_value("DESCENDING") + assert_equal(-1, sort_value("DESCENDING")) end def test_sort_value_when_value_is_uppercase_desc - assert_equal -1, sort_value("DESC") + assert_equal(-1, sort_value("DESC")) end def test_sort_value_when_value_is_symbol_descending - assert_equal -1, sort_value(:descending) + assert_equal(-1, sort_value(:descending)) end def test_sort_value_when_value_is_symbol_desc - assert_equal -1, sort_value(:desc) + assert_equal(-1, sort_value(:desc)) end def test_sort_value_when_value_is_uppercase_symbol_descending - assert_equal -1, sort_value(:DESCENDING) + assert_equal(-1, sort_value(:DESCENDING)) end def test_sort_value_when_value_is_uppercase_symbol_desc - assert_equal -1, sort_value(:DESC) + assert_equal(-1, sort_value(:DESC)) end def test_sort_value_when_value_is_invalid diff --git a/test/cursor_test.rb b/test/cursor_test.rb index a91f964..4b974b1 100644 --- a/test/cursor_test.rb +++ b/test/cursor_test.rb @@ -120,7 +120,7 @@ class CursorTest < Test::Unit::TestCase results = @@coll.find.sort([:n, :asc]).to_a 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 MaxKey.new, results[3]['n'] end diff --git a/test/db_test.rb b/test/db_test.rb index b4850fd..0a53759 100644 --- a/test/db_test.rb +++ b/test/db_test.rb @@ -26,7 +26,7 @@ class DBTest < Test::Unit::TestCase @@db.collection('test').insert('a' => 1) fail "expected 'NilClass' exception" rescue => ex - assert_match /NilClass/, ex.to_s + assert_match(/NilClass/, ex.to_s) ensure @@db = standard_connection.db(MONGO_TEST_DB) @@users = @@db.collection('system.users') @@ -104,7 +104,7 @@ class DBTest < Test::Unit::TestCase db.pk_factory = Object.new fail "error: expected exception" rescue => ex - assert_match /Cannot change/, ex.to_s + assert_match(/Cannot change/, ex.to_s) ensure conn.close end @@ -280,7 +280,7 @@ class DBTest < Test::Unit::TestCase assert_not_nil doc result = doc['result'] assert_not_nil result - assert_match /firstExtent/, result + assert_match(/firstExtent/, result) end end From 46af71fbfe21bbea5f177394897c71ef222473a8 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:19:53 +0100 Subject: [PATCH 26/34] Make cursor test unit names unique --- test/cursor_fail_test.rb | 2 +- test/cursor_message_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cursor_fail_test.rb b/test/cursor_fail_test.rb index bc3876f..c5e65fc 100644 --- a/test/cursor_fail_test.rb +++ b/test/cursor_fail_test.rb @@ -1,7 +1,7 @@ require './test/test_helper' require 'logger' -class CursorTest < Test::Unit::TestCase +class CursorFailTest < Test::Unit::TestCase include Mongo diff --git a/test/cursor_message_test.rb b/test/cursor_message_test.rb index 0a98802..17b82df 100644 --- a/test/cursor_message_test.rb +++ b/test/cursor_message_test.rb @@ -1,7 +1,7 @@ require './test/test_helper' require 'logger' -class CursorTest < Test::Unit::TestCase +class CursorMessageTest < Test::Unit::TestCase include Mongo From ccd7818024917b3260a75e7809a4810e3d7b6204 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:20:09 +0100 Subject: [PATCH 27/34] Fix indentation --- test/cursor_test.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/cursor_test.rb b/test/cursor_test.rb index 4b974b1..f6f295c 100644 --- a/test/cursor_test.rb +++ b/test/cursor_test.rb @@ -450,5 +450,4 @@ class CursorTest < Test::Unit::TestCase cursor.rewind! assert_equal 100, cursor.map {|doc| doc }.length end - - end +end From a17a0a68af0a4bd567ef1f457a2269de793970d9 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:23:08 +0100 Subject: [PATCH 28/34] Remove test case name duplication --- test/db_api_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/db_api_test.rb b/test/db_api_test.rb index d1688a3..7ff6710 100644 --- a/test/db_api_test.rb +++ b/test/db_api_test.rb @@ -621,7 +621,7 @@ class DBAPITest < Test::Unit::TestCase assert_equal("mike", @@coll.find_one()["hello"]) end - def test_collection_names + def test_collection_names_errors assert_raise TypeError do @@db.collection(5) end From e5ef555f9fe5c3042c1627e25abd8de81c47e00c Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:20:23 +0100 Subject: [PATCH 29/34] Fix failing test --- test/db_api_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/db_api_test.rb b/test/db_api_test.rb index 7ff6710..323f04f 100644 --- a/test/db_api_test.rb +++ b/test/db_api_test.rb @@ -239,7 +239,7 @@ class DBAPITest < Test::Unit::TestCase names = @@db.collection_names assert names.length >= 2 assert names.include?(@@coll.name) - assert names.include?('mongo-ruby-test.test2') + assert names.include?('test2') ensure @@db.drop_collection('test2') end From c6491461bcdb9d4720491e57a434d14c3ac0479f Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 17:23:45 +0100 Subject: [PATCH 30/34] Move helper methods away from tests setup to avoid redefinition on each test run --- test/grid_test.rb | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/grid_test.rb b/test/grid_test.rb index 184f23b..2748071 100644 --- a/test/grid_test.rb +++ b/test/grid_test.rb @@ -1,6 +1,22 @@ require './test/test_helper' 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 context "Tests:" do setup do @@ -161,22 +177,6 @@ class GridTest < Test::Unit::TestCase context "Streaming: " 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') end From cf6e7e86345f104f195d81ce87e6c988f9f95007 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 00:33:57 +0100 Subject: [PATCH 31/34] Enable warnings in test:pooled_threading --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index df591b6..8c80a70 100644 --- a/Rakefile +++ b/Rakefile @@ -95,6 +95,7 @@ namespace :test do Rake::TestTask.new(:pooled_threading) do |t| t.test_files = FileList['test/threading/*_test.rb'] t.verbose = true + t.ruby_opts << '-w' end Rake::TestTask.new(:auto_reconnect) do |t| From d9ba3da0bf26e1538cedfd180899573e508044e0 Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 00:35:27 +0100 Subject: [PATCH 32/34] Enable warnings in test:auto_reconnect --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 8c80a70..cd5d970 100644 --- a/Rakefile +++ b/Rakefile @@ -101,6 +101,7 @@ namespace :test do Rake::TestTask.new(:auto_reconnect) do |t| t.test_files = FileList['test/auxillary/autoreconnect_test.rb'] t.verbose = true + t.ruby_opts << '-w' end Rake::TestTask.new(:authentication) do |t| From 132ed07bfde289bb9b21808138095fdd01fd4acf Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 00:42:03 +0100 Subject: [PATCH 33/34] Enable warnings in test:authentication --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index cd5d970..92173ba 100644 --- a/Rakefile +++ b/Rakefile @@ -107,6 +107,7 @@ namespace :test do Rake::TestTask.new(:authentication) do |t| t.test_files = FileList['test/auxillary/authentication_test.rb'] t.verbose = true + t.ruby_opts << '-w' end Rake::TestTask.new(:new_features) do |t| From 4c9ff36698e44fff02a5d4618fd96f8e429d54df Mon Sep 17 00:00:00 2001 From: Wojciech Piekutowski Date: Sun, 20 Feb 2011 00:43:32 +0100 Subject: [PATCH 34/34] Enable warnings in test:new_features --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 92173ba..b38a151 100644 --- a/Rakefile +++ b/Rakefile @@ -113,6 +113,7 @@ namespace :test do Rake::TestTask.new(:new_features) do |t| t.test_files = FileList['test/auxillary/1.4_features.rb'] t.verbose = true + t.ruby_opts << '-w' end Rake::TestTask.new(:bson) do |t|