diff --git a/app/models/article.rb b/app/models/article.rb index 2209695..a7d2cba 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -151,7 +151,7 @@ class Article < ActiveRecord::Base # HTML. Other article types can override this method to provide customized # views of themselves. def to_html(options = {}) - body + body || '' end # returns the data of the article. Must be overriden in each subclass to diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 416f9b7..a7288ad 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -81,6 +81,11 @@ class ArticleTest < Test::Unit::TestCase assert_equal 'the body of the article', a.to_html end + should 'provide HTML version when body is nil' do + a = fast_create(Article, :profile_id => profile.id, :body => nil) + assert_equal '', a.to_html + end + should 'provide first paragraph of HTML version' do profile = create_user('testinguser').person a = Article.create!(:name => 'my article', :profile_id => profile.id) diff --git a/test/unit/blog_helper_test.rb b/test/unit/blog_helper_test.rb index bba2b27..6b7aadf 100644 --- a/test/unit/blog_helper_test.rb +++ b/test/unit/blog_helper_test.rb @@ -75,6 +75,15 @@ class BlogHelperTest < Test::Unit::TestCase assert_equal 'TITLE TO_HTML', display_post(article) end + should 'display empty post if body is nil' do + blog.children << article = fast_create(Article, :profile_id => profile.id, :parent_id => blog.id, :body => nil) + expects(:article_title).with(article).returns('TITLE') + expects(:content_tag).with('p', '').returns('') + self.stubs(:params).returns({:npage => nil}) + + assert_equal 'TITLE', display_post(article) + end + should 'display link to file if post is an uploaded_file' do file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => profile, :published => true, :parent => blog) -- libgit2 0.21.2