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 904  
905 905 def helper_for_article(article)
906 906 article_helper = ActionView::Base.new
  907 + article_helper.controller = controller
907 908 article_helper.extend ArticleHelper
908 909 begin
909 910 class_name = article.class.name + 'Helper'
... ...
app/helpers/article_helper.rb
... ... @@ -8,12 +8,13 @@ module ArticleHelper
8 8 'div',
9 9 check_box(:article, :published) +
10 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 13 content_tag(
13 14 'div',
14 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 18 content_tag(
18 19 'div',
19 20 check_box(:article, :notify_comments) +
... ...
test/functional/cms_controller_test.rb
... ... @@ -1505,4 +1505,38 @@ class CmsControllerTest < Test::Unit::TestCase
1505 1505 assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'article[display_posts_in_current_language]', :checked => 'checked' }
1506 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 1542 end
... ...
test/unit/cms_helper_test.rb
... ... @@ -7,12 +7,14 @@ class CmsHelperTest &lt; Test::Unit::TestCase
7 7 include ApplicationHelper
8 8  
9 9 should 'show default options for article' do
  10 + CmsHelperTest.any_instance.stubs(:controller).returns(ActionController::Base.new)
10 11 result = options_for_article(RssFeed.new)
11 12 assert_match /id="article_published" name="article\[published\]" type="checkbox" value="1"/, result
12 13 assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result
13 14 end
14 15  
15 16 should 'show custom options for blog' do
  17 + CmsHelperTest.any_instance.stubs(:controller).returns(ActionController::Base.new)
16 18 result = options_for_article(Blog.new)
17 19 assert_match /id="article\[published\]" name="article\[published\]" type="hidden" value="1"/, result
18 20 assert_match /id="article\[accept_comments\]" name="article\[accept_comments\]" type="hidden" value="0"/, result
... ...