Commit bec3c316d252fa848e8e0de03585c07afbd48319

Authored by Caio Almeida
Committed by Antonio Terceiro
1 parent 2b95ed8b

Forum posts receive comments by default

(ActionItem1769)
app/helpers/application_helper.rb
@@ -904,6 +904,7 @@ module ApplicationHelper @@ -904,6 +904,7 @@ module ApplicationHelper
904 904
905 def helper_for_article(article) 905 def helper_for_article(article)
906 article_helper = ActionView::Base.new 906 article_helper = ActionView::Base.new
  907 + article_helper.controller = controller
907 article_helper.extend ArticleHelper 908 article_helper.extend ArticleHelper
908 begin 909 begin
909 class_name = article.class.name + 'Helper' 910 class_name = article.class.name + 'Helper'
app/helpers/article_helper.rb
@@ -8,12 +8,13 @@ module ArticleHelper @@ -8,12 +8,13 @@ module ArticleHelper
8 'div', 8 'div',
9 check_box(:article, :published) + 9 check_box(:article, :published) +
10 content_tag('label', _('This article must be published (visible to other people)'), :for => 'article_published') 10 content_tag('label', _('This article must be published (visible to other people)'), :for => 'article_published')
11 - ) + 11 + ) + (article.parent && article.parent.forum? && controller.action_name == 'new' ?
  12 + hidden_field_tag('article[accept_comments]', 1) :
12 content_tag( 13 content_tag(
13 'div', 14 'div',
14 check_box(:article, :accept_comments) + 15 check_box(:article, :accept_comments) +
15 - content_tag('label', _('I want to receive comments about this article'), :for => 'article_accept_comments')  
16 - ) + 16 + content_tag('label', (article.parent && article.parent.forum? ? _('This topic is opened for replies') : _('I want to receive comments about this article')), :for => 'article_accept_comments')
  17 + )) +
17 content_tag( 18 content_tag(
18 'div', 19 'div',
19 check_box(:article, :notify_comments) + 20 check_box(:article, :notify_comments) +
test/functional/cms_controller_test.rb
@@ -1505,4 +1505,38 @@ class CmsControllerTest < Test::Unit::TestCase @@ -1505,4 +1505,38 @@ class CmsControllerTest < Test::Unit::TestCase
1505 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'article[display_posts_in_current_language]', :checked => 'checked' } 1505 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'article[display_posts_in_current_language]', :checked => 'checked' }
1506 end 1506 end
1507 1507
  1508 + should 'not display accept comments option when creating forum post' do
  1509 + profile.articles << f = Forum.new(:name => 'Forum for test')
  1510 + get :new, :profile => profile.identifier, :type => 'TinyMceArticle', :parent_id => f.id
  1511 + assert :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'hidden'}
  1512 + assert_no_tag :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'checkbox'}
  1513 + end
  1514 +
  1515 + should 'display accept comments option when creating an article that is not a forum post' do
  1516 + get :new, :profile => profile.identifier, :type => 'TinyMceArticle'
  1517 + assert_no_tag :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'hidden'}
  1518 + assert_tag :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'checkbox'}
  1519 + end
  1520 +
  1521 + should 'display accept comments option when editing forum post' do
  1522 + profile.articles << f = Forum.new(:name => 'Forum for test')
  1523 + profile.articles << a = TinyMceArticle.new(:name => 'Forum post for test', :parent => f)
  1524 + get :edit, :profile => profile.identifier, :id => a.id
  1525 + assert_no_tag :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'hidden'}
  1526 + assert_tag :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'checkbox'}
  1527 + end
  1528 +
  1529 + should 'display accept comments option when editing forum post with a different label' do
  1530 + profile.articles << f = Forum.new(:name => 'Forum for test')
  1531 + profile.articles << a = TinyMceArticle.new(:name => 'Forum post for test', :parent => f)
  1532 + get :edit, :profile => profile.identifier, :id => a.id
  1533 + assert_tag :tag => 'label', :attributes => { :for => 'article_accept_comments' }, :content => _('This topic is opened for replies')
  1534 + end
  1535 +
  1536 + should 'display correct label for accept comments option for an article that is not a forum post' do
  1537 + profile.articles << a = TinyMceArticle.new(:name => 'Forum post for test')
  1538 + get :edit, :profile => profile.identifier, :id => a.id
  1539 + assert_tag :tag => 'label', :attributes => { :for => 'article_accept_comments' }, :content => _('I want to receive comments about this article')
  1540 + end
  1541 +
1508 end 1542 end
test/unit/cms_helper_test.rb
@@ -7,12 +7,14 @@ class CmsHelperTest &lt; Test::Unit::TestCase @@ -7,12 +7,14 @@ class CmsHelperTest &lt; Test::Unit::TestCase
7 include ApplicationHelper 7 include ApplicationHelper
8 8
9 should 'show default options for article' do 9 should 'show default options for article' do
  10 + CmsHelperTest.any_instance.stubs(:controller).returns(ActionController::Base.new)
10 result = options_for_article(RssFeed.new) 11 result = options_for_article(RssFeed.new)
11 assert_match /id="article_published" name="article\[published\]" type="checkbox" value="1"/, result 12 assert_match /id="article_published" name="article\[published\]" type="checkbox" value="1"/, result
12 assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result 13 assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result
13 end 14 end
14 15
15 should 'show custom options for blog' do 16 should 'show custom options for blog' do
  17 + CmsHelperTest.any_instance.stubs(:controller).returns(ActionController::Base.new)
16 result = options_for_article(Blog.new) 18 result = options_for_article(Blog.new)
17 assert_match /id="article\[published\]" name="article\[published\]" type="hidden" value="1"/, result 19 assert_match /id="article\[published\]" name="article\[published\]" type="hidden" value="1"/, result
18 assert_match /id="article\[accept_comments\]" name="article\[accept_comments\]" type="hidden" value="0"/, result 20 assert_match /id="article\[accept_comments\]" name="article\[accept_comments\]" type="hidden" value="0"/, result