Commit 80d971f1cf513a863099b3bd77d83c8d750748bf
1 parent
1c7ee398
Exists in
master
and in
29 other branches
ActionItem147: Article could not accept comments
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2435 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
9 changed files
with
44 additions
and
6 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
app/controllers/my_profile/memberships_controller.rb
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
... | ... | @@ -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 < 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 < 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 < 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 | ... | ... |