Commit 13d40bdbca43561d81c5e7729896fa7276ab3640

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 17aa8b4c

Allowing uploaded files to be added on article block

* Moved article_to_html to ApplicationHelper

(ActionItem1526)
app/helpers/application_helper.rb
@@ -936,4 +936,11 @@ module ApplicationHelper @@ -936,4 +936,11 @@ module ApplicationHelper
936 content_for(:head) { stylesheet_link_tag(*args) } 936 content_for(:head) { stylesheet_link_tag(*args) }
937 end 937 end
938 938
  939 + def article_to_html(article)
  940 + content = article.to_html(:page => params[:npage])
  941 + return self.instance_eval(&content) if content.kind_of?(Proc)
  942 + content
  943 + end
  944 +
  945 +
939 end 946 end
app/helpers/content_viewer_helper.rb
@@ -24,12 +24,6 @@ module ContentViewerHelper @@ -24,12 +24,6 @@ module ContentViewerHelper
24 title 24 title
25 end 25 end
26 26
27 - def article_to_html(article)  
28 - content = article.to_html(:page => params[:npage])  
29 - return self.instance_eval(&content) if content.kind_of?(Proc)  
30 - content  
31 - end  
32 -  
33 def link_to_comments(article) 27 def link_to_comments(article)
34 link_to( number_of_comments(article), article.url.merge(:anchor => 'comments_list') ) 28 link_to( number_of_comments(article), article.url.merge(:anchor => 'comments_list') )
35 end 29 end
app/models/article_block.rb
@@ -9,8 +9,11 @@ class ArticleBlock < Block @@ -9,8 +9,11 @@ class ArticleBlock < Block
9 end 9 end
10 10
11 def content 11 def content
12 - block_title(title) +  
13 - (article ? article.to_html : _('Article not selected yet.')) 12 + block = self
  13 + lambda do
  14 + block_title(block.title) +
  15 + (block.article ? article_to_html(block.article) : _('Article not selected yet.'))
  16 + end
14 end 17 end
15 18
16 def article_id 19 def article_id
test/unit/article_block_test.rb
@@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper' @@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper'
2 2
3 class ArticleBlockTest < Test::Unit::TestCase 3 class ArticleBlockTest < Test::Unit::TestCase
4 4
  5 + include ApplicationHelper
  6 +
5 should 'describe itself' do 7 should 'describe itself' do
6 assert_not_equal Block.description, ArticleBlock.description 8 assert_not_equal Block.description, ArticleBlock.description
7 end 9 end
@@ -12,7 +14,7 @@ class ArticleBlockTest &lt; Test::Unit::TestCase @@ -12,7 +14,7 @@ class ArticleBlockTest &lt; Test::Unit::TestCase
12 article.expects(:to_html).returns("Article content") 14 article.expects(:to_html).returns("Article content")
13 block.stubs(:article).returns(article) 15 block.stubs(:article).returns(article)
14 16
15 - assert_match(/Article content/, block.content) 17 + assert_match(/Article content/, instance_eval(&block.content))
16 end 18 end
17 19
18 should 'refer to an article' do 20 should 'refer to an article' do
@@ -58,7 +60,7 @@ class ArticleBlockTest &lt; Test::Unit::TestCase @@ -58,7 +60,7 @@ class ArticleBlockTest &lt; Test::Unit::TestCase
58 block.expects(:title).returns('') 60 block.expects(:title).returns('')
59 block.stubs(:article).returns(article) 61 block.stubs(:article).returns(article)
60 62
61 - assert_equal "<h3 class=\"block-title empty\"></h3>Article content", block.content 63 + assert_equal "<h3></h3>Article content", instance_eval(&block.content)
62 end 64 end
63 65
64 should "display title if defined" do 66 should "display title if defined" do
@@ -68,7 +70,45 @@ class ArticleBlockTest &lt; Test::Unit::TestCase @@ -68,7 +70,45 @@ class ArticleBlockTest &lt; Test::Unit::TestCase
68 block.expects(:title).returns('Article title') 70 block.expects(:title).returns('Article title')
69 block.stubs(:article).returns(article) 71 block.stubs(:article).returns(article)
70 72
71 - assert_equal "<h3 class=\"block-title\">Article title</h3>Article content", block.content 73 + assert_equal "<h3>Article title</h3>Article content", instance_eval(&block.content)
  74 + end
  75 +
  76 + should 'display image if article is an image' do
  77 + profile = create_user('testuser').person
  78 + block = ArticleBlock.new
  79 + image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
  80 +
  81 + block.article = image
  82 + block.save!
  83 +
  84 + expects(:image_tag).with(image.public_filename(:display), :class => image.css_class_name, :style => 'max-width: 100%').returns('image')
  85 +
  86 + assert_match(/image/, instance_eval(&block.content))
  87 + end
  88 +
  89 + should 'display link to archive if article is an archive' do
  90 + profile = create_user('testuser').person
  91 + block = ArticleBlock.new
  92 + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'))
  93 +
  94 + block.article = file
  95 + block.save!
  96 +
  97 + assert_tag_in_string instance_eval(&block.content), :tag => 'a', :content => 'test.txt'
72 end 98 end
73 99
  100 + protected
  101 +
  102 + def content_tag(tag, text, options = {})
  103 + "<#{tag}>#{text}</#{tag}>"
  104 + end
  105 + def image_tag(arg)
  106 + arg
  107 + end
  108 + def link_to(text, url, options = {})
  109 + "<a href='#{url.to_s}'>#{text}</a>"
  110 + end
  111 + def params
  112 + {}
  113 + end
74 end 114 end
test/unit/blog_helper_test.rb
@@ -5,6 +5,7 @@ class BlogHelperTest &lt; Test::Unit::TestCase @@ -5,6 +5,7 @@ class BlogHelperTest &lt; Test::Unit::TestCase
5 include BlogHelper 5 include BlogHelper
6 include ContentViewerHelper 6 include ContentViewerHelper
7 include ActionView::Helpers::AssetTagHelper 7 include ActionView::Helpers::AssetTagHelper
  8 + include ApplicationHelper
8 9
9 def setup 10 def setup
10 stubs(:show_date).returns('') 11 stubs(:show_date).returns('')
test/unit/content_viewer_helper_test.rb
@@ -5,6 +5,7 @@ class ContentViewerHelperTest &lt; Test::Unit::TestCase @@ -5,6 +5,7 @@ class ContentViewerHelperTest &lt; Test::Unit::TestCase
5 include ActionView::Helpers::TagHelper 5 include ActionView::Helpers::TagHelper
6 include ContentViewerHelper 6 include ContentViewerHelper
7 include DatesHelper 7 include DatesHelper
  8 + include ApplicationHelper
8 9
9 def setup 10 def setup
10 @profile = create_user('blog_helper_test').person 11 @profile = create_user('blog_helper_test').person