Commit 0d2f2d57738e4c1989ab3c07fda9437edb8a476f

Authored by AntonioTerceiro
1 parent 46cba55f

ActionItem24: checkpoint



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1135 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/cms_helper.rb
@@ -9,4 +9,9 @@ module CmsHelper @@ -9,4 +9,9 @@ module CmsHelper
9 mime_type.gsub('/', '_').gsub('-', '') 9 mime_type.gsub('/', '_').gsub('-', '')
10 end 10 end
11 11
  12 + def icon_for_article(article)
  13 + icon = article.icon_name
  14 + (icon =~ /\//) ? icon : "icons-mime/#{article.icon_name}"
  15 + end
  16 +
12 end 17 end
app/models/uploaded_file.rb
@@ -4,7 +4,11 @@ class UploadedFile < Article @@ -4,7 +4,11 @@ class UploadedFile < Article
4 has_attachment :thumbnails => { :icon => [24,24] } 4 has_attachment :thumbnails => { :icon => [24,24] }
5 5
6 def icon_name 6 def icon_name
7 - public_filename(:icon) 7 + self.image? ? public_filename(:icon) : self.content_type.gsub('/', '-')
  8 + end
  9 +
  10 + def mime_type
  11 + content_type
8 end 12 end
9 13
10 end 14 end
app/views/cms/view.rhtml
@@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
28 <ul> 28 <ul>
29 <% @subitems.each do |item| %> 29 <% @subitems.each do |item| %>
30 <li> 30 <li>
31 - <%= file_manager_button(item.name, "icons-mime/#{item.icon_name}", :action => 'view', :id => item.id) %> 31 + <%= file_manager_button(item.name, icon_for_article(item), :action => 'view', :id => item.id) %>
32 </li> 32 </li>
33 <% end %> 33 <% end %>
34 </ul> 34 </ul>
test/functional/cms_controller_test.rb
@@ -162,4 +162,12 @@ class CmsControllerTest &lt; Test::Unit::TestCase @@ -162,4 +162,12 @@ class CmsControllerTest &lt; Test::Unit::TestCase
162 assert_equal 'parent_and_children', updated.include 162 assert_equal 'parent_and_children', updated.include
163 end 163 end
164 164
  165 + should 'be able to upload a file' do
  166 + flunk 'pending'
  167 + end
  168 +
  169 + should 'be able to update an uploaded file' do
  170 + flunk 'pending'
  171 + end
  172 +
165 end 173 end
test/unit/uploaded_file_test.rb
@@ -2,10 +2,23 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39; @@ -2,10 +2,23 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
2 2
3 class UploadedFileTest < Test::Unit::TestCase 3 class UploadedFileTest < Test::Unit::TestCase
4 4
5 - should 'return a thumbnail as icon' do 5 + should 'return a thumbnail as icon for images ' do
6 f = UploadedFile.new 6 f = UploadedFile.new
  7 + f.expects(:image?).returns(true)
7 f.expects(:public_filename).with(:icon).returns('/path/to/file.xyz') 8 f.expects(:public_filename).with(:icon).returns('/path/to/file.xyz')
8 assert_equal '/path/to/file.xyz', f.icon_name 9 assert_equal '/path/to/file.xyz', f.icon_name
9 end 10 end
10 - 11 +
  12 + should 'return mime-type icon for non-image files' do
  13 + f= UploadedFile.new
  14 + f.expects(:image?).returns(false)
  15 + f.expects(:content_type).returns('application/pdf')
  16 + assert_equal 'application-pdf', f.icon_name
  17 + end
  18 +
  19 + should 'use attachment_fu content_type method to return mime_type' do
  20 + f = UploadedFile.new
  21 + f.expects(:content_type).returns('application/pdf')
  22 + assert_equal 'application/pdf', f.mime_type
  23 + end
11 end 24 end