diff --git a/test/fixtures/test1.pdf b/test/fixtures/test1.pdf new file mode 100644 index 000000000..6502314a5 Binary files /dev/null and b/test/fixtures/test1.pdf differ diff --git a/test/unit/store_test.rb b/test/unit/store_test.rb new file mode 100644 index 000000000..68886e7cb --- /dev/null +++ b/test/unit/store_test.rb @@ -0,0 +1,58 @@ +require 'test_helper' + +class StoreTest < ActiveSupport::TestCase + test 'store attachment' do + files = [ + { + :data => 'hello world', + :filename => 'test.txt', + }, + { + :data => 'hello world äöüß', + :filename => 'testäöüß.txt', + }, + { + :data => IO.read('test/fixtures/test1.pdf'), + :filename => 'test.pdf', + }, + ] + + + files.each { |file| + + md5 = Digest::MD5.hexdigest( file[:data] ) + + # add attachments + store = Store.add( + :object => 'Test', + :o_id => 1, + :data => file[:data], + :filename => file[:filename], + :preferences => {} + ) + assert store + + # get list of attachments + attachments = Store.list( + :object => 'Test', + :o_id => 1 + ) + assert attachments + + # md5 check + md5_new = Digest::MD5.hexdigest( attachments[0].store_file.data ) + assert_equal( md5, md5_new ) + + # filename check + assert_equal( file[:filename], attachments[0].filename ) + + # delete attachments + success = Store.remove( + :object => 'Test', + :o_id => 1 + ) + assert success + } + end +end +