minor: whitespace

This commit is contained in:
Mike Dirolf 2009-12-08 17:52:07 -05:00
parent 8f2e25f8d3
commit a9bb31e392
2 changed files with 28 additions and 28 deletions

View File

@ -100,12 +100,12 @@ module Mongo
# objects missed, which were preset at both the start and # objects missed, which were preset at both the start and
# end of the query's execution. For details see # end of the query's execution. For details see
# http://www.mongodb.org/display/DOCS/How+to+do+Snapshotting+in+the+Mongo+Database # http://www.mongodb.org/display/DOCS/How+to+do+Snapshotting+in+the+Mongo+Database
# :timeout :: When +true+ (default), the returned cursor will be subject to # :timeout :: When +true+ (default), the returned cursor will be subject to
# the normal cursor timeout behavior of the mongod process. # the normal cursor timeout behavior of the mongod process.
# When +false+, the returned cursor will never timeout. Note # When +false+, the returned cursor will never timeout. Note
# that disabling timeout will only work when #find is invoked # that disabling timeout will only work when #find is invoked
# with a block. This is to prevent any inadvertant failure to # with a block. This is to prevent any inadvertant failure to
# close the cursor, as the cursor is explicitly closed when # close the cursor, as the cursor is explicitly closed when
# block code finishes. # block code finishes.
def find(selector={}, options={}) def find(selector={}, options={})
fields = options.delete(:fields) fields = options.delete(:fields)
@ -116,7 +116,7 @@ module Mongo
hint = options.delete(:hint) hint = options.delete(:hint)
snapshot = options.delete(:snapshot) snapshot = options.delete(:snapshot)
if options[:timeout] == false && !block_given? if options[:timeout] == false && !block_given?
raise ArgumentError, "Timeout can be set to false only when #find is invoked with a block." raise ArgumentError, "Timeout can be set to false only when #find is invoked with a block."
end end
timeout = block_given? ? (options.delete(:timeout) || true) : true timeout = block_given? ? (options.delete(:timeout) || true) : true
if hint if hint
@ -126,7 +126,7 @@ module Mongo
end end
raise RuntimeError, "Unknown options [#{options.inspect}]" unless options.empty? raise RuntimeError, "Unknown options [#{options.inspect}]" unless options.empty?
cursor = Cursor.new(self, :selector => selector, :fields => fields, :skip => skip, :limit => limit, cursor = Cursor.new(self, :selector => selector, :fields => fields, :skip => skip, :limit => limit,
:order => sort, :hint => hint, :snapshot => snapshot, :timeout => timeout) :order => sort, :hint => hint, :snapshot => snapshot, :timeout => timeout)
if block_given? if block_given?
yield cursor yield cursor
@ -204,14 +204,14 @@ module Mongo
end end
alias_method :<<, :insert alias_method :<<, :insert
# Remove all records from this collection. # Remove all records from this collection.
# If +selector+ is specified, only matching documents will be removed. # If +selector+ is specified, only matching documents will be removed.
# #
# Remove all records from the collection: # Remove all records from the collection:
# @collection.remove # @collection.remove
# @collection.remove({}) # @collection.remove({})
# #
# Remove only records that have expired: # Remove only records that have expired:
# @collection.remove({:expire => {'$lte' => Time.now}}) # @collection.remove({:expire => {'$lte' => Time.now}})
def remove(selector={}) def remove(selector={})
message = ByteBuffer.new message = ByteBuffer.new
@ -225,7 +225,7 @@ module Mongo
# Update a single document in this collection. # Update a single document in this collection.
# #
# :selector :: a hash specifying elements which must be present for a document to be updated. Note: # :selector :: a hash specifying elements which must be present for a document to be updated. Note:
# the update command currently updates only the first document matching the # the update command currently updates only the first document matching the
# given selector. If you want all matching documents to be updated, be sure # given selector. If you want all matching documents to be updated, be sure
# to specify :multi => true. # to specify :multi => true.
@ -254,7 +254,7 @@ module Mongo
@connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name, @connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name,
"db.#{@name}.update(#{selector.inspect}, #{document.inspect})") "db.#{@name}.update(#{selector.inspect}, #{document.inspect})")
else else
@connection.send_message(Mongo::Constants::OP_UPDATE, message, @connection.send_message(Mongo::Constants::OP_UPDATE, message,
"db.#{@name}.update(#{selector.inspect}, #{document.inspect})") "db.#{@name}.update(#{selector.inspect}, #{document.inspect})")
end end
end end
@ -329,7 +329,7 @@ module Mongo
result = @db.command(hash) result = @db.command(hash)
unless result["ok"] == 1 unless result["ok"] == 1
raise Mongo::OperationFailure, "map-reduce failed: #{result['errmsg']}" raise Mongo::OperationFailure, "map-reduce failed: #{result['errmsg']}"
end end
@db[result["result"]] @db[result["result"]]
end end
@ -343,7 +343,7 @@ module Mongo
# query specification) # query specification)
# :initial :: initial value of the aggregation counter object # :initial :: initial value of the aggregation counter object
# :reduce :: aggregation function as a JavaScript string # :reduce :: aggregation function as a JavaScript string
# :finalize :: optional. a JavaScript function that receives and modifies # :finalize :: optional. a JavaScript function that receives and modifies
# each of the resultant grouped objects. Available only when group is run # each of the resultant grouped objects. Available only when group is run
# with command set to true. # with command set to true.
# :command :: if true, run the group as a command instead of in an # :command :: if true, run the group as a command instead of in an
@ -541,7 +541,7 @@ EOS
indexes = [] indexes = []
spec.each_pair do |field, direction| spec.each_pair do |field, direction|
indexes.push("#{field}_#{direction}") indexes.push("#{field}_#{direction}")
end end
indexes.join("_") indexes.join("_")
end end
end end

