Commit 5955ed72b9252635177e89bb5f1ce92be6444285

Authored by Rafael Reggiani Manzo
1 parent 1fafa75f

Fix ArticleBlock unit tests and view

By removing the content method, it is now necessary to turn the test
into a view one using the BoxesHelper method and properly stubbing other
helpers.

The view required fix at the html escaping method call synthax.
app/views/blocks/article.html.erb
1 1 <%= block_title(block.title) %>
2 2 <% if block.article %>
3   - <%=h
4   - article_to_html(FilePresenter.for(block.article),
  3 + <%=
  4 + h(article_to_html(FilePresenter.for(block.article),
5 5 :gallery_view => false,
6 6 :inside_block => block, # For Blogs and folders
7 7 :format => block.visualization_format # For Articles and contents
8   - )
  8 + ))
9 9 %>
10 10 <% else %>
11 11 <%= _('Article not selected yet.') %>
... ...
test/unit/article_block_test.rb
... ... @@ -7,15 +7,6 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
7 7 assert_not_equal Block.description, ArticleBlock.description
8 8 end
9 9  
10   - should "take article's content" do
11   - block = ArticleBlock.new
12   - article = mock
13   - article.expects(:to_html).returns("Article content")
14   - block.stubs(:article).returns(article)
15   -
16   - assert_match(/Article content/, instance_eval(&block.content))
17   - end
18   -
19 10 should 'refer to an article' do
20 11 profile = create_user('testuser').person
21 12 article = profile.articles.build(:name => 'test article')
... ... @@ -85,6 +76,30 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
85 76 assert_equal [a],block.available_articles
86 77 end
87 78  
  79 + protected
  80 + include NoosferoTestHelper
  81 +
  82 +end
  83 +
  84 +require 'boxes_helper'
  85 +require 'block_helper'
  86 +
  87 +class ArticleBlockViewTest < ActionView::TestCase
  88 + include BoxesHelper
  89 +
  90 + ActionView::Base.send :include, ApplicationHelper
  91 + ActionView::Base.send :include, BlockHelper
  92 +
  93 + should "take article's content" do
  94 + block = ArticleBlock.new
  95 + article = mock
  96 + article.expects(:to_html).returns("Article content")
  97 + block.stubs(:article).returns(article)
  98 + ActionView::Base.any_instance.stubs(:block_title).returns("")
  99 +
  100 + assert_match(/Article content/, render_block_content(block))
  101 + end
  102 +
88 103 should "display empty title if title is blank" do
89 104 block = ArticleBlock.new
90 105 article = mock
... ... @@ -92,7 +107,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
92 107 block.expects(:title).returns('')
93 108 block.stubs(:article).returns(article)
94 109  
95   - assert_equal "<h3 class=\"block-title empty\"><span></span></h3>Article content", instance_eval(&block.content)
  110 + assert_equal "<h3 class=\"block-title empty\"><span></span></h3>\n Article content\n", render_block_content(block)
96 111 end
97 112  
98 113 should "display title if defined" do
... ... @@ -102,7 +117,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
102 117 block.expects(:title).returns('Article title')
103 118 block.stubs(:article).returns(article)
104 119  
105   - assert_equal "<h3 class=\"block-title\"><span>Article title</span></h3>Article content", instance_eval(&block.content)
  120 + assert_equal "<h3 class=\"block-title\"><span>Article title</span></h3>\n Article content\n", render_block_content(block)
106 121 end
107 122  
108 123 should 'display image if article is an image' do
... ... @@ -113,7 +128,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
113 128 block.article = image
114 129 block.save!
115 130  
116   - assert_tag_in_string instance_eval(&block.content),
  131 + assert_tag_in_string render_block_content(block),
117 132 :tag => 'img',
118 133 :attributes => {
119 134 :src => image.public_filename(:display),
... ... @@ -129,7 +144,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
129 144 block.article = image
130 145 block.save!
131 146  
132   - assert_no_match(/Previous/, instance_eval(&block.content))
  147 + assert_no_match(/Previous/, render_block_content(block))
133 148 end
134 149  
135 150 should 'display link to archive if article is an archive' do
... ... @@ -141,11 +156,7 @@ class ArticleBlockTest &lt; ActiveSupport::TestCase
141 156 block.save!
142 157  
143 158 UploadedFile.any_instance.stubs(:url).returns('myhost.mydomain/path/to/file')
  159 + assert_tag_in_string render_block_content(block), :tag => 'a', :content => _('Download')
144 160  
145   - assert_tag_in_string instance_eval(&block.content), :tag => 'a', :content => _('Download')
146 161 end
147   -
148   - protected
149   - include NoosferoTestHelper
150   -
151 162 end
... ...