Commit 13d40bdbca43561d81c5e7729896fa7276ab3640
Committed by
Antonio Terceiro
1 parent
17aa8b4c
Exists in
master
and in
29 other branches
Allowing uploaded files to be added on article block
* Moved article_to_html to ApplicationHelper (ActionItem1526)
Showing
6 changed files
with
57 additions
and
11 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -936,4 +936,11 @@ module ApplicationHelper |
936 | 936 | content_for(:head) { stylesheet_link_tag(*args) } |
937 | 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 | 946 | end | ... | ... |
app/helpers/content_viewer_helper.rb
... | ... | @@ -24,12 +24,6 @@ module ContentViewerHelper |
24 | 24 | title |
25 | 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 | 27 | def link_to_comments(article) |
34 | 28 | link_to( number_of_comments(article), article.url.merge(:anchor => 'comments_list') ) |
35 | 29 | end | ... | ... |
app/models/article_block.rb
... | ... | @@ -9,8 +9,11 @@ class ArticleBlock < Block |
9 | 9 | end |
10 | 10 | |
11 | 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 | 17 | end |
15 | 18 | |
16 | 19 | def article_id | ... | ... |
test/unit/article_block_test.rb
... | ... | @@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class ArticleBlockTest < Test::Unit::TestCase |
4 | 4 | |
5 | + include ApplicationHelper | |
6 | + | |
5 | 7 | should 'describe itself' do |
6 | 8 | assert_not_equal Block.description, ArticleBlock.description |
7 | 9 | end |
... | ... | @@ -12,7 +14,7 @@ class ArticleBlockTest < Test::Unit::TestCase |
12 | 14 | article.expects(:to_html).returns("Article content") |
13 | 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 | 18 | end |
17 | 19 | |
18 | 20 | should 'refer to an article' do |
... | ... | @@ -58,7 +60,7 @@ class ArticleBlockTest < Test::Unit::TestCase |
58 | 60 | block.expects(:title).returns('') |
59 | 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 | 64 | end |
63 | 65 | |
64 | 66 | should "display title if defined" do |
... | ... | @@ -68,7 +70,45 @@ class ArticleBlockTest < Test::Unit::TestCase |
68 | 70 | block.expects(:title).returns('Article title') |
69 | 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 | 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 | 114 | end | ... | ... |
test/unit/blog_helper_test.rb
test/unit/content_viewer_helper_test.rb