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

@ -128,6 +128,10 @@ module GridFS
end end
alias_method :delete, :unlink 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 end
#--- #---

View File

@ -152,6 +152,16 @@ class GridStoreTest < Test::Unit::TestCase
assert_equal 0, @@chunks.count assert_equal 0, @@chunks.count
end 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 def test_append
GridStore.open(@@db, 'foobar', 'w+') { |f| f.write(" how are you?") } GridStore.open(@@db, 'foobar', 'w+') { |f| f.write(" how are you?") }
assert_equal 1, @@chunks.count assert_equal 1, @@chunks.count