Commit 8c0aebb619aa989fc681cd5c51e809f4761cf119
Committed by
Antonio Terceiro
1 parent
fda93ec0
Exists in
master
and in
28 other branches
ActionItem1061: allowing removal of comments when article is an image
Showing
3 changed files
with
35 additions
and
2 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
| @@ -110,7 +110,7 @@ class ContentViewerController < ApplicationController | @@ -110,7 +110,7 @@ class ContentViewerController < ApplicationController | ||
| 110 | @comment.destroy | 110 | @comment.destroy |
| 111 | flash[:notice] = _('Comment succesfully deleted') | 111 | flash[:notice] = _('Comment succesfully deleted') |
| 112 | end | 112 | end |
| 113 | - redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path | 113 | + redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] |
| 114 | end | 114 | end |
| 115 | 115 | ||
| 116 | end | 116 | end |
app/views/content_viewer/_comment.rhtml
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | 3 | ||
| 4 | <% if logged_in? && (user == @page.profile || user == comment.author || user.has_permission?(:moderate_comments, @page.profile)) %> | 4 | <% if logged_in? && (user == @page.profile || user == comment.author || user.has_permission?(:moderate_comments, @page.profile)) %> |
| 5 | <% button_bar(:style => 'float: right; margin-top: 0px;') do %> | 5 | <% button_bar(:style => 'float: right; margin-top: 0px;') do %> |
| 6 | - <%= icon_button(:delete, _('Remove this comment'), { :profile => params[:profile], :remove_comment => comment.id }, :method => :post, :confirm => _('Are you sure you want to remove this comment?')) %> | 6 | + <%= icon_button(:delete, _('Remove this comment'), { :profile => params[:profile], :remove_comment => comment.id, :view => params[:view] }, :method => :post, :confirm => _('Are you sure you want to remove this comment?')) %> |
| 7 | <% end %> | 7 | <% end %> |
| 8 | <% end %> | 8 | <% end %> |
| 9 | 9 |
test/functional/content_viewer_controller_test.rb
| @@ -118,6 +118,20 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -118,6 +118,20 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 118 | assert_tag :tag => 'a', :attributes => { :href => '/testuser/test?remove_comment=' + comment.id.to_s } | 118 | assert_tag :tag => 'a', :attributes => { :href => '/testuser/test?remove_comment=' + comment.id.to_s } |
| 119 | end | 119 | end |
| 120 | 120 | ||
| 121 | + should 'display remove comment button with param view when image' do | ||
| 122 | + profile = create_user('testuser').person | ||
| 123 | + | ||
| 124 | + image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
| 125 | + image.save! | ||
| 126 | + | ||
| 127 | + comment = image.comments.build(:author => profile, :title => 'a comment', :body => 'lalala') | ||
| 128 | + comment.save! | ||
| 129 | + | ||
| 130 | + login_as 'testuser' | ||
| 131 | + get :view_page, :profile => 'testuser', :page => [ image.filename ], :view => true | ||
| 132 | + assert_tag :tag => 'a', :attributes => { :href => "/testuser/#{image.filename}?remove_comment=" + comment.id.to_s + '&view=true'} | ||
| 133 | + end | ||
| 134 | + | ||
| 121 | should 'not add unneeded params for remove comment button' do | 135 | should 'not add unneeded params for remove comment button' do |
| 122 | profile = create_user('testuser').person | 136 | profile = create_user('testuser').person |
| 123 | article = profile.articles.build(:name => 'test') | 137 | article = profile.articles.build(:name => 'test') |
| @@ -177,6 +191,25 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -177,6 +191,25 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 177 | end | 191 | end |
| 178 | end | 192 | end |
| 179 | 193 | ||
| 194 | + should 'be able to remove comments of their images' do | ||
| 195 | + profile = create_user('testuser').person | ||
| 196 | + | ||
| 197 | + image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) | ||
| 198 | + image.save! | ||
| 199 | + | ||
| 200 | + commenter = create_user('otheruser').person | ||
| 201 | + comment = image.comments.build(:author => commenter, :title => 'a comment', :body => 'lalala') | ||
| 202 | + comment.save! | ||
| 203 | + | ||
| 204 | + login_as 'testuser' # testuser must be able to remove comments in his articles | ||
| 205 | + assert_difference Comment, :count, -1 do | ||
| 206 | + post :view_page, :profile => profile.identifier, :page => [ image.filename ], :remove_comment => comment.id, :view => true | ||
| 207 | + | ||
| 208 | + assert_response :redirect | ||
| 209 | + assert_redirected_to :profile => profile.identifier, :page => image.explode_path, :view => true | ||
| 210 | + end | ||
| 211 | + end | ||
| 212 | + | ||
| 180 | should 'not be able to post comment while inverse captcha field filled' do | 213 | should 'not be able to post comment while inverse captcha field filled' do |
| 181 | profile = create_user('popstar').person | 214 | profile = create_user('popstar').person |
| 182 | page = profile.articles.build(:name => 'myarticle', :body => 'the body of the text') | 215 | page = profile.articles.build(:name => 'myarticle', :body => 'the body of the text') |