Class: BasicTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- BasicTest
- Defined in:
- lib/test/basic_test.rb
Instance Method Summary collapse
- #test_should_convert_thumbnail_name ⇒ Object
- #test_should_normalize_content_types_to_array ⇒ Object
- #test_should_require_valid_thumbnails_option ⇒ Object
- #test_should_sanitize_content_type ⇒ Object
- #test_should_sanitize_filenames ⇒ Object
- #test_should_set_default_max_size ⇒ Object
- #test_should_set_default_min_size ⇒ Object
- #test_should_set_default_size ⇒ Object
- #test_should_set_default_thumbnail_class ⇒ Object
- #test_should_set_default_thumbnails_option ⇒ Object
Instance Method Details
#test_should_convert_thumbnail_name ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/test/basic_test.rb', line 47 def test_should_convert_thumbnail_name @attachment = FileAttachment.new :filename => 'foo.bar' assert_equal 'foo.bar', @attachment.thumbnail_name_for(nil) assert_equal 'foo.bar', @attachment.thumbnail_name_for('') assert_equal 'foo_blah.bar', @attachment.thumbnail_name_for(:blah) assert_equal 'foo_blah.blah.bar', @attachment.thumbnail_name_for('blah.blah') @attachment.filename = 'foo.bar.baz' assert_equal 'foo.bar_blah.baz', @attachment.thumbnail_name_for(:blah) end |
#test_should_normalize_content_types_to_array ⇒ Object
24 25 26 27 28 29 |
# File 'lib/test/basic_test.rb', line 24 def test_should_normalize_content_types_to_array assert_equal %w(pdf), PdfAttachment.[:content_type] assert_equal %w(pdf doc txt), DocAttachment.[:content_type] assert_equal ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'], ImageAttachment.[:content_type] assert_equal ['pdf', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'], ImageOrPdfAttachment.[:content_type] end |
#test_should_require_valid_thumbnails_option ⇒ Object
58 59 60 61 62 63 |
# File 'lib/test/basic_test.rb', line 58 def test_should_require_valid_thumbnails_option klass = Class.new(ActiveRecord::Base) assert_raise ArgumentError do klass. :thumbnails => [] end end |
#test_should_sanitize_content_type ⇒ Object
31 32 33 34 |
# File 'lib/test/basic_test.rb', line 31 def test_should_sanitize_content_type @attachment = Attachment.new :content_type => ' foo ' assert_equal 'foo', @attachment.content_type end |
#test_should_sanitize_filenames ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/test/basic_test.rb', line 36 def test_should_sanitize_filenames @attachment = Attachment.new :filename => 'blah/foo.bar' assert_equal 'foo.bar', @attachment.filename @attachment.filename = 'blah\\foo.bar' assert_equal 'foo.bar', @attachment.filename @attachment.filename = 'f o!O-.bar' assert_equal 'f_o_O-.bar', @attachment.filename end |
#test_should_set_default_max_size ⇒ Object
8 9 10 |
# File 'lib/test/basic_test.rb', line 8 def test_should_set_default_max_size assert_equal 1.megabyte, Attachment.[:max_size] end |
#test_should_set_default_min_size ⇒ Object
4 5 6 |
# File 'lib/test/basic_test.rb', line 4 def test_should_set_default_min_size assert_equal 1, Attachment.[:min_size] end |
#test_should_set_default_size ⇒ Object
12 13 14 |
# File 'lib/test/basic_test.rb', line 12 def test_should_set_default_size assert_equal (1..1.megabyte), Attachment.[:size] end |
#test_should_set_default_thumbnail_class ⇒ Object
20 21 22 |
# File 'lib/test/basic_test.rb', line 20 def test_should_set_default_thumbnail_class assert_equal Attachment, Attachment.[:thumbnail_class] end |
#test_should_set_default_thumbnails_option ⇒ Object
16 17 18 |
# File 'lib/test/basic_test.rb', line 16 def test_should_set_default_thumbnails_option assert_equal Hash.new, Attachment.[:thumbnails] end |