View File

@ -379,61 +379,61 @@ class TestCollection < Test::Unit::TestCase
# {"inc_value" => 0.5}), true)[0]["count"] # {"inc_value" => 0.5}), true)[0]["count"]
# test finalize # test finalize
#assert_equal( 3, #assert_equal( 3,
# @@test.group( # @@test.group(
# [], {}, {"count" => 0}, # [], {}, {"count" => 0},
# Code.new(reduce_function,{"inc_value" => 2}), true, # Code.new(reduce_function,{"inc_value" => 2}), true,
# Code.new("function (o) { o.final_count = o.count - 1; }") # Code.new("function (o) { o.final_count = o.count - 1; }")
# )[0]["final_count"] # )[0]["final_count"]
#) #)
end end
context "A collection with two records" do context "A collection with two records" do
setup do setup do
@collection = @@db.collection('test-collection') @collection = @@db.collection('test-collection')
@collection.insert({:name => "Jones"}) @collection.insert({:name => "Jones"})
@collection.insert({:name => "Smith"}) @collection.insert({:name => "Smith"})
end end
should "have two records" do should "have two records" do
assert_equal 2, @collection.size assert_equal 2, @collection.size
end end
should "remove the two records" do should "remove the two records" do
@collection.remove() @collection.remove()
assert_equal 0, @collection.size assert_equal 0, @collection.size
end end
should "remove all records if an empty document is specified" do should "remove all records if an empty document is specified" do
@collection.remove({}) @collection.remove({})
assert_equal 0, @collection.find.count assert_equal 0, @collection.find.count
end end
should "remove only matching records" do should "remove only matching records" do
@collection.remove({:name => "Jones"}) @collection.remove({:name => "Jones"})
assert_equal 1, @collection.size assert_equal 1, @collection.size
end end
end end
context "Creating indexes " do context "Creating indexes " do
setup do setup do
@collection = @@db.collection('test-collection') @collection = @@db.collection('test-collection')
end end
should "generate indexes in the proper order" do should "generate indexes in the proper order" do
@collection.expects(:insert_documents) do |sel, coll, safe| @collection.expects(:insert_documents) do |sel, coll, safe|
assert_equal 'b_1_a_1', sel[:name] assert_equal 'b_1_a_1', sel[:name]
end end
@collection.create_index([['b', 1], ['a', 1]]) @collection.create_index([['b', 1], ['a', 1]])
end end
context "with an index created" do context "with an index created" do
setup do setup do
@collection.create_index([['b', 1], ['a', 1]]) @collection.create_index([['b', 1], ['a', 1]])
end end
should "return properly ordered index information" do should "return properly ordered index information" do
assert_equal [['b', 1], ['a', 1]], @collection.index_information["b_1_a_1"] assert_equal [['b', 1], ['a', 1]], @collection.index_information["b_1_a_1"]
end end
end end