diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb index 9b9aa5e..c30ea09 100644 --- a/app/helpers/cms_helper.rb +++ b/app/helpers/cms_helper.rb @@ -9,4 +9,9 @@ module CmsHelper mime_type.gsub('/', '_').gsub('-', '') end + def icon_for_article(article) + icon = article.icon_name + (icon =~ /\//) ? icon : "icons-mime/#{article.icon_name}" + end + end diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index ded15b6..556d62e 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -4,7 +4,11 @@ class UploadedFile < Article has_attachment :thumbnails => { :icon => [24,24] } def icon_name - public_filename(:icon) + self.image? ? public_filename(:icon) : self.content_type.gsub('/', '-') + end + + def mime_type + content_type end end diff --git a/app/views/cms/view.rhtml b/app/views/cms/view.rhtml index fe40e72..91b16e2 100644 --- a/app/views/cms/view.rhtml +++ b/app/views/cms/view.rhtml @@ -28,7 +28,7 @@ diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index a6bb627..6abff63 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -162,4 +162,12 @@ class CmsControllerTest < Test::Unit::TestCase assert_equal 'parent_and_children', updated.include end + should 'be able to upload a file' do + flunk 'pending' + end + + should 'be able to update an uploaded file' do + flunk 'pending' + end + end diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb index 65f28d3..f99edd9 100644 --- a/test/unit/uploaded_file_test.rb +++ b/test/unit/uploaded_file_test.rb @@ -2,10 +2,23 @@ require File.dirname(__FILE__) + '/../test_helper' class UploadedFileTest < Test::Unit::TestCase - should 'return a thumbnail as icon' do + should 'return a thumbnail as icon for images ' do f = UploadedFile.new + f.expects(:image?).returns(true) f.expects(:public_filename).with(:icon).returns('/path/to/file.xyz') assert_equal '/path/to/file.xyz', f.icon_name end - + + should 'return mime-type icon for non-image files' do + f= UploadedFile.new + f.expects(:image?).returns(false) + f.expects(:content_type).returns('application/pdf') + assert_equal 'application-pdf', f.icon_name + end + + should 'use attachment_fu content_type method to return mime_type' do + f = UploadedFile.new + f.expects(:content_type).returns('application/pdf') + assert_equal 'application/pdf', f.mime_type + end end -- libgit2 0.21.2