Commit 6c59ac4a8cfd8089927917718a312493c77a578a
1 parent
92746476
Exists in
master
and in
29 other branches
Fix: avoid crashing when displaying articles
On environments created before including =spam_comments_count=, the visualization of number of comments was crashing because it was nil Fixes #31
Showing
2 changed files
with
9 additions
and
1 deletions
Show diff stats
app/helpers/content_viewer_helper.rb
... | ... | @@ -10,7 +10,7 @@ module ContentViewerHelper |
10 | 10 | end |
11 | 11 | |
12 | 12 | def number_of_comments(article) |
13 | - display_number_of_comments(article.comments_count - article.spam_comments_count) | |
13 | + display_number_of_comments(article.comments_count - article.spam_comments_count.to_i) | |
14 | 14 | end |
15 | 15 | |
16 | 16 | def article_title(article, args = {}) | ... | ... |
test/unit/content_viewer_helper_test.rb
... | ... | @@ -83,6 +83,14 @@ class ContentViewerHelperTest < ActiveSupport::TestCase |
83 | 83 | assert_equal '', result |
84 | 84 | end |
85 | 85 | |
86 | + should 'not crash if spam_comments_count is nil' do | |
87 | + article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) | |
88 | + article.stubs(:comments_count).returns(10) | |
89 | + article.stubs(:spam_comments_count).returns(nil) | |
90 | + result = number_of_comments(article) | |
91 | + assert_match /10 comments/, result | |
92 | + end | |
93 | + | |
86 | 94 | should 'not list feed article' do |
87 | 95 | profile.articles << Blog.new(:name => 'Blog test', :profile => profile) |
88 | 96 | assert_includes profile.blog.children.map{|i| i.class}, RssFeed | ... | ... |