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_reassign_attribute_data
17 attachment = upload_file :filename => '/files/rails.png'
18 assert_valid attachment
19 assert attachment.size > 0, "no data was set"
21 attachment.temp_data = 'wtf'
22 assert attachment.save_attachment?
25 assert_equal 'wtf', attachment_model.find(attachment.id).send(:current_data)
29 def test_no_reassign_attribute_data_on_nil
31 attachment = upload_file :filename => '/files/rails.png'
32 assert_valid attachment
33 assert attachment.size > 0, "no data was set"
35 attachment.temp_data = nil
36 assert !attachment.save_attachment?
40 def test_should_overwrite_old_contents_when_updating
41 attachment = upload_file :filename => '/files/rails.png'
42 assert_not_created do # no new db_file records
43 use_temp_file 'files/rails.png' do |file|
44 attachment.filename = 'rails2.png'
45 attachment.temp_path = File.join(fixture_path, file)
51 def test_should_save_without_updating_file
52 attachment = upload_file :filename => '/files/foo.txt'
53 assert_valid attachment
54 assert !attachment.save_attachment?
55 assert_nothing_raised { attachment.save! }