Commit 8fbf67eb3449da5a7664d668df46babd812a964c
Committed by
Antonio Terceiro
1 parent
41900a39
Exists in
master
and in
23 other branches
Fixing when an uploaded file is added as a blog post
(ActionItem1321)
Showing
2 changed files
with
22 additions
and
1 deletions
Show diff stats
app/helpers/blog_helper.rb
| @@ -38,7 +38,7 @@ module BlogHelper | @@ -38,7 +38,7 @@ module BlogHelper | ||
| 38 | end | 38 | end |
| 39 | 39 | ||
| 40 | def display_post(article) | 40 | def display_post(article) |
| 41 | - html = article.to_html | 41 | + html = article_to_html(article) |
| 42 | html = content_tag('p', html) if ! html.include?('</p>') | 42 | html = content_tag('p', html) if ! html.include?('</p>') |
| 43 | article_title(article) + html | 43 | article_title(article) + html |
| 44 | end | 44 | end |
test/unit/blog_helper_test.rb
| @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
| 3 | class BlogHelperTest < Test::Unit::TestCase | 3 | class BlogHelperTest < Test::Unit::TestCase |
| 4 | 4 | ||
| 5 | include BlogHelper | 5 | include BlogHelper |
| 6 | + include ContentViewerHelper | ||
| 6 | 7 | ||
| 7 | def setup | 8 | def setup |
| 8 | stubs(:show_date).returns('') | 9 | stubs(:show_date).returns('') |
| @@ -50,10 +51,30 @@ class BlogHelperTest < Test::Unit::TestCase | @@ -50,10 +51,30 @@ class BlogHelperTest < Test::Unit::TestCase | ||
| 50 | blog.children << article = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => blog, :published => true) | 51 | blog.children << article = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => blog, :published => true) |
| 51 | expects(:article_title).with(article).returns('TITLE') | 52 | expects(:article_title).with(article).returns('TITLE') |
| 52 | expects(:content_tag).with('p', article.to_html).returns(' TO_HTML') | 53 | expects(:content_tag).with('p', article.to_html).returns(' TO_HTML') |
| 54 | + self.stubs(:params).returns({:npage => nil}) | ||
| 53 | 55 | ||
| 54 | assert_equal 'TITLE TO_HTML', display_post(article) | 56 | assert_equal 'TITLE TO_HTML', display_post(article) |
| 55 | end | 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 | def will_paginate(arg1, arg2) | 78 | def will_paginate(arg1, arg2) |
| 58 | end | 79 | end |
| 59 | 80 |