From 8fbf67eb3449da5a7664d668df46babd812a964c Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Fri, 11 Dec 2009 18:31:51 -0300 Subject: [PATCH] Fixing when an uploaded file is added as a blog post --- app/helpers/blog_helper.rb | 2 +- test/unit/blog_helper_test.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb index 394d8ea..218126c 100644 --- a/app/helpers/blog_helper.rb +++ b/app/helpers/blog_helper.rb @@ -38,7 +38,7 @@ module BlogHelper end def display_post(article) - html = article.to_html + html = article_to_html(article) html = content_tag('p', html) if ! html.include?('

') article_title(article) + html end diff --git a/test/unit/blog_helper_test.rb b/test/unit/blog_helper_test.rb index 1d0e0ed..1b23084 100644 --- a/test/unit/blog_helper_test.rb +++ b/test/unit/blog_helper_test.rb @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' class BlogHelperTest < Test::Unit::TestCase include BlogHelper + include ContentViewerHelper def setup stubs(:show_date).returns('') @@ -50,10 +51,30 @@ class BlogHelperTest < Test::Unit::TestCase blog.children << article = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => blog, :published => true) expects(:article_title).with(article).returns('TITLE') expects(:content_tag).with('p', article.to_html).returns(' TO_HTML') + self.stubs(:params).returns({:npage => nil}) assert_equal 'TITLE TO_HTML', display_post(article) end + should 'display link to file if post is an uploaded_file' do + file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => profile, :published => true, :parent => blog) + + expects(:article_to_html).with(file).returns('TO HTML') + + result = display_post(file) + assert_tag_in_string result, :content => /TO HTML/ + end + + should 'display image if post is an image' do + file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile, :published => true, :parent => blog) + + self.stubs(:params).returns({:npage => nil}) + + result = display_post(file) + assert_tag_in_string result, :content => 'rails.png' + assert_tag_in_string result, :tag => 'img', :attributes => { :src => /#{file.public_filename(:display)}/ } + end + def will_paginate(arg1, arg2) end -- libgit2 0.21.2