Class: FileSystemTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- FileSystemTest
show all
- Includes:
- BaseAttachmentTests
- Defined in:
- lib/test/backends/file_system_test.rb
Instance Method Summary
collapse
#test_no_reassign_attribute_data_on_nil, #test_reassign_attribute_data, #test_should_create_file_from_uploaded_file, #test_should_overwrite_old_contents_when_updating, #test_should_save_without_updating_file
Instance Method Details
#test_filesystem_size_for_file_attachment(klass = FileAttachment) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/test/backends/file_system_test.rb', line 7
def test_filesystem_size_for_file_attachment(klass = FileAttachment)
attachment_model klass
assert_created 1 do
attachment = upload_file :filename => '/files/rails.png'
assert_equal attachment.size, File.open(attachment.full_filename).stat.size
end
end
|
#test_should_delete_old_file_when_renaming(klass = FileAttachment) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/test/backends/file_system_test.rb', line 65
def test_should_delete_old_file_when_renaming(klass = FileAttachment)
attachment_model klass
attachment = upload_file :filename => '/files/rails.png'
old_filename = attachment.full_filename
assert_not_created do
attachment.filename = 'rails2.png'
attachment.save
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
assert !File.exists?(old_filename), "#{old_filename} still exists"
assert !attachment.reload.size.zero?
assert_equal 'rails2.png', attachment.filename
end
end
|
#test_should_delete_old_file_when_updating(klass = FileAttachment) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/test/backends/file_system_test.rb', line 48
def test_should_delete_old_file_when_updating(klass = FileAttachment)
attachment_model klass
attachment = upload_file :filename => '/files/rails.png'
old_filename = attachment.full_filename
assert_not_created do
use_temp_file 'files/rails.png' do |file|
attachment.filename = 'rails2.png'
attachment.temp_path = File.join(fixture_path, file)
attachment.save!
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
assert !File.exists?(old_filename), "#{old_filename} still exists"
end
end
end
|
#test_should_not_overwrite_file_attachment(klass = FileAttachment) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/test/backends/file_system_test.rb', line 17
def test_should_not_overwrite_file_attachment(klass = FileAttachment)
attachment_model klass
assert_created 2 do
real = upload_file :filename => '/files/rails.png'
assert_valid real
assert !real.new_record?, real.errors.full_messages.join("\n")
assert !real.size.zero?
fake = upload_file :filename => '/files/fake/rails.png'
assert_valid fake
assert !fake.size.zero?
assert_not_equal File.open(real.full_filename).stat.size, File.open(fake.full_filename).stat.size
end
end
|
#test_should_store_file_attachment_in_filesystem(klass = FileAttachment) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/test/backends/file_system_test.rb', line 35
def test_should_store_file_attachment_in_filesystem(klass = FileAttachment)
attachment_model klass
attachment = nil
assert_created do
attachment = upload_file :filename => '/files/rails.png'
assert_valid attachment
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
end
attachment
end
|