1 require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
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)
9 @attachment.size = 2000
10 assert !@attachment.valid?
11 assert @attachment.errors.on(:size), @attachment.errors.full_messages.to_sentence
13 @attachment.size = 1000
14 assert !@attachment.valid?
15 assert_nil @attachment.errors.on(:size)
18 def test_should_invalidate_small_files
19 @attachment = BigAttachment.new
20 assert !@attachment.valid?
21 assert @attachment.errors.on(:size)
23 @attachment.size = 2000
24 assert !@attachment.valid?
25 assert @attachment.errors.on(:size), @attachment.errors.full_messages.to_sentence
27 @attachment.size = 1.megabyte
28 assert !@attachment.valid?
29 assert_nil @attachment.errors.on(:size)
32 def test_should_validate_content_type
33 @attachment = PdfAttachment.new
34 assert !@attachment.valid?
35 assert @attachment.errors.on(:content_type)
37 @attachment.content_type = 'foo'
38 assert !@attachment.valid?
39 assert @attachment.errors.on(:content_type)
41 @attachment.content_type = 'pdf'
42 assert !@attachment.valid?
43 assert_nil @attachment.errors.on(:content_type)
46 def test_should_require_filename
47 @attachment = Attachment.new
48 assert !@attachment.valid?
49 assert @attachment.errors.on(:filename)
51 @attachment.filename = 'foo'
52 assert !@attachment.valid?
53 assert_nil @attachment.errors.on(:filename)