Commit 80d971f1cf513a863099b3bd77d83c8d750748bf

Authored by GrazienoPellegrino
1 parent 1c7ee398

ActionItem147: Article could not accept comments

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2435 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/cms_controller.rb
... ... @@ -56,6 +56,7 @@ class CmsController < MyProfileController
56 56  
57 57 # user must choose an article type first
58 58 @type = params[:type]
  59 +
59 60 if @type.blank?
60 61 @article_types = []
61 62 available_article_types.each do |type|
... ...
app/controllers/my_profile/memberships_controller.rb
... ... @@ -17,6 +17,7 @@ class MembershipsController < MyProfileController
17 17  
18 18 def leave
19 19 @to_leave = Profile.find(params[:id])
  20 +
20 21 if request.post? && params[:confirmation]
21 22 @to_leave.remove_member(profile)
22 23 redirect_to :action => 'index'
... ...
app/controllers/public/content_viewer_controller.rb
... ... @@ -46,7 +46,7 @@ class ContentViewerController < PublicController
46 46 return
47 47 end
48 48  
49   - if request.post? && params[:comment] && params[self.icaptcha_field].blank?
  49 + if request.post? && params[:comment] && params[self.icaptcha_field].blank? && @page.accept_comments?
50 50 add_comment
51 51 end
52 52  
... ...
app/views/cms/edit.rhtml
... ... @@ -28,6 +28,8 @@
28 28 <div>
29 29 <%= check_box :article, :published %>
30 30 <label for='article_published'><%= _('Published')%></label>
  31 + <%= check_box :article, :accept_comments %>
  32 + <label for='article_accept_comments'><%= _('Accept Comments')%></label>
31 33 </div>
32 34 </div>
33 35  
... ...
app/views/content_viewer/view_page.rhtml
... ... @@ -68,8 +68,14 @@
68 68 </div>
69 69 <% end %>
70 70  
71   -<h3><%= @comments.size == 0 ? _('No comments yet') : (n_('One comment', '%{comments} comments', @comments.size)) % { :comments => @comments.size} %></h3>
72   -<%= render :partial => 'comment', :collection => @comments %>
73   -<%= render :partial => 'comment_form' %>
  71 + <h3>
  72 + <%= @comments.size == 0 ? _('No comments yet') : (n_('One comment', '%{comments} comments', @comments.size)) % { :comments => @comments.size} %>
  73 + </h3>
  74 + <%= render :partial => 'comment', :collection => @comments %>
  75 +<% if !@page.accept_comments? %>
  76 + <h3><%= _('This article does not accept comments')%></h3>
  77 +<% else %>
  78 + <%= render :partial => 'comment_form' %>
  79 +<% end %>
74 80  
75 81 </div><!-- end id="article" -->
... ...
app/views/search/_search_form.rhtml
1 1 <div class='search-form'>
2   -
3 2 <% simple_search = false unless defined? simple_search %>
4 3  
5 4 <% form_tag( { :action => 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) },
... ...
db/migrate/053_add_accept_comments_to_articles.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class AddAcceptCommentsToArticles < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :articles, :accept_comments, :boolean, :default => true
  4 + add_column :article_versions, :accept_comments, :boolean, :default => true
  5 + end
  6 +
  7 + def self.down
  8 + remove_column :articles, :accept_comments
  9 + remove_column :article_versions, :accept_comments
  10 + end
  11 +end
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -89,7 +89,7 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
89 89 page = profile.articles.build(:name => 'myarticle', :body => 'the body of the text')
90 90 page.save!
91 91 profile.home_page = page; profile.save!
92   -
  92 +
93 93 assert_difference Comment, :count do
94 94 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' }
95 95 end
... ... @@ -396,5 +396,12 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
396 396 assert_template 'view_page'
397 397 end
398 398  
  399 + should 'not be able to post comment if article do not accept it' do
  400 + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text', :accept_comments => false)
  401 +
  402 + assert_no_difference Comment, :count do
  403 + 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' }
  404 + end
  405 + end
399 406  
400 407 end
... ...
test/functional/my_profile_controller_test.rb
... ... @@ -45,4 +45,15 @@ class MyProfileControllerTest &lt; Test::Unit::TestCase
45 45 get :index, :profile => 'hacking_institute'
46 46 assert_response 403 # forbidden
47 47 end
  48 +
  49 + def test_accept_comments
  50 + article=profile.articles.create!(:name=>'my article',:body =>'my text',:accept_comments=>true)
  51 + assert article.comments.create(:author=>profile,:title=>'A new comment', :body =>'Go go go!')
  52 + end
  53 +
  54 + def test_not_accept_comments
  55 + article=profile.articles.create!(:name=>'my article',:body =>'my text',:accept_comments=>true)
  56 + assert article.comments.create(:author=>profile,:title=>'A new comment', :body =>'Go go go!')
  57 + end
  58 +
48 59 end
... ...