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
# end of the query's execution. For details see
# 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
# the normal cursor timeout behavior of the mongod process.
# :timeout :: When +true+ (default), the returned cursor will be subject to
# the normal cursor timeout behavior of the mongod process.
# When +false+, the returned cursor will never timeout. Note
# that disabling timeout will only work when #find is invoked
# 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.
def find(selector={}, options={})
fields = options.delete(:fields)
@ -116,7 +116,7 @@ module Mongo
hint = options.delete(:hint)
snapshot = options.delete(:snapshot)
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
timeout = block_given? ? (options.delete(:timeout) || true) : true
if hint
@ -126,7 +126,7 @@ module Mongo
end
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)
if block_given?
yield cursor
@ -204,14 +204,14 @@ module Mongo
end
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.
#
#
# Remove all records from the collection:
# @collection.remove
# @collection.remove({})
#
# Remove only records that have expired:
# Remove only records that have expired:
# @collection.remove({:expire => {'$lte' => Time.now}})
def remove(selector={})
message = ByteBuffer.new
@ -225,7 +225,7 @@ module Mongo
# 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
# given selector. If you want all matching documents to be updated, be sure
# to specify :multi => true.
@ -254,7 +254,7 @@ module Mongo
@connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name,
"db.#{@name}.update(#{selector.inspect}, #{document.inspect})")
else
@connection.send_message(Mongo::Constants::OP_UPDATE, message,
@connection.send_message(Mongo::Constants::OP_UPDATE, message,
"db.#{@name}.update(#{selector.inspect}, #{document.inspect})")
end
end
@ -329,7 +329,7 @@ module Mongo
result = @db.command(hash)
unless result["ok"] == 1
raise Mongo::OperationFailure, "map-reduce failed: #{result['errmsg']}"
raise Mongo::OperationFailure, "map-reduce failed: #{result['errmsg']}"
end
@db[result["result"]]
end
@ -343,7 +343,7 @@ module Mongo
# query specification)
# :initial :: initial value of the aggregation counter object
# :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
# with command set to true.
# :command :: if true, run the group as a command instead of in an
@ -541,7 +541,7 @@ EOS
indexes = []
spec.each_pair do |field, direction|
indexes.push("#{field}_#{direction}")
end
end
indexes.join("_")
end
end

View File

@ -379,61 +379,61 @@ class TestCollection < Test::Unit::TestCase
# {"inc_value" => 0.5}), true)[0]["count"]
# test finalize
#assert_equal( 3,
#assert_equal( 3,
# @@test.group(
# [], {}, {"count" => 0},
# Code.new(reduce_function,{"inc_value" => 2}), true,
# [], {}, {"count" => 0},
# Code.new(reduce_function,{"inc_value" => 2}), true,
# Code.new("function (o) { o.final_count = o.count - 1; }")
# )[0]["final_count"]
#)
end
context "A collection with two records" do
setup do
context "A collection with two records" do
setup do
@collection = @@db.collection('test-collection')
@collection.insert({:name => "Jones"})
@collection.insert({:name => "Smith"})
end
should "have two records" do
should "have two records" do
assert_equal 2, @collection.size
end
should "remove the two records" do
should "remove the two records" do
@collection.remove()
assert_equal 0, @collection.size
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({})
assert_equal 0, @collection.find.count
end
should "remove only matching records" do
should "remove only matching records" do
@collection.remove({:name => "Jones"})
assert_equal 1, @collection.size
end
end
context "Creating indexes " do
setup do
context "Creating indexes " do
setup do
@collection = @@db.collection('test-collection')
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|
assert_equal 'b_1_a_1', sel[:name]
end
@collection.create_index([['b', 1], ['a', 1]])
end
context "with an index created" do
setup do
context "with an index created" do
setup do
@collection.create_index([['b', 1], ['a', 1]])
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"]
end
end