From 66b8afe0d6cc791cebe4b8da90cdc49147a979ab Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 18 Oct 2012 14:09:46 -0400 Subject: [PATCH] match the chunk size in the 10gen mongo driver to solve connection issues when saving large files, and get tests working again --- lib/mongoid-grid_fs.rb | 4 +++- test/helper.rb | 1 + test/mongoid-grid_fs_test.rb | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/mongoid-grid_fs.rb b/lib/mongoid-grid_fs.rb index 3ba4113..25c10c0 100644 --- a/lib/mongoid-grid_fs.rb +++ b/lib/mongoid-grid_fs.rb @@ -58,6 +58,8 @@ # module Mongoid class GridFS + DEFAULT_CHUNK_SIZE = 256 * 1024 + class << GridFS attr_accessor :namespace attr_accessor :file_model @@ -293,7 +295,7 @@ field(:contentType, :type => String, :default => 'application/octet-stream') field(:length, :type => Integer, :default => 0) - field(:chunkSize, :type => Integer, :default => (256 * (2 ** 20))) + field(:chunkSize, :type => Integer, :default => DEFAULT_CHUNK_SIZE) field(:uploadDate, :type => Date, :default => Time.now.utc) field(:md5, :type => String, :default => Digest::MD5.hexdigest('')) diff --git a/test/helper.rb b/test/helper.rb index 79f7098..df2e393 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -2,6 +2,7 @@ require 'pp' require_relative 'testing' require_relative '../lib/mongoid-sequence.rb' +require_relative '../lib/mongoid-grid_fs.rb' Mongoid.configure do |config| config.connect_to('mongoid-sequence') diff --git a/test/mongoid-grid_fs_test.rb b/test/mongoid-grid_fs_test.rb index 82f87e4..51daf97 100644 --- a/test/mongoid-grid_fs_test.rb +++ b/test/mongoid-grid_fs_test.rb @@ -70,7 +70,7 @@ Testing Mongoid::GridFs do path = 'a.rb' data = IO.read(__FILE__) - sio = SIO.new(path, data) + sio = StringIO.new(data) g = assert{ GridFs[path] = sio and GridFs[path] } @@ -79,7 +79,7 @@ Testing Mongoid::GridFs do before = GridFs::File.count - assert{ GridFs[path] = SIO.new(path, 'foobar') } + assert{ GridFs[path] = StringIO.new('foobar') } assert{ GridFs[path].data == 'foobar' } after = GridFs::File.count