md5 for ruby gridfs too
This commit is contained in:
parent
ff68d3a734
commit
16c8170498
|
@ -67,6 +67,8 @@ module XGen
|
|||
|
||||
attr_accessor :lineno
|
||||
|
||||
attr_reader :md5
|
||||
|
||||
class << self
|
||||
|
||||
def exist?(db, name, root_collection=DEFAULT_ROOT_COLLECTION)
|
||||
|
@ -142,6 +144,7 @@ module XGen
|
|||
@aliases = doc['aliases']
|
||||
@length = doc['length']
|
||||
@metadata = doc['metadata']
|
||||
@md5 = doc['md5']
|
||||
else
|
||||
@files_id = XGen::Mongo::Driver::ObjectID.new
|
||||
@content_type = DEFAULT_CONTENT_TYPE
|
||||
|
@ -426,6 +429,10 @@ module XGen
|
|||
h['uploadDate'] = @upload_date
|
||||
h['aliases'] = @aliases
|
||||
h['metadata'] = @metadata
|
||||
md5_command = OrderedHash.new
|
||||
md5_command['filemd5'] = @files_id
|
||||
md5_command['root'] = @root
|
||||
h['md5'] = @db.db_command(md5_command)['md5']
|
||||
h
|
||||
end
|
||||
|
||||
|
|
|
@ -208,6 +208,23 @@ class GridStoreTest < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_md5
|
||||
GridStore.open(@@db, 'new-file', 'w') { |f| f.write("hello world\n")}
|
||||
GridStore.open(@@db, 'new-file', 'r') { |f|
|
||||
assert f.md5 == '6f5902ac237024bdd0c176cb93063dc4'
|
||||
begin
|
||||
f.md5 = 'cant do this'
|
||||
fail "should have seen error"
|
||||
rescue => ex
|
||||
true
|
||||
end
|
||||
}
|
||||
GridStore.open(@@db, 'new-file', 'w') {}
|
||||
GridStore.open(@@db, 'new-file', 'r') { |f|
|
||||
assert f.md5 == 'd41d8cd98f00b204e9800998ecf8427e'
|
||||
}
|
||||
end
|
||||
|
||||
def test_upload_date
|
||||
now = Time.now
|
||||
orig_file_upload_date = nil
|
||||
|
|
Loading…
Reference in New Issue