diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb index 8fc4960..4077617 100644 --- a/app/helpers/content_viewer_helper.rb +++ b/app/helpers/content_viewer_helper.rb @@ -20,14 +20,18 @@ module ContentViewerHelper unless args[:no_link] title = content_tag('h1', link_to(article.name, article.url), :class => 'title') end - comments = args[:no_comments] ? '' : (("- %s") % link_to_comments(article)) + comments = '' + unless args[:no_comments] || !article.accept_comments + comments = ("- %s") % link_to_comments(article) + end title << content_tag('span', _("%s, by %s %s") % [show_date(article.published_at), link_to(article.author_name, article.author.url), comments], :class => 'created-at') end title end def link_to_comments(article, args = {}) - link_to( number_of_comments(article), article.url.merge(:anchor => 'comments_list') ) + return '' unless article.accept_comments? + link_to(number_of_comments(article), article.url.merge(:anchor => 'comments_list') ) end def article_translations(article) diff --git a/test/unit/content_viewer_helper_test.rb b/test/unit/content_viewer_helper_test.rb index b04d27e..e3e36ed 100644 --- a/test/unit/content_viewer_helper_test.rb +++ b/test/unit/content_viewer_helper_test.rb @@ -46,6 +46,20 @@ class ContentViewerHelperTest < Test::Unit::TestCase assert_no_match /a href='#{article.url}'>#{article.name} 'Blog test', :profile_id => profile.id) + article = fast_create(TextileArticle, :name => 'art test', :profile_id => profile.id, :parent_id => blog.id) + result = article_title(article, :no_comments => true) + assert_no_match(/a href='.*comments_list.*>No comments yet 'Blog test', :profile_id => profile.id) + article = fast_create(TextileArticle, :name => 'art test', :profile_id => profile.id, :parent_id => blog.id, :accept_comments => false) + result = article_title(article) + assert_no_match(/a href='.*comments_list.*>No comments yet 'first post for test', :body => 'first post for test', :profile => profile) article.stubs(:url).returns({}) @@ -54,6 +68,14 @@ class ContentViewerHelperTest < Test::Unit::TestCase assert_match /One comment/, result end + should 'not display total of comments if the article doesn\'t allow comments' do + article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile, :accept_comments => false) + article.stubs(:url).returns({}) + article.stubs(:comments).returns([Comment.new(:author => profile, :title => 'test', :body => 'test')]) + result = link_to_comments(article) + assert_equal '', result + end + should 'not list feed article' do profile.articles << Blog.new(:name => 'Blog test', :profile => profile) assert_includes profile.blog.children.map{|i| i.class}, RssFeed -- libgit2 0.21.2