From 80d971f1cf513a863099b3bd77d83c8d750748bf Mon Sep 17 00:00:00 2001 From: GrazienoPellegrino Date: Sat, 30 Aug 2008 14:33:37 +0000 Subject: [PATCH] ActionItem147: Article could not accept comments --- app/controllers/my_profile/cms_controller.rb | 1 + app/controllers/my_profile/memberships_controller.rb | 1 + app/controllers/public/content_viewer_controller.rb | 2 +- app/views/cms/edit.rhtml | 2 ++ app/views/content_viewer/view_page.rhtml | 12 +++++++++--- app/views/search/_search_form.rhtml | 1 - db/migrate/053_add_accept_comments_to_articles.rb | 11 +++++++++++ test/functional/content_viewer_controller_test.rb | 9 ++++++++- test/functional/my_profile_controller_test.rb | 11 +++++++++++ 9 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 db/migrate/053_add_accept_comments_to_articles.rb diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 6c22a0b..c94ebad 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -56,6 +56,7 @@ class CmsController < MyProfileController # user must choose an article type first @type = params[:type] + if @type.blank? @article_types = [] available_article_types.each do |type| diff --git a/app/controllers/my_profile/memberships_controller.rb b/app/controllers/my_profile/memberships_controller.rb index bd08e66..74daf44 100644 --- a/app/controllers/my_profile/memberships_controller.rb +++ b/app/controllers/my_profile/memberships_controller.rb @@ -17,6 +17,7 @@ class MembershipsController < MyProfileController def leave @to_leave = Profile.find(params[:id]) + if request.post? && params[:confirmation] @to_leave.remove_member(profile) redirect_to :action => 'index' diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index c57e326..d2f7645 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -46,7 +46,7 @@ class ContentViewerController < PublicController return end - if request.post? && params[:comment] && params[self.icaptcha_field].blank? + if request.post? && params[:comment] && params[self.icaptcha_field].blank? && @page.accept_comments? add_comment end diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml index ba0aa72..205f30d 100644 --- a/app/views/cms/edit.rhtml +++ b/app/views/cms/edit.rhtml @@ -28,6 +28,8 @@
<%= check_box :article, :published %> + <%= check_box :article, :accept_comments %> +
diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index fee9cd5..e5f7fcd 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -68,8 +68,14 @@ <% end %> -

<%= @comments.size == 0 ? _('No comments yet') : (n_('One comment', '%{comments} comments', @comments.size)) % { :comments => @comments.size} %>

-<%= render :partial => 'comment', :collection => @comments %> -<%= render :partial => 'comment_form' %> +

+ <%= @comments.size == 0 ? _('No comments yet') : (n_('One comment', '%{comments} comments', @comments.size)) % { :comments => @comments.size} %> +

+ <%= render :partial => 'comment', :collection => @comments %> +<% if !@page.accept_comments? %> +

<%= _('This article does not accept comments')%>

+<% else %> + <%= render :partial => 'comment_form' %> +<% end %> diff --git a/app/views/search/_search_form.rhtml b/app/views/search/_search_form.rhtml index 59843f7..6b57b94 100644 --- a/app/views/search/_search_form.rhtml +++ b/app/views/search/_search_form.rhtml @@ -1,5 +1,4 @@
- <% simple_search = false unless defined? simple_search %> <% form_tag( { :action => 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, diff --git a/db/migrate/053_add_accept_comments_to_articles.rb b/db/migrate/053_add_accept_comments_to_articles.rb new file mode 100644 index 0000000..dce463e --- /dev/null +++ b/db/migrate/053_add_accept_comments_to_articles.rb @@ -0,0 +1,11 @@ +class AddAcceptCommentsToArticles < ActiveRecord::Migration + def self.up + add_column :articles, :accept_comments, :boolean, :default => true + add_column :article_versions, :accept_comments, :boolean, :default => true + end + + def self.down + remove_column :articles, :accept_comments + remove_column :article_versions, :accept_comments + end +end diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 5ecd448..defa90a 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -89,7 +89,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase page = profile.articles.build(:name => 'myarticle', :body => 'the body of the text') page.save! profile.home_page = page; profile.save! - + assert_difference Comment, :count do post :view_page, :profile => 'popstar', :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap', :name => 'Anonymous coward', :email => 'coward@anonymous.com' } end @@ -396,5 +396,12 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_template 'view_page' end + should 'not be able to post comment if article do not accept it' do + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text', :accept_comments => false) + + assert_no_difference Comment, :count do + post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap', :name => 'Anonymous coward', :email => 'coward@anonymous.com' } + end + end end diff --git a/test/functional/my_profile_controller_test.rb b/test/functional/my_profile_controller_test.rb index 69f53e5..6d0c6ba 100644 --- a/test/functional/my_profile_controller_test.rb +++ b/test/functional/my_profile_controller_test.rb @@ -45,4 +45,15 @@ class MyProfileControllerTest < Test::Unit::TestCase get :index, :profile => 'hacking_institute' assert_response 403 # forbidden end + + def test_accept_comments + article=profile.articles.create!(:name=>'my article',:body =>'my text',:accept_comments=>true) + assert article.comments.create(:author=>profile,:title=>'A new comment', :body =>'Go go go!') + end + + def test_not_accept_comments + article=profile.articles.create!(:name=>'my article',:body =>'my text',:accept_comments=>true) + assert article.comments.create(:author=>profile,:title=>'A new comment', :body =>'Go go go!') + end + end -- libgit2 0.21.2