diff --git a/lib/file_presenter.rb b/lib/file_presenter.rb index 08c4d43..f0e926d 100644 --- a/lib/file_presenter.rb +++ b/lib/file_presenter.rb @@ -51,7 +51,12 @@ class FilePresenter end def short_description - _("File (%s)") % content_type.sub(/^application\//, '').sub(/^x-/, '').sub(/^image\//, '') + file_type = if content_type.present? + content_type.sub(/^application\//, '').sub(/^x-/, '').sub(/^image\//, '') + else + _('Unknown') + end + _("File (%s)") % file_type end # Define the css classes to style the page fragment with the file related diff --git a/test/unit/file_presenter_test.rb b/test/unit/file_presenter_test.rb index 9b0d9f7..917885f 100644 --- a/test/unit/file_presenter_test.rb +++ b/test/unit/file_presenter_test.rb @@ -62,4 +62,16 @@ class FilePresenterTest < ActiveSupport::TestCase f = FilePresenter.for(UploadedFile.new) assert f.kind_of?(UploadedFile) end + + should 'not crash with uploaded_file short description without content_type' do + f = FilePresenter.for(UploadedFile.new) + assert_nothing_raised do + f.short_description + end + end + + should 'show unknown type when file doesn\'t have a content_type' do + f = FilePresenter.for(UploadedFile.new) + assert_match /Unknown/, f.short_description + end end -- libgit2 0.21.2