2010-02-12 23:03:07 +00:00
|
|
|
require 'test/test_helper'
|
|
|
|
|
|
|
|
class GridTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@db ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
|
|
|
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
2010-02-18 21:31:25 +00:00
|
|
|
@files = @db.collection('test-bucket.files')
|
|
|
|
@chunks = @db.collection('test-bucket.chunks')
|
2010-02-12 23:03:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@files.remove
|
|
|
|
@chunks.remove
|
|
|
|
end
|
|
|
|
|
2010-02-18 21:31:25 +00:00
|
|
|
context "A basic grid-stored file" do
|
2010-02-12 23:03:07 +00:00
|
|
|
setup do
|
2010-02-18 21:31:25 +00:00
|
|
|
@data = "GRIDDATA" * 50000
|
|
|
|
@grid = Grid.new(@db, 'test-bucket')
|
|
|
|
@id = @grid.put(@data, 'sample', :metadata => {'app' => 'photos'})
|
2010-02-12 23:03:07 +00:00
|
|
|
end
|
|
|
|
|
2010-02-18 21:31:25 +00:00
|
|
|
should "retrieve the stored data" do
|
|
|
|
data = @grid.get(@id).data
|
|
|
|
assert_equal @data, data
|
2010-02-12 23:03:07 +00:00
|
|
|
end
|
|
|
|
|
2010-02-18 21:31:25 +00:00
|
|
|
should "store the filename" do
|
|
|
|
file = @grid.get(@id)
|
|
|
|
assert_equal 'sample', file.filename
|
2010-02-12 23:03:07 +00:00
|
|
|
end
|
|
|
|
|
2010-02-18 21:31:25 +00:00
|
|
|
should "store any relevant metadata" do
|
|
|
|
file = @grid.get(@id)
|
|
|
|
assert_equal 'photos', file.metadata['app']
|
2010-02-12 23:03:07 +00:00
|
|
|
end
|
|
|
|
|
2010-02-18 21:31:25 +00:00
|
|
|
should "delete the file and any chunks" do
|
|
|
|
@grid.delete(@id)
|
|
|
|
assert_raise GridError do
|
|
|
|
@grid.get(@id)
|
2010-02-12 23:03:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|