Skip to content
This repository
Newer
Older
100644 67 lines (53 sloc) 2.546 kb
f83683b5 »
2006-12-14 all tests pass
1 require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
7a14bcb9 »
2006-12-14 initial code with basic option/validation tests
2
3 class BasicTest < Test::Unit::TestCase
4 def test_should_set_default_min_size
5 assert_equal 1, Attachment.attachment_options[:min_size]
6 end
7
8 def test_should_set_default_max_size
9 assert_equal 1.megabyte, Attachment.attachment_options[:max_size]
10 end
11
12 def test_should_set_default_size
13 assert_equal (1..1.megabyte), Attachment.attachment_options[:size]
14 end
15
16 def test_should_set_default_thumbnails_option
17 assert_equal Hash.new, Attachment.attachment_options[:thumbnails]
18 end
19
20 def test_should_set_default_thumbnail_class
21 assert_equal Attachment, Attachment.attachment_options[:thumbnail_class]
22 end
23
24 def test_should_normalize_content_types_to_array
25 assert_equal %w(pdf), PdfAttachment.attachment_options[:content_type]
26 assert_equal %w(pdf doc txt), DocAttachment.attachment_options[:content_type]
5319e039 »
2008-01-07 add missing image/jpg content types from failing test [Giles Bowkett]
27 assert_equal ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'], ImageAttachment.attachment_options[:content_type]
28 assert_equal ['pdf', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'], ImageOrPdfAttachment.attachment_options[:content_type]
7a14bcb9 »
2006-12-14 initial code with basic option/validation tests
29 end
30
31 def test_should_sanitize_content_type
32 @attachment = Attachment.new :content_type => ' foo '
33 assert_equal 'foo', @attachment.content_type
34 end
35
36 def test_should_sanitize_filenames
37 @attachment = Attachment.new :filename => 'blah/foo.bar'
38 assert_equal 'foo.bar', @attachment.filename
39
40 @attachment.filename = 'blah\\foo.bar'
41 assert_equal 'foo.bar', @attachment.filename
42
43 @attachment.filename = 'f o!O-.bar'
44 assert_equal 'f_o_O-.bar', @attachment.filename
61ad36fb »
2008-05-16 Fixed a nil reference error in sanitize_filename
45
46 @attachment.filename = nil
47 assert_nil @attachment.filename
7a14bcb9 »
2006-12-14 initial code with basic option/validation tests
48 end
49
50 def test_should_convert_thumbnail_name
51 @attachment = FileAttachment.new :filename => 'foo.bar'
52 assert_equal 'foo.bar', @attachment.thumbnail_name_for(nil)
53 assert_equal 'foo.bar', @attachment.thumbnail_name_for('')
54 assert_equal 'foo_blah.bar', @attachment.thumbnail_name_for(:blah)
55 assert_equal 'foo_blah.blah.bar', @attachment.thumbnail_name_for('blah.blah')
56
57 @attachment.filename = 'foo.bar.baz'
58 assert_equal 'foo.bar_blah.baz', @attachment.thumbnail_name_for(:blah)
59 end
8fbfceec »
2007-04-02 Check for current type of :thumbnails option.
60
61 def test_should_require_valid_thumbnails_option
62 klass = Class.new(ActiveRecord::Base)
63 assert_raise ArgumentError do
64 klass.has_attachment :thumbnails => []
65 end
66 end
7a14bcb9 »
2006-12-14 initial code with basic option/validation tests
67 end
Something went wrong with that request. Please try again.