diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 72f22e4..b71f199 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -904,6 +904,7 @@ module ApplicationHelper def helper_for_article(article) article_helper = ActionView::Base.new + article_helper.controller = controller article_helper.extend ArticleHelper begin class_name = article.class.name + 'Helper' diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index 176e478..2da58d2 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -8,12 +8,13 @@ module ArticleHelper 'div', check_box(:article, :published) + content_tag('label', _('This article must be published (visible to other people)'), :for => 'article_published') - ) + + ) + (article.parent && article.parent.forum? && controller.action_name == 'new' ? + hidden_field_tag('article[accept_comments]', 1) : content_tag( 'div', check_box(:article, :accept_comments) + - content_tag('label', _('I want to receive comments about this article'), :for => 'article_accept_comments') - ) + + 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') + )) + content_tag( 'div', check_box(:article, :notify_comments) + diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 4f84267..71c5e41 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1505,4 +1505,38 @@ class CmsControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'article[display_posts_in_current_language]', :checked => 'checked' } end + should 'not display accept comments option when creating forum post' do + profile.articles << f = Forum.new(:name => 'Forum for test') + get :new, :profile => profile.identifier, :type => 'TinyMceArticle', :parent_id => f.id + assert :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'hidden'} + assert_no_tag :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'checkbox'} + end + + should 'display accept comments option when creating an article that is not a forum post' do + get :new, :profile => profile.identifier, :type => 'TinyMceArticle' + assert_no_tag :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'hidden'} + assert_tag :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'checkbox'} + end + + should 'display accept comments option when editing forum post' do + profile.articles << f = Forum.new(:name => 'Forum for test') + profile.articles << a = TinyMceArticle.new(:name => 'Forum post for test', :parent => f) + get :edit, :profile => profile.identifier, :id => a.id + assert_no_tag :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'hidden'} + assert_tag :tag => 'input', :attributes => {:name => 'article[accept_comments]', :value => 1, :type => 'checkbox'} + end + + should 'display accept comments option when editing forum post with a different label' do + profile.articles << f = Forum.new(:name => 'Forum for test') + profile.articles << a = TinyMceArticle.new(:name => 'Forum post for test', :parent => f) + get :edit, :profile => profile.identifier, :id => a.id + assert_tag :tag => 'label', :attributes => { :for => 'article_accept_comments' }, :content => _('This topic is opened for replies') + end + + should 'display correct label for accept comments option for an article that is not a forum post' do + profile.articles << a = TinyMceArticle.new(:name => 'Forum post for test') + get :edit, :profile => profile.identifier, :id => a.id + assert_tag :tag => 'label', :attributes => { :for => 'article_accept_comments' }, :content => _('I want to receive comments about this article') + end + end diff --git a/test/unit/cms_helper_test.rb b/test/unit/cms_helper_test.rb index d6d9191..118e77c 100644 --- a/test/unit/cms_helper_test.rb +++ b/test/unit/cms_helper_test.rb @@ -7,12 +7,14 @@ class CmsHelperTest < Test::Unit::TestCase include ApplicationHelper should 'show default options for article' do + CmsHelperTest.any_instance.stubs(:controller).returns(ActionController::Base.new) result = options_for_article(RssFeed.new) assert_match /id="article_published" name="article\[published\]" type="checkbox" value="1"/, result assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result end should 'show custom options for blog' do + CmsHelperTest.any_instance.stubs(:controller).returns(ActionController::Base.new) result = options_for_article(Blog.new) assert_match /id="article\[published\]" name="article\[published\]" type="hidden" value="1"/, result assert_match /id="article\[accept_comments\]" name="article\[accept_comments\]" type="hidden" value="0"/, result -- libgit2 0.21.2