]> projects.mako.cc - selectricity/blob - vendor/plugins/attachment_fu/test/base_attachment_tests.rb
Added some minor TODO's for increased user funcitonality. Change email, beautify...
[selectricity] / 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_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   
28   def test_reassign_attribute_data
29     assert_created 1 do
30       attachment = upload_file :filename => '/files/rails.png'
31       assert_valid attachment
32       assert attachment.size > 0, "no data was set"
33       
34       attachment.set_temp_data 'wtf'
35       assert attachment.save_attachment?
36       attachment.save!
37       
38       assert_equal 'wtf', attachment_model.find(attachment.id).send(:current_data)
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
46       assert attachment.size > 0, "no data was set"
47       
48       attachment.set_temp_data nil
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
56       use_temp_file 'files/rails.png' do |file|
57         attachment.filename = 'rails2.png'
58         attachment.temp_paths.unshift File.join(fixture_path, file)
59         attachment.save!
60       end
61     end
62   end
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
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
77 end

Benjamin Mako Hill || Want to submit a patch?