Commit 5955ed72b9252635177e89bb5f1ce92be6444285
1 parent
1fafa75f
Exists in
web_steps_improvements
and in
9 other branches
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.
Showing
2 changed files
with
32 additions
and
21 deletions
Show diff stats
app/views/blocks/article.html.erb
1 | <%= block_title(block.title) %> | 1 | <%= block_title(block.title) %> |
2 | <% if block.article %> | 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 | :gallery_view => false, | 5 | :gallery_view => false, |
6 | :inside_block => block, # For Blogs and folders | 6 | :inside_block => block, # For Blogs and folders |
7 | :format => block.visualization_format # For Articles and contents | 7 | :format => block.visualization_format # For Articles and contents |
8 | - ) | 8 | + )) |
9 | %> | 9 | %> |
10 | <% else %> | 10 | <% else %> |
11 | <%= _('Article not selected yet.') %> | 11 | <%= _('Article not selected yet.') %> |
test/unit/article_block_test.rb
@@ -7,15 +7,6 @@ class ArticleBlockTest < ActiveSupport::TestCase | @@ -7,15 +7,6 @@ class ArticleBlockTest < ActiveSupport::TestCase | ||
7 | assert_not_equal Block.description, ArticleBlock.description | 7 | assert_not_equal Block.description, ArticleBlock.description |
8 | end | 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 | should 'refer to an article' do | 10 | should 'refer to an article' do |
20 | profile = create_user('testuser').person | 11 | profile = create_user('testuser').person |
21 | article = profile.articles.build(:name => 'test article') | 12 | article = profile.articles.build(:name => 'test article') |
@@ -85,6 +76,30 @@ class ArticleBlockTest < ActiveSupport::TestCase | @@ -85,6 +76,30 @@ class ArticleBlockTest < ActiveSupport::TestCase | ||
85 | assert_equal [a],block.available_articles | 76 | assert_equal [a],block.available_articles |
86 | end | 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 | should "display empty title if title is blank" do | 103 | should "display empty title if title is blank" do |
89 | block = ArticleBlock.new | 104 | block = ArticleBlock.new |
90 | article = mock | 105 | article = mock |
@@ -92,7 +107,7 @@ class ArticleBlockTest < ActiveSupport::TestCase | @@ -92,7 +107,7 @@ class ArticleBlockTest < ActiveSupport::TestCase | ||
92 | block.expects(:title).returns('') | 107 | block.expects(:title).returns('') |
93 | block.stubs(:article).returns(article) | 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 | end | 111 | end |
97 | 112 | ||
98 | should "display title if defined" do | 113 | should "display title if defined" do |
@@ -102,7 +117,7 @@ class ArticleBlockTest < ActiveSupport::TestCase | @@ -102,7 +117,7 @@ class ArticleBlockTest < ActiveSupport::TestCase | ||
102 | block.expects(:title).returns('Article title') | 117 | block.expects(:title).returns('Article title') |
103 | block.stubs(:article).returns(article) | 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 | end | 121 | end |
107 | 122 | ||
108 | should 'display image if article is an image' do | 123 | should 'display image if article is an image' do |
@@ -113,7 +128,7 @@ class ArticleBlockTest < ActiveSupport::TestCase | @@ -113,7 +128,7 @@ class ArticleBlockTest < ActiveSupport::TestCase | ||
113 | block.article = image | 128 | block.article = image |
114 | block.save! | 129 | block.save! |
115 | 130 | ||
116 | - assert_tag_in_string instance_eval(&block.content), | 131 | + assert_tag_in_string render_block_content(block), |
117 | :tag => 'img', | 132 | :tag => 'img', |
118 | :attributes => { | 133 | :attributes => { |
119 | :src => image.public_filename(:display), | 134 | :src => image.public_filename(:display), |
@@ -129,7 +144,7 @@ class ArticleBlockTest < ActiveSupport::TestCase | @@ -129,7 +144,7 @@ class ArticleBlockTest < ActiveSupport::TestCase | ||
129 | block.article = image | 144 | block.article = image |
130 | block.save! | 145 | block.save! |
131 | 146 | ||
132 | - assert_no_match(/Previous/, instance_eval(&block.content)) | 147 | + assert_no_match(/Previous/, render_block_content(block)) |
133 | end | 148 | end |
134 | 149 | ||
135 | should 'display link to archive if article is an archive' do | 150 | should 'display link to archive if article is an archive' do |
@@ -141,11 +156,7 @@ class ArticleBlockTest < ActiveSupport::TestCase | @@ -141,11 +156,7 @@ class ArticleBlockTest < ActiveSupport::TestCase | ||
141 | block.save! | 156 | block.save! |
142 | 157 | ||
143 | UploadedFile.any_instance.stubs(:url).returns('myhost.mydomain/path/to/file') | 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 | end | 161 | end |
147 | - | ||
148 | - protected | ||
149 | - include NoosferoTestHelper | ||
150 | - | ||
151 | end | 162 | end |