updated top the the new version of attachment_fu plugin to work out some
[selectricity-live] / vendor / plugins / attachment_fu / test / base_attachment_tests.rb
index c9dbbd7a1018cc2477369f3acee202635a22855c..a35ab1c63eab75753eaf6a29d934d0f91aa2d00a 100644 (file)
@@ -12,13 +12,26 @@ module BaseAttachmentTests
     end
   end
   
+  def test_should_create_file_from_merb_temp_file
+    assert_created do
+      attachment = upload_merb_file :filename => '/files/foo.txt'
+      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.temp_data = 'wtf'
+      attachment.set_temp_data 'wtf'
       assert attachment.save_attachment?
       attachment.save!
       
@@ -32,7 +45,7 @@ module BaseAttachmentTests
       assert_valid attachment
       assert attachment.size > 0, "no data was set"
       
-      attachment.temp_data = nil
+      attachment.set_temp_data nil
       assert !attachment.save_attachment?
     end
   end
@@ -42,7 +55,7 @@ module BaseAttachmentTests
     assert_not_created do # no new db_file records
       use_temp_file 'files/rails.png' do |file|
         attachment.filename = 'rails2.png'
-        attachment.temp_path = File.join(fixture_path, file)
+        attachment.temp_paths.unshift File.join(fixture_path, file)
         attachment.save!
       end
     end
@@ -54,4 +67,11 @@ module BaseAttachmentTests
     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
\ No newline at end of file

Benjamin Mako Hill || Want to submit a patch?