Commit 3dd8a8a9313fb3d06df3518ee96ca39fb3b51b3c

Authored by Joenio Costa
Committed by Antonio Terceiro
1 parent 6d36bda8

ActionItem1228: Should show link to non-image files in article block

app/models/uploaded_file.rb
... ... @@ -50,7 +50,14 @@ class UploadedFile < Article
50 50 include ActionView::Helpers::TagHelper
51 51  
52 52 def to_html(options = {})
53   - tag('img', :src => public_filename(:display), :class => css_class_name, :style => 'max-width: 100%') if image?
  53 + if image?
  54 + tag('img', :src => public_filename(:display), :class => css_class_name, :style => 'max-width: 100%')
  55 + else
  56 + article = self
  57 + lambda do
  58 + content_tag('ul', content_tag('li', link_to(article.name, article.url, :class => article.css_class_name)))
  59 + end
  60 + end
54 61 end
55 62  
56 63 def allow_children?
... ...
test/unit/uploaded_file_test.rb
... ... @@ -109,4 +109,14 @@ class UploadedFileTest < Test::Unit::TestCase
109 109 assert_match /#{UploadedFile.max_size.to_humanreadable}/, up.errors[:size]
110 110 end
111 111  
  112 + should 'display link to download of non-image files' do
  113 + p = create_user('test_user').person
  114 + file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => p)
  115 +
  116 + stubs(:content_tag)
  117 + expects(:link_to).with(file.name, file.url, :class => file.css_class_name)
  118 +
  119 + instance_eval(&file.to_html)
  120 + end
  121 +
112 122 end
... ...