Class: ValidationTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/test/validation_test.rb

Instance Method Summary collapse

Instance Method Details

#test_should_invalidate_big_filesObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/test/validation_test.rb', line 4

def test_should_invalidate_big_files
  @attachment = SmallAttachment.new
  assert !@attachment.valid?
  assert @attachment.errors.on(:size)
  
  @attachment.size = 2000
  assert !@attachment.valid?
  assert @attachment.errors.on(:size), @attachment.errors.full_messages.to_sentence
  
  @attachment.size = 1000
  assert !@attachment.valid?
  assert_nil @attachment.errors.on(:size)
end

#test_should_invalidate_small_filesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/test/validation_test.rb', line 18

def test_should_invalidate_small_files
  @attachment = BigAttachment.new
  assert !@attachment.valid?
  assert @attachment.errors.on(:size)
  
  @attachment.size = 2000
  assert !@attachment.valid?
  assert @attachment.errors.on(:size), @attachment.errors.full_messages.to_sentence
  
  @attachment.size = 1.megabyte
  assert !@attachment.valid?
  assert_nil @attachment.errors.on(:size)
end

#test_should_require_filenameObject



46
47
48
49
50
51
52
53
54
# File 'lib/test/validation_test.rb', line 46

def test_should_require_filename
  @attachment = Attachment.new
  assert !@attachment.valid?
  assert @attachment.errors.on(:filename)
  
  @attachment.filename = 'foo'
  assert !@attachment.valid?
  assert_nil @attachment.errors.on(:filename)
end

#test_should_validate_content_typeObject



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/test/validation_test.rb', line 32

def test_should_validate_content_type
  @attachment = PdfAttachment.new
  assert !@attachment.valid?
  assert @attachment.errors.on(:content_type)

  @attachment.content_type = 'foo'
  assert !@attachment.valid?
  assert @attachment.errors.on(:content_type)

  @attachment.content_type = 'pdf'
  assert !@attachment.valid?
  assert_nil @attachment.errors.on(:content_type)
end