Commit 757d3ea561470e88758c67e8a8fb2d484eaa9f00
Committed by
Antonio Terceiro
1 parent
bf45b411
Exists in
master
and in
29 other branches
Method to_html returns '' when body is nil
(ActionItem1455)
Showing
3 changed files
with
15 additions
and
1 deletions
Show diff stats
app/models/article.rb
@@ -151,7 +151,7 @@ class Article < ActiveRecord::Base | @@ -151,7 +151,7 @@ class Article < ActiveRecord::Base | ||
151 | # HTML. Other article types can override this method to provide customized | 151 | # HTML. Other article types can override this method to provide customized |
152 | # views of themselves. | 152 | # views of themselves. |
153 | def to_html(options = {}) | 153 | def to_html(options = {}) |
154 | - body | 154 | + body || '' |
155 | end | 155 | end |
156 | 156 | ||
157 | # returns the data of the article. Must be overriden in each subclass to | 157 | # returns the data of the article. Must be overriden in each subclass to |
test/unit/article_test.rb
@@ -81,6 +81,11 @@ class ArticleTest < Test::Unit::TestCase | @@ -81,6 +81,11 @@ class ArticleTest < Test::Unit::TestCase | ||
81 | assert_equal 'the body of the article', a.to_html | 81 | assert_equal 'the body of the article', a.to_html |
82 | end | 82 | end |
83 | 83 | ||
84 | + should 'provide HTML version when body is nil' do | ||
85 | + a = fast_create(Article, :profile_id => profile.id, :body => nil) | ||
86 | + assert_equal '', a.to_html | ||
87 | + end | ||
88 | + | ||
84 | should 'provide first paragraph of HTML version' do | 89 | should 'provide first paragraph of HTML version' do |
85 | profile = create_user('testinguser').person | 90 | profile = create_user('testinguser').person |
86 | a = Article.create!(:name => 'my article', :profile_id => profile.id) | 91 | a = Article.create!(:name => 'my article', :profile_id => profile.id) |
test/unit/blog_helper_test.rb
@@ -75,6 +75,15 @@ class BlogHelperTest < Test::Unit::TestCase | @@ -75,6 +75,15 @@ class BlogHelperTest < Test::Unit::TestCase | ||
75 | assert_equal 'TITLE TO_HTML', display_post(article) | 75 | assert_equal 'TITLE TO_HTML', display_post(article) |
76 | end | 76 | end |
77 | 77 | ||
78 | + should 'display empty post if body is nil' do | ||
79 | + blog.children << article = fast_create(Article, :profile_id => profile.id, :parent_id => blog.id, :body => nil) | ||
80 | + expects(:article_title).with(article).returns('TITLE') | ||
81 | + expects(:content_tag).with('p', '').returns('') | ||
82 | + self.stubs(:params).returns({:npage => nil}) | ||
83 | + | ||
84 | + assert_equal 'TITLE', display_post(article) | ||
85 | + end | ||
86 | + | ||
78 | should 'display link to file if post is an uploaded_file' do | 87 | should 'display link to file if post is an uploaded_file' do |
79 | file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => profile, :published => true, :parent => blog) | 88 | file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => profile, :published => true, :parent => blog) |
80 | 89 |