GridStore#mv

This commit is contained in:
Matt Powell 2010-01-14 15:58:42 +13:00 committed by Kyle Banker
parent 8a8d6716b3
commit 3b30cde0fb
2 changed files with 15 additions and 1 deletions

View File

@ -118,7 +118,7 @@ module GridFS
gs.readlines(separator)
}
end
def unlink(db, *names)
names.each { |name|
gs = GridStore.new(db, name)
@ -128,6 +128,10 @@ module GridFS
end
alias_method :delete, :unlink
def mv(db, src, dest, root_collection=DEFAULT_ROOT_COLLECTION)
db.collection("#{root_collection}.files").update({ :filename => src }, { '$set' => { :filename => dest } })
end
end
#---

View File

@ -151,6 +151,16 @@ class GridStoreTest < Test::Unit::TestCase
assert_equal 0, @@files.count
assert_equal 0, @@chunks.count
end
def test_mv
assert_equal 1, @@files.count
assert_equal 1, @@chunks.count
GridStore.mv(@@db, 'foobar', 'bazqux')
assert_equal 1, @@files.count
assert_equal 1, @@chunks.count
assert !GridStore.exist?(@@db, 'foobar')
assert GridStore.exist?(@@db, 'bazqux')
end
def test_append
GridStore.open(@@db, 'foobar', 'w+') { |f| f.write(" how are you?") }