From 13d40bdbca43561d81c5e7729896fa7276ab3640 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Wed, 12 May 2010 20:03:35 -0300 Subject: [PATCH] Allowing uploaded files to be added on article block --- app/helpers/application_helper.rb | 7 +++++++ app/helpers/content_viewer_helper.rb | 6 ------ app/models/article_block.rb | 7 +++++-- test/unit/article_block_test.rb | 46 +++++++++++++++++++++++++++++++++++++++++++--- test/unit/blog_helper_test.rb | 1 + test/unit/content_viewer_helper_test.rb | 1 + 6 files changed, 57 insertions(+), 11 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 75fc1f8..c530262 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -936,4 +936,11 @@ module ApplicationHelper content_for(:head) { stylesheet_link_tag(*args) } end + def article_to_html(article) + content = article.to_html(:page => params[:npage]) + return self.instance_eval(&content) if content.kind_of?(Proc) + content + end + + end diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb index 518ee86..90f3fe8 100644 --- a/app/helpers/content_viewer_helper.rb +++ b/app/helpers/content_viewer_helper.rb @@ -24,12 +24,6 @@ module ContentViewerHelper title end - def article_to_html(article) - content = article.to_html(:page => params[:npage]) - return self.instance_eval(&content) if content.kind_of?(Proc) - content - end - def link_to_comments(article) link_to( number_of_comments(article), article.url.merge(:anchor => 'comments_list') ) end diff --git a/app/models/article_block.rb b/app/models/article_block.rb index 9ea3bf1..c1cff7b 100644 --- a/app/models/article_block.rb +++ b/app/models/article_block.rb @@ -9,8 +9,11 @@ class ArticleBlock < Block end def content - block_title(title) + - (article ? article.to_html : _('Article not selected yet.')) + block = self + lambda do + block_title(block.title) + + (block.article ? article_to_html(block.article) : _('Article not selected yet.')) + end end def article_id diff --git a/test/unit/article_block_test.rb b/test/unit/article_block_test.rb index 01ca705..c4a7057 100644 --- a/test/unit/article_block_test.rb +++ b/test/unit/article_block_test.rb @@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper' class ArticleBlockTest < Test::Unit::TestCase + include ApplicationHelper + should 'describe itself' do assert_not_equal Block.description, ArticleBlock.description end @@ -12,7 +14,7 @@ class ArticleBlockTest < Test::Unit::TestCase article.expects(:to_html).returns("Article content") block.stubs(:article).returns(article) - assert_match(/Article content/, block.content) + assert_match(/Article content/, instance_eval(&block.content)) end should 'refer to an article' do @@ -58,7 +60,7 @@ class ArticleBlockTest < Test::Unit::TestCase block.expects(:title).returns('') block.stubs(:article).returns(article) - assert_equal "

Article content", block.content + assert_equal "

Article content", instance_eval(&block.content) end should "display title if defined" do @@ -68,7 +70,45 @@ class ArticleBlockTest < Test::Unit::TestCase block.expects(:title).returns('Article title') block.stubs(:article).returns(article) - assert_equal "

Article title

Article content", block.content + assert_equal "

Article title

Article content", instance_eval(&block.content) + end + + should 'display image if article is an image' do + profile = create_user('testuser').person + block = ArticleBlock.new + image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + + block.article = image + block.save! + + expects(:image_tag).with(image.public_filename(:display), :class => image.css_class_name, :style => 'max-width: 100%').returns('image') + + assert_match(/image/, instance_eval(&block.content)) + end + + should 'display link to archive if article is an archive' do + profile = create_user('testuser').person + block = ArticleBlock.new + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) + + block.article = file + block.save! + + assert_tag_in_string instance_eval(&block.content), :tag => 'a', :content => 'test.txt' end + protected + + def content_tag(tag, text, options = {}) + "<#{tag}>#{text}" + end + def image_tag(arg) + arg + end + def link_to(text, url, options = {}) + "#{text}" + end + def params + {} + end end diff --git a/test/unit/blog_helper_test.rb b/test/unit/blog_helper_test.rb index a640196..203b2ef 100644 --- a/test/unit/blog_helper_test.rb +++ b/test/unit/blog_helper_test.rb @@ -5,6 +5,7 @@ class BlogHelperTest < Test::Unit::TestCase include BlogHelper include ContentViewerHelper include ActionView::Helpers::AssetTagHelper + include ApplicationHelper def setup stubs(:show_date).returns('') diff --git a/test/unit/content_viewer_helper_test.rb b/test/unit/content_viewer_helper_test.rb index 828c071..a675c09 100644 --- a/test/unit/content_viewer_helper_test.rb +++ b/test/unit/content_viewer_helper_test.rb @@ -5,6 +5,7 @@ class ContentViewerHelperTest < Test::Unit::TestCase include ActionView::Helpers::TagHelper include ContentViewerHelper include DatesHelper + include ApplicationHelper def setup @profile = create_user('blog_helper_test').person -- libgit2 0.21.2