Commit 8fbf67eb3449da5a7664d668df46babd812a964c

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 41900a39

Fixing when an uploaded file is added as a blog post

(ActionItem1321)
app/helpers/blog_helper.rb
... ... @@ -38,7 +38,7 @@ module BlogHelper
38 38 end
39 39  
40 40 def display_post(article)
41   - html = article.to_html
  41 + html = article_to_html(article)
42 42 html = content_tag('p', html) if ! html.include?('</p>')
43 43 article_title(article) + html
44 44 end
... ...
test/unit/blog_helper_test.rb
... ... @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 3 class BlogHelperTest < Test::Unit::TestCase
4 4  
5 5 include BlogHelper
  6 + include ContentViewerHelper
6 7  
7 8 def setup
8 9 stubs(:show_date).returns('')
... ... @@ -50,10 +51,30 @@ class BlogHelperTest &lt; Test::Unit::TestCase
50 51 blog.children << article = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => blog, :published => true)
51 52 expects(:article_title).with(article).returns('TITLE')
52 53 expects(:content_tag).with('p', article.to_html).returns(' TO_HTML')
  54 + self.stubs(:params).returns({:npage => nil})
53 55  
54 56 assert_equal 'TITLE TO_HTML', display_post(article)
55 57 end
56 58  
  59 + should 'display link to file if post is an uploaded_file' do
  60 + file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => profile, :published => true, :parent => blog)
  61 +
  62 + expects(:article_to_html).with(file).returns('TO HTML')
  63 +
  64 + result = display_post(file)
  65 + assert_tag_in_string result, :content => /TO HTML/
  66 + end
  67 +
  68 + should 'display image if post is an image' do
  69 + file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile, :published => true, :parent => blog)
  70 +
  71 + self.stubs(:params).returns({:npage => nil})
  72 +
  73 + result = display_post(file)
  74 + assert_tag_in_string result, :content => 'rails.png'
  75 + assert_tag_in_string result, :tag => 'img', :attributes => { :src => /#{file.public_filename(:display)}/ }
  76 + end
  77 +
57 78 def will_paginate(arg1, arg2)
58 79 end
59 80  
... ...