Skip to content
This repository
Newer
Older
100644 77 lines (68 sloc) 2.458 kb
f83683b5 » technoweenie
2006-12-14 all tests pass
1 module BaseAttachmentTests
2 def test_should_create_file_from_uploaded_file
3 assert_created do
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
12 end
13 end
14
3836c313 » redinger
2008-05-07 Work with merb tempfile
15 def test_should_create_file_from_merb_temp_file
16 assert_created do
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
25 end
26 end
27
f83683b5 » technoweenie
2006-12-14 all tests pass
28 def test_reassign_attribute_data
29 assert_created 1 do
30 attachment = upload_file :filename => '/files/rails.png'
31 assert_valid attachment
88f42fbb » technoweenie
2006-12-23 first pass at temp file usage
32 assert attachment.size > 0, "no data was set"
f83683b5 » technoweenie
2006-12-14 all tests pass
33
cda2d148 »
2008-10-06 remove temp_path= and temp_data= methods so they cant be assigned wit…
34 attachment.set_temp_data 'wtf'
88f42fbb » technoweenie
2006-12-23 first pass at temp file usage
35 assert attachment.save_attachment?
36 attachment.save!
f83683b5 » technoweenie
2006-12-14 all tests pass
37
d89bfe43 » technoweenie
2006-12-23 comments comments comments
38 assert_equal 'wtf', attachment_model.find(attachment.id).send(:current_data)
f83683b5 » technoweenie
2006-12-14 all tests pass
39 end
40 end
41
42 def test_no_reassign_attribute_data_on_nil
43 assert_created 1 do
44 attachment = upload_file :filename => '/files/rails.png'
45 assert_valid attachment
88f42fbb » technoweenie
2006-12-23 first pass at temp file usage
46 assert attachment.size > 0, "no data was set"
f83683b5 » technoweenie
2006-12-14 all tests pass
47
cda2d148 »
2008-10-06 remove temp_path= and temp_data= methods so they cant be assigned wit…
48 attachment.set_temp_data nil
f83683b5 » technoweenie
2006-12-14 all tests pass
49 assert !attachment.save_attachment?
50 end
51 end
52
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
88f42fbb » technoweenie
2006-12-23 first pass at temp file usage
56 use_temp_file 'files/rails.png' do |file|
57 attachment.filename = 'rails2.png'
cda2d148 »
2008-10-06 remove temp_path= and temp_data= methods so they cant be assigned wit…
58 attachment.temp_paths.unshift File.join(fixture_path, file)
88f42fbb » technoweenie
2006-12-23 first pass at temp file usage
59 attachment.save!
60 end
f83683b5 » technoweenie
2006-12-14 all tests pass
61 end
62 end
e279f106 » technoweenie
2007-01-11 change #process_attachment to an after_validation callback
63
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! }
69 end
6b7bc91a » redinger
2008-05-09 Fixed bug from previous commit that wasn't catching nil files uploaded.
70
71 def test_should_handle_nil_file_upload
72 attachment = attachment_model.create :uploaded_data => ''
73 assert_raise ActiveRecord::RecordInvalid do
74 attachment.save!
75 end
76 end
f83683b5 » technoweenie
2006-12-14 all tests pass
77 end
Something went wrong with that request. Please try again.