]> projects.mako.cc - selectricity-live/blob - vendor/plugins/attachment_fu/test/base_attachment_tests.rb
scrollbar appears if two many electons on control panel. ooks pretty nasty.
[selectricity-live] / vendor / plugins / attachment_fu / test / base_attachment_tests.rb
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   
15   def test_reassign_attribute_data
16     assert_created 1 do
17       attachment = upload_file :filename => '/files/rails.png'
18       assert_valid attachment
19       assert attachment.size > 0, "no data was set"
20       
21       attachment.temp_data = 'wtf'
22       assert attachment.save_attachment?
23       attachment.save!
24       
25       assert_equal 'wtf', attachment_model.find(attachment.id).send(:current_data)
26     end
27   end
28   
29   def test_no_reassign_attribute_data_on_nil
30     assert_created 1 do
31       attachment = upload_file :filename => '/files/rails.png'
32       assert_valid attachment
33       assert attachment.size > 0, "no data was set"
34       
35       attachment.temp_data = nil
36       assert !attachment.save_attachment?
37     end
38   end
39   
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)
46         attachment.save!
47       end
48     end
49   end
50   
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! }
56   end
57 end

Benjamin Mako Hill || Want to submit a patch?