1 module BaseAttachmentTests
2 def test_should_create_file_from_uploaded_file
4 attachment = upload_file :filename => '/files/foo.txt'
5 assert_valid attachment
6 assert !attachment.db_file.new_record? if attachment.respond_to?(:db_file)
7 assert attachment.image?
8 assert !attachment.size.zero?
9 #assert_equal 3, attachment.size
10 assert_nil attachment.width
11 assert_nil attachment.height
15 def test_should_create_file_from_merb_temp_file
17 attachment = upload_merb_file :filename => '/files/foo.txt'
18 assert_valid attachment
19 assert !attachment.db_file.new_record? if attachment.respond_to?(:db_file)
20 assert attachment.image?
21 assert !attachment.size.zero?
22 #assert_equal 3, attachment.size
23 assert_nil attachment.width
24 assert_nil attachment.height
28 def test_reassign_attribute_data
30 attachment = upload_file :filename => '/files/rails.png'
31 assert_valid attachment
32 assert attachment.size > 0, "no data was set"
34 attachment.set_temp_data 'wtf'
35 assert attachment.save_attachment?
38 assert_equal 'wtf', attachment_model.find(attachment.id).send(:current_data)
42 def test_no_reassign_attribute_data_on_nil
44 attachment = upload_file :filename => '/files/rails.png'
45 assert_valid attachment
46 assert attachment.size > 0, "no data was set"
48 attachment.set_temp_data nil
49 assert !attachment.save_attachment?
53 def test_should_overwrite_old_contents_when_updating
54 attachment = upload_file :filename => '/files/rails.png'
55 assert_not_created do # no new db_file records
56 use_temp_file 'files/rails.png' do |file|
57 attachment.filename = 'rails2.png'
58 attachment.temp_paths.unshift File.join(fixture_path, file)
64 def test_should_save_without_updating_file
65 attachment = upload_file :filename => '/files/foo.txt'
66 assert_valid attachment
67 assert !attachment.save_attachment?
68 assert_nothing_raised { attachment.save! }
71 def test_should_handle_nil_file_upload
72 attachment = attachment_model.create :uploaded_data => ''
73 assert_raise ActiveRecord::RecordInvalid do