Commit 74d02a29089732f690ac959b1a7ef8810ab2d4ec
1 parent
131144ba
Exists in
master
and in
28 other branches
file_presenter: display unknown type when file has no content_type
(ActionItem3049)
Showing
2 changed files
with
18 additions
and
1 deletions
Show diff stats
lib/file_presenter.rb
| @@ -51,7 +51,12 @@ class FilePresenter | @@ -51,7 +51,12 @@ class FilePresenter | ||
| 51 | end | 51 | end |
| 52 | 52 | ||
| 53 | def short_description | 53 | def short_description |
| 54 | - _("File (%s)") % content_type.sub(/^application\//, '').sub(/^x-/, '').sub(/^image\//, '') | 54 | + file_type = if content_type.present? |
| 55 | + content_type.sub(/^application\//, '').sub(/^x-/, '').sub(/^image\//, '') | ||
| 56 | + else | ||
| 57 | + _('Unknown') | ||
| 58 | + end | ||
| 59 | + _("File (%s)") % file_type | ||
| 55 | end | 60 | end |
| 56 | 61 | ||
| 57 | # Define the css classes to style the page fragment with the file related | 62 | # Define the css classes to style the page fragment with the file related |
test/unit/file_presenter_test.rb
| @@ -62,4 +62,16 @@ class FilePresenterTest < ActiveSupport::TestCase | @@ -62,4 +62,16 @@ class FilePresenterTest < ActiveSupport::TestCase | ||
| 62 | f = FilePresenter.for(UploadedFile.new) | 62 | f = FilePresenter.for(UploadedFile.new) |
| 63 | assert f.kind_of?(UploadedFile) | 63 | assert f.kind_of?(UploadedFile) |
| 64 | end | 64 | end |
| 65 | + | ||
| 66 | + should 'not crash with uploaded_file short description without content_type' do | ||
| 67 | + f = FilePresenter.for(UploadedFile.new) | ||
| 68 | + assert_nothing_raised do | ||
| 69 | + f.short_description | ||
| 70 | + end | ||
| 71 | + end | ||
| 72 | + | ||
| 73 | + should 'show unknown type when file doesn\'t have a content_type' do | ||
| 74 | + f = FilePresenter.for(UploadedFile.new) | ||
| 75 | + assert_match /Unknown/, f.short_description | ||
| 76 | + end | ||
| 65 | end | 77 | end |