]> projects.mako.cc - selectricity-live/blob - vendor/plugins/attachment_fu/test/validation_test.rb
added new tests and fixtures
[selectricity-live] / vendor / plugins / attachment_fu / test / validation_test.rb
1 require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
2
3 class ValidationTest < Test::Unit::TestCase
4   def test_should_invalidate_big_files
5     @attachment = SmallAttachment.new
6     assert !@attachment.valid?
7     assert @attachment.errors.on(:size)
8     
9     @attachment.size = 2000
10     assert !@attachment.valid?
11     assert @attachment.errors.on(:size), @attachment.errors.full_messages.to_sentence
12     
13     @attachment.size = 1000
14     assert !@attachment.valid?
15     assert_nil @attachment.errors.on(:size)
16   end
17
18   def test_should_invalidate_small_files
19     @attachment = BigAttachment.new
20     assert !@attachment.valid?
21     assert @attachment.errors.on(:size)
22     
23     @attachment.size = 2000
24     assert !@attachment.valid?
25     assert @attachment.errors.on(:size), @attachment.errors.full_messages.to_sentence
26     
27     @attachment.size = 1.megabyte
28     assert !@attachment.valid?
29     assert_nil @attachment.errors.on(:size)
30   end
31   
32   def test_should_validate_content_type
33     @attachment = PdfAttachment.new
34     assert !@attachment.valid?
35     assert @attachment.errors.on(:content_type)
36
37     @attachment.content_type = 'foo'
38     assert !@attachment.valid?
39     assert @attachment.errors.on(:content_type)
40
41     @attachment.content_type = 'pdf'
42     assert !@attachment.valid?
43     assert_nil @attachment.errors.on(:content_type)
44   end
45
46   def test_should_require_filename
47     @attachment = Attachment.new
48     assert !@attachment.valid?
49     assert @attachment.errors.on(:filename)
50     
51     @attachment.filename = 'foo'
52     assert !@attachment.valid?
53     assert_nil @attachment.errors.on(:filename)
54   end
55 end

Benjamin Mako Hill || Want to submit a patch?