Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 77 lines (68 sloc) 2.447 kb
f83683b all tests pass
technoweenie authored
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
3836c31 @redinger Work with merb tempfile
redinger authored
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
f83683b all tests pass
technoweenie authored
28 def test_reassign_attribute_data
29 assert_created 1 do
30 attachment = upload_file :filename => '/files/rails.png'
31 assert_valid attachment
88f42fb first pass at temp file usage
technoweenie authored
32 assert attachment.size > 0, "no data was set"
f83683b all tests pass
technoweenie authored
33
88f42fb first pass at temp file usage
technoweenie authored
34 attachment.temp_data = 'wtf'
35 assert attachment.save_attachment?
36 attachment.save!
f83683b all tests pass
technoweenie authored
37
d89bfe4 comments comments comments
technoweenie authored
38 assert_equal 'wtf', attachment_model.find(attachment.id).send(:current_data)
f83683b all tests pass
technoweenie authored
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
88f42fb first pass at temp file usage
technoweenie authored
46 assert attachment.size > 0, "no data was set"
f83683b all tests pass
technoweenie authored
47
88f42fb first pass at temp file usage
technoweenie authored
48 attachment.temp_data = nil
f83683b all tests pass
technoweenie authored
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
88f42fb first pass at temp file usage
technoweenie authored
56 use_temp_file 'files/rails.png' do |file|
57 attachment.filename = 'rails2.png'
1c56f39 small tweaks with tempfile path
technoweenie authored
58 attachment.temp_path = File.join(fixture_path, file)
88f42fb first pass at temp file usage
technoweenie authored
59 attachment.save!
60 end
f83683b all tests pass
technoweenie authored
61 end
62 end
e279f10 change #process_attachment to an after_validation callback
technoweenie authored
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
6b7bc91 @redinger Fixed bug from previous commit that wasn't catching nil files uploaded.
redinger authored
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
f83683b all tests pass
technoweenie authored
77 end
Something went wrong with that request. Please try again.