base_attachment_tests.rb
2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
module BaseAttachmentTests
def test_should_create_file_from_uploaded_file
assert_created do
attachment = upload_file :filename => '/files/foo.txt', :content_type => 'text/plain'
assert_valid attachment
assert !attachment.db_file.new_record? if attachment.respond_to?(:db_file)
assert !attachment.image?
assert !attachment.size.zero?
#assert_equal 3, attachment.size
assert_nil attachment.width
assert_nil attachment.height
end
end
def test_should_create_file_from_merb_temp_file
assert_created do
attachment = upload_merb_file :filename => '/files/foo.txt', :content_type => 'text/plain'
assert_valid attachment
assert !attachment.db_file.new_record? if attachment.respond_to?(:db_file)
assert !attachment.image?
assert !attachment.size.zero?
#assert_equal 3, attachment.size
assert_nil attachment.width
assert_nil attachment.height
end
end
def test_reassign_attribute_data
assert_created 1 do
attachment = upload_file :filename => '/files/rails.png'
assert_valid attachment
assert attachment.size > 0, "no data was set"
attachment.set_temp_data 'wtf'
assert attachment.save_attachment?
attachment.save!
assert_equal 'wtf', attachment_model.find(attachment.id).send(:current_data)
end
end
def test_no_reassign_attribute_data_on_nil
assert_created 1 do
attachment = upload_file :filename => '/files/rails.png'
assert_valid attachment
assert attachment.size > 0, "no data was set"
attachment.set_temp_data nil
assert !attachment.save_attachment?
end
end
def test_should_overwrite_old_contents_when_updating
attachment = upload_file :filename => '/files/rails.png'
assert_not_created do # no new db_file records
use_temp_file 'files/rails.png' do |file|
attachment.filename = 'rails2.png'
attachment.temp_paths.unshift File.join(FIXTURE_PATH, file)
attachment.save!
end
end
end
def test_should_save_without_updating_file
attachment = upload_file :filename => '/files/foo.txt'
assert_valid attachment
assert !attachment.save_attachment?
assert_nothing_raised { attachment.save! }
end
def test_should_handle_nil_file_upload
attachment = attachment_model.create :uploaded_data => ''
assert_raise ActiveRecord::RecordInvalid do
attachment.save!
end
end
end