Commit c265698665dfd0ae007706b61a6ccf83549e61b6
1 parent
b2cd2f0b
Exists in
master
and in
29 other branches
Removed comments message when it's not enabled on article
(ActionItem1888)
Showing
2 changed files
with
28 additions
and
2 deletions
Show diff stats
app/helpers/content_viewer_helper.rb
@@ -20,14 +20,18 @@ module ContentViewerHelper | @@ -20,14 +20,18 @@ module ContentViewerHelper | ||
20 | unless args[:no_link] | 20 | unless args[:no_link] |
21 | title = content_tag('h1', link_to(article.name, article.url), :class => 'title') | 21 | title = content_tag('h1', link_to(article.name, article.url), :class => 'title') |
22 | end | 22 | end |
23 | - comments = args[:no_comments] ? '' : (("- %s") % link_to_comments(article)) | 23 | + comments = '' |
24 | + unless args[:no_comments] || !article.accept_comments | ||
25 | + comments = ("- %s") % link_to_comments(article) | ||
26 | + end | ||
24 | 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') | 27 | 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') |
25 | end | 28 | end |
26 | title | 29 | title |
27 | end | 30 | end |
28 | 31 | ||
29 | def link_to_comments(article, args = {}) | 32 | def link_to_comments(article, args = {}) |
30 | - link_to( number_of_comments(article), article.url.merge(:anchor => 'comments_list') ) | 33 | + return '' unless article.accept_comments? |
34 | + link_to(number_of_comments(article), article.url.merge(:anchor => 'comments_list') ) | ||
31 | end | 35 | end |
32 | 36 | ||
33 | def article_translations(article) | 37 | def article_translations(article) |
test/unit/content_viewer_helper_test.rb
@@ -46,6 +46,20 @@ class ContentViewerHelperTest < Test::Unit::TestCase | @@ -46,6 +46,20 @@ class ContentViewerHelperTest < Test::Unit::TestCase | ||
46 | assert_no_match /a href='#{article.url}'>#{article.name}</, result | 46 | assert_no_match /a href='#{article.url}'>#{article.name}</, result |
47 | end | 47 | end |
48 | 48 | ||
49 | + should 'not create link to comments if called with no_comments' do | ||
50 | + blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) | ||
51 | + article = fast_create(TextileArticle, :name => 'art test', :profile_id => profile.id, :parent_id => blog.id) | ||
52 | + result = article_title(article, :no_comments => true) | ||
53 | + assert_no_match(/a href='.*comments_list.*>No comments yet</, result) | ||
54 | + end | ||
55 | + | ||
56 | + should 'not create link to comments if the article doesn\'t allow comments' do | ||
57 | + blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) | ||
58 | + article = fast_create(TextileArticle, :name => 'art test', :profile_id => profile.id, :parent_id => blog.id, :accept_comments => false) | ||
59 | + result = article_title(article) | ||
60 | + assert_no_match(/a href='.*comments_list.*>No comments yet</, result) | ||
61 | + end | ||
62 | + | ||
49 | should 'count total of comments from post' do | 63 | should 'count total of comments from post' do |
50 | article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile) | 64 | article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile) |
51 | article.stubs(:url).returns({}) | 65 | article.stubs(:url).returns({}) |
@@ -54,6 +68,14 @@ class ContentViewerHelperTest < Test::Unit::TestCase | @@ -54,6 +68,14 @@ class ContentViewerHelperTest < Test::Unit::TestCase | ||
54 | assert_match /One comment/, result | 68 | assert_match /One comment/, result |
55 | end | 69 | end |
56 | 70 | ||
71 | + should 'not display total of comments if the article doesn\'t allow comments' do | ||
72 | + article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile, :accept_comments => false) | ||
73 | + article.stubs(:url).returns({}) | ||
74 | + article.stubs(:comments).returns([Comment.new(:author => profile, :title => 'test', :body => 'test')]) | ||
75 | + result = link_to_comments(article) | ||
76 | + assert_equal '', result | ||
77 | + end | ||
78 | + | ||
57 | should 'not list feed article' do | 79 | should 'not list feed article' do |
58 | profile.articles << Blog.new(:name => 'Blog test', :profile => profile) | 80 | profile.articles << Blog.new(:name => 'Blog test', :profile => profile) |
59 | assert_includes profile.blog.children.map{|i| i.class}, RssFeed | 81 | assert_includes profile.blog.children.map{|i| i.class}, RssFeed |