forked from technoweenie/attachment_fu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation_test.rb
55 lines (44 loc) · 1.58 KB
/
validation_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
class ValidationTest < Test::Unit::TestCase
def test_should_invalidate_big_files
@attachment = SmallAttachment.new
assert [email protected]?
assert @attachment.errors.on(:size)
@attachment.size = 2000
assert [email protected]?
assert @attachment.errors.on(:size), @attachment.errors.full_messages.to_sentence
@attachment.size = 1000
assert [email protected]?
assert_nil @attachment.errors.on(:size)
end
def test_should_invalidate_small_files
@attachment = BigAttachment.new
assert [email protected]?
assert @attachment.errors.on(:size)
@attachment.size = 2000
assert [email protected]?
assert @attachment.errors.on(:size), @attachment.errors.full_messages.to_sentence
@attachment.size = 1.megabyte
assert [email protected]?
assert_nil @attachment.errors.on(:size)
end
def test_should_validate_content_type
@attachment = PdfAttachment.new
assert [email protected]?
assert @attachment.errors.on(:content_type)
@attachment.content_type = 'foo'
assert [email protected]?
assert @attachment.errors.on(:content_type)
@attachment.content_type = 'pdf'
assert [email protected]?
assert_nil @attachment.errors.on(:content_type)
end
def test_should_require_filename
@attachment = Attachment.new
assert [email protected]?
assert @attachment.errors.on(:filename)
@attachment.filename = 'foo'
assert [email protected]?
assert_nil @attachment.errors.on(:filename)
end
end