minor: fix for default root collection on gridfs

This commit is contained in:
Kyle Banker 2010-02-08 17:04:35 -05:00
parent a6310a0a4f
commit 7863b37f07
2 changed files with 9 additions and 9 deletions

View File

@ -49,11 +49,11 @@ module GridFS
# #
# @core gridfs # @core gridfs
class GridStore class GridStore
include Enumerable
DEFAULT_ROOT_COLLECTION = 'fs' DEFAULT_ROOT_COLLECTION = 'fs'
DEFAULT_CONTENT_TYPE = 'text/plain'
include Enumerable DEFAULT_CONTENT_TYPE = 'text/plain'
attr_accessor :filename attr_accessor :filename
@ -94,7 +94,7 @@ module GridFS
# @param [String] root_collection the name of the gridfs root collection. # @param [String] root_collection the name of the gridfs root collection.
# #
# @return [Boolean] # @return [Boolean]
def self.exist?(db, name, root_collection=DEFAULT_ROOT_COLLECTION) def self.exist?(db, name, root_collection=GridStore.default_root_collection)
db.collection("#{root_collection}.files").find({'filename' => name}).next_document != nil db.collection("#{root_collection}.files").find({'filename' => name}).next_document != nil
end end
@ -144,7 +144,7 @@ module GridFS
# @param [String] root_collection the name of the root collection. # @param [String] root_collection the name of the root collection.
# #
# @return [Array] # @return [Array]
def self.list(db, root_collection=DEFAULT_ROOT_COLLECTION) def self.list(db, root_collection=GridStore.default_root_collection)
db.collection("#{root_collection}.files").find().map do |f| db.collection("#{root_collection}.files").find().map do |f|
f['filename'] f['filename']
end end
@ -182,13 +182,14 @@ module GridFS
end end
# Rename a file in this collection. Note that this method uses # Rename a file in this collection. Note that this method uses
# Collection#update, which means that you will not be notified # Collection#update, which means that you will not be notified of the
# success of the operation.
# #
# @param [Mongo::DB] a MongoDB database. # @param [Mongo::DB] a MongoDB database.
# @param [String] src the name of the source file. # @param [String] src the name of the source file.
# @param [String] dest the name of the destination file. # @param [String] dest the name of the destination file.
# @param [String] root_collection the name of the default root collection. # @param [String] root_collection the name of the default root collection.
def self.mv(db, src, dest, root_collection=DEFAULT_ROOT_COLLECTION) def self.mv(db, src, dest, root_collection=GridStore.default_root_collection)
db.collection("#{root_collection}.files").update({ :filename => src }, { '$set' => { :filename => dest } }) db.collection("#{root_collection}.files").update({ :filename => src }, { '$set' => { :filename => dest } })
end end

View File

@ -196,7 +196,6 @@ class DBTest < Test::Unit::TestCase
def test_user_management def test_user_management
@@db.add_user("bob", "secret") @@db.add_user("bob", "secret")
@@db.logout @@db.logout
p @@users.find.to_a
assert @@db.authenticate("bob", "secret") assert @@db.authenticate("bob", "secret")
assert @@db.remove_user("bob") assert @@db.remove_user("bob")
assert !@@db.authenticate("bob", "secret") assert !@@db.authenticate("bob", "secret")