Added back support for :delete_old option and wrote tests for :versions option on GridFilesystem.
This commit is contained in:
parent
c70b1d1b30
commit
417000da7b
@ -97,7 +97,12 @@ module Mongo
|
|||||||
def open(filename, mode, opts={})
|
def open(filename, mode, opts={})
|
||||||
opts = opts.dup
|
opts = opts.dup
|
||||||
opts.merge!(default_grid_io_opts(filename))
|
opts.merge!(default_grid_io_opts(filename))
|
||||||
versions = opts.delete(:versions) && mode == 'w'
|
if mode == 'w'
|
||||||
|
versions = opts.delete(:versions)
|
||||||
|
if opts.delete(:delete_old) || (versions && versions < 1)
|
||||||
|
versions = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
file = GridIO.new(@files, @chunks, filename, mode, opts)
|
file = GridIO.new(@files, @chunks, filename, mode, opts)
|
||||||
return file unless block_given?
|
return file unless block_given?
|
||||||
result = nil
|
result = nil
|
||||||
|
@ -165,6 +165,18 @@ class GridFileSystemTest < Test::Unit::TestCase
|
|||||||
assert_equal 0, @db['fs.chunks'].find({'files_id' => {'$in' => @ids}}).count
|
assert_equal 0, @db['fs.chunks'].find({'files_id' => {'$in' => @ids}}).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "delete all versions which exceed the number of versions to keep specified by the option :versions" do
|
||||||
|
@versions = 1 + rand(4-1)
|
||||||
|
@grid.open('sample', 'w', :versions => @versions) do |f|
|
||||||
|
f.write @new_data
|
||||||
|
end
|
||||||
|
@new_ids = @db['fs.files'].find({'filename' => 'sample'}).map {|file| file['_id']}
|
||||||
|
assert_equal @versions, @new_ids.length
|
||||||
|
id = @new_ids.first
|
||||||
|
assert !@ids.include?(id)
|
||||||
|
assert_equal @versions, @db['fs.files'].find({'filename' => 'sample'}).count
|
||||||
|
end
|
||||||
|
|
||||||
should "delete old versions on write with :delete_old is passed in" do
|
should "delete old versions on write with :delete_old is passed in" do
|
||||||
@grid.open('sample', 'w', :delete_old => true) do |f|
|
@grid.open('sample', 'w', :delete_old => true) do |f|
|
||||||
f.write @new_data
|
f.write @new_data
|
||||||
|
Loading…
Reference in New Issue
Block a user