Skip to content

Commit

Permalink
Whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ches committed Jan 5, 2011
1 parent 3a6d99d commit d902472
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ up the file in the GridFS store.
For example,

GET '/gridfs/someobjectid'

If the prefix is "gridfs", then the id will be be "someobjectid".

== Mongo Driver Compatibility Notes

This version is currently based off of mongo-0.20.1.
This version is currently based off of mongo-0.20.1.

As of mongo-0.19.1, there have been significant changes to GridFS. I do
not plan to support versions of the mongo driver prior to 0.19. There are
Expand Down
16 changes: 8 additions & 8 deletions lib/rack/gridfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
require 'mongo'

module Rack

class GridFSConnectionError < StandardError ; end

class GridFS
VERSION = "0.2.0"

attr_reader :hostname, :port, :database, :prefix, :db

def initialize(app, options = {})
options = {
:hostname => 'localhost',
:hostname => 'localhost',
:prefix => 'gridfs',
:port => Mongo::Connection::DEFAULT_PORT
}.merge(options)
Expand Down Expand Up @@ -42,17 +42,17 @@ def gridfs_request(id)
rescue Mongo::GridError, BSON::InvalidObjectID
[404, {'Content-Type' => 'text/plain'}, ['File not found.']]
end

private

def connect!
Timeout::timeout(5) do
@db = Mongo::Connection.new(hostname).db(database)
end
rescue Exception => e
raise Rack::GridFSConnectionError, "Unable to connect to the MongoDB server (#{e.to_s})"
end

end

end
18 changes: 9 additions & 9 deletions test/gridfs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

class Rack::GridFSTest < Test::Unit::TestCase
include Rack::Test::Methods

def stub_mongodb_connection
Rack::GridFS.any_instance.stubs(:connect!).returns(true)
end

def test_database_options
{ :hostname => 'localhost', :port => 27017, :database => 'test', :prefix => 'gridfs' }
end

def db
@db ||= Mongo::Connection.new(test_database_options[:hostname], test_database_options[:port]).db(test_database_options[:database])
end
def app

def app
gridfs_opts = test_database_options
Rack::Builder.new do
use Rack::GridFS, gridfs_opts
Expand Down Expand Up @@ -71,7 +71,7 @@ def load_artifact(filename, content_type)
mware = Rack::GridFS.new(nil, @options)
assert_equal mware.prefix, @options[:prefix]
end

should "have a default prefix" do
mware = Rack::GridFS.new(nil, @options.except(:prefix))
assert_equal mware.prefix, 'gridfs'
Expand Down Expand Up @@ -116,17 +116,17 @@ def load_artifact(filename, content_type)
get "/gridfs/#{@html_id}"
assert_match /html.*?body.*Test/m, last_response.body
end

should "return the proper content type for HTML files" do
get "/gridfs/#{@html_id}"
assert_equal 'text/html', last_response.content_type
end

should "return a not found for a unknown path" do
get '/gridfs/unknown'
assert last_response.not_found?
end

should "work for small images" do
image_id = load_artifact('3wolfmoon.jpg', 'image/jpeg')
get "/gridfs/#{image_id}"
Expand Down

0 comments on commit d902472

Please sign in to comment.