Improved tests.
This commit is contained in:
parent
1be0682457
commit
4b35e77104
2 changed files with 17 additions and 10 deletions
|
@ -152,6 +152,7 @@ end
|
|||
class Store::File < ApplicationModel
|
||||
before_validation :add_md5
|
||||
before_create :check_location
|
||||
after_destroy :unlink_location
|
||||
|
||||
# generate file location
|
||||
def get_locaton
|
||||
|
@ -168,6 +169,14 @@ class Store::File < ApplicationModel
|
|||
location += "/file"
|
||||
end
|
||||
|
||||
# read file from fs
|
||||
def unlink_location
|
||||
if File.exist?( self.get_locaton )
|
||||
puts "NOTICE: storge remove '#{self.get_locaton}'"
|
||||
File.delete( self.get_locaton )
|
||||
end
|
||||
end
|
||||
|
||||
# read file from fs
|
||||
def read_from_fs
|
||||
puts "read from fs #{self.get_locaton}"
|
||||
|
@ -236,10 +245,7 @@ class Store::File < ApplicationModel
|
|||
Store::File.where( :file_system => true ).each {|item|
|
||||
item.write_to_db
|
||||
item.update_attribute( :file_system, false )
|
||||
if File.exist?( item.get_locaton )
|
||||
puts "NOTICE: storge remove '#{item.get_locaton}'"
|
||||
File.delete( item.get_locaton )
|
||||
end
|
||||
item.unlink_location
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -19,6 +19,11 @@ class StoreTest < ActiveSupport::TestCase
|
|||
:filename => 'test.pdf',
|
||||
:o_id => 3,
|
||||
},
|
||||
{
|
||||
:data => IO.read('test/fixtures/test1.pdf'),
|
||||
:filename => 'test-again.pdf',
|
||||
:o_id => 4,
|
||||
},
|
||||
]
|
||||
|
||||
files.each { |file|
|
||||
|
@ -89,19 +94,15 @@ class StoreTest < ActiveSupport::TestCase
|
|||
|
||||
# filename check
|
||||
assert_equal( file[:filename], attachments[0].filename )
|
||||
}
|
||||
|
||||
# delete attachments
|
||||
files.each { |file|
|
||||
# delete attachments
|
||||
success = Store.remove(
|
||||
:object => 'Test',
|
||||
:o_id => file[:o_id],
|
||||
)
|
||||
assert success
|
||||
}
|
||||
|
||||
# check attachments again
|
||||
files.each { |file|
|
||||
# check attachments again
|
||||
attachments = Store.list(
|
||||
:object => 'Test',
|
||||
:o_id => file[:o_id],
|
||||
|
|
Loading…
Reference in a new issue