Commit 88adb34ee3f2c3b3a5d34b5d34fdcfca10c900fd
Committed by
Daniela Feitosa
1 parent
f15a7f20
Exists in
master
and in
28 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,7 +54,7 @@ class UploadedFile < Article | ||
54 | 54 | ||
55 | def self.icon_name(article = nil) | 55 | def self.icon_name(article = nil) |
56 | if article | 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 | else | 58 | else |
59 | 'upload-file' | 59 | 'upload-file' |
60 | end | 60 | end |
test/unit/uploaded_file_test.rb
@@ -287,4 +287,10 @@ class UploadedFileTest < Test::Unit::TestCase | @@ -287,4 +287,10 @@ class UploadedFileTest < Test::Unit::TestCase | ||
287 | assert_equal '', f.lead | 287 | assert_equal '', f.lead |
288 | end | 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 | end | 296 | end |