Commit 88adb34ee3f2c3b3a5d34b5d34fdcfca10c900fd
Committed by
Daniela Feitosa
1 parent
f15a7f20
Exists in
master
and in
29 other branches
Check if mime_type isn't nil before try to use it
(ActionItem1891)
Showing
2 changed files
with
7 additions
and
1 deletions
Show diff stats
app/models/uploaded_file.rb
... | ... | @@ -54,7 +54,7 @@ class UploadedFile < Article |
54 | 54 | |
55 | 55 | def self.icon_name(article = nil) |
56 | 56 | if article |
57 | - article.image? ? article.public_filename(:icon) : article.mime_type.gsub(/[\/+.]/, '-') | |
57 | + article.image? ? article.public_filename(:icon) : (article.mime_type ? article.mime_type.gsub(/[\/+.]/, '-') : 'upload-file') | |
58 | 58 | else |
59 | 59 | 'upload-file' |
60 | 60 | end | ... | ... |
test/unit/uploaded_file_test.rb
... | ... | @@ -287,4 +287,10 @@ class UploadedFileTest < Test::Unit::TestCase |
287 | 287 | assert_equal '', f.lead |
288 | 288 | end |
289 | 289 | |
290 | + should 'survive when try to get icon_name from a file with mime_type nil' do | |
291 | + f = UploadedFile.new | |
292 | + f.expects(:mime_type).returns(nil) | |
293 | + assert_equal 'upload-file', UploadedFile.icon_name(f) | |
294 | + end | |
295 | + | |
290 | 296 | end | ... | ... |