PageRenderTime 1039ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/plugins/attachment_fu/test/basic_test.rb

https://github.com/grantneufeld/wayground-old
Ruby | 64 lines | 51 code | 13 blank | 0 comment | 0 complexity | bb6f889236ea7f6df8d260be801d1cc9 MD5 | raw file
  1. require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
  2. class BasicTest < Test::Unit::TestCase
  3. def test_should_set_default_min_size
  4. assert_equal 1, Attachment.attachment_options[:min_size]
  5. end
  6. def test_should_set_default_max_size
  7. assert_equal 1.megabyte, Attachment.attachment_options[:max_size]
  8. end
  9. def test_should_set_default_size
  10. assert_equal (1..1.megabyte), Attachment.attachment_options[:size]
  11. end
  12. def test_should_set_default_thumbnails_option
  13. assert_equal Hash.new, Attachment.attachment_options[:thumbnails]
  14. end
  15. def test_should_set_default_thumbnail_class
  16. assert_equal Attachment, Attachment.attachment_options[:thumbnail_class]
  17. end
  18. def test_should_normalize_content_types_to_array
  19. assert_equal %w(pdf), PdfAttachment.attachment_options[:content_type]
  20. assert_equal %w(pdf doc txt), DocAttachment.attachment_options[:content_type]
  21. assert_equal ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'], ImageAttachment.attachment_options[:content_type]
  22. assert_equal ['pdf', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg'], ImageOrPdfAttachment.attachment_options[:content_type]
  23. end
  24. def test_should_sanitize_content_type
  25. @attachment = Attachment.new :content_type => ' foo '
  26. assert_equal 'foo', @attachment.content_type
  27. end
  28. def test_should_sanitize_filenames
  29. @attachment = Attachment.new :filename => 'blah/foo.bar'
  30. assert_equal 'foo.bar', @attachment.filename
  31. @attachment.filename = 'blah\\foo.bar'
  32. assert_equal 'foo.bar', @attachment.filename
  33. @attachment.filename = 'f o!O-.bar'
  34. assert_equal 'f_o_O-.bar', @attachment.filename
  35. end
  36. def test_should_convert_thumbnail_name
  37. @attachment = FileAttachment.new :filename => 'foo.bar'
  38. assert_equal 'foo.bar', @attachment.thumbnail_name_for(nil)
  39. assert_equal 'foo.bar', @attachment.thumbnail_name_for('')
  40. assert_equal 'foo_blah.bar', @attachment.thumbnail_name_for(:blah)
  41. assert_equal 'foo_blah.blah.bar', @attachment.thumbnail_name_for('blah.blah')
  42. @attachment.filename = 'foo.bar.baz'
  43. assert_equal 'foo.bar_blah.baz', @attachment.thumbnail_name_for(:blah)
  44. end
  45. def test_should_require_valid_thumbnails_option
  46. klass = Class.new(ActiveRecord::Base)
  47. assert_raise ArgumentError do
  48. klass.has_attachment :thumbnails => []
  49. end
  50. end
  51. end