Commit e9c6a9665e330dc9088bea048168d95b87568a43

Authored by MoisesMachado
1 parent 09d0a1d6

ActionItem519: fixing URL's generated for remove comment

They broke when I added the domain routing stuff

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2420 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/content_viewer_controller.rb
... ... @@ -76,7 +76,7 @@ class ContentViewerController < PublicController
76 76 @comment.destroy
77 77 flash[:notice] = _('Comment succesfully deleted')
78 78 end
79   - redirect_to :action => 'view_page'
  79 + redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path
80 80 end
81 81  
82 82 end
... ...
app/views/content_viewer/_comment.rhtml
... ... @@ -2,7 +2,7 @@
2 2 <div class="article-comment<%= ' comment-from-owner' if ( comment.author && (@page.profile.name == comment.author.name) ) %> comment-logged-<%= comment.author ? 'in' : 'out' %>">
3 3 <% if logged_in? && (user == @page.profile || user == comment.author || user.has_permission?(:moderate_comments, @page.profile)) %>
4 4 <% button_bar(:style => 'float: right; margin-top: 0;') do %>
5   - <%= icon_button(:delete, _('Remove'), { :remove_comment => comment.id }, :method => :post, :confirm => _('Are you sure you want to remove this comment?')) %>
  5 + <%= icon_button(:delete, _('Remove'), { :profile => params[:profile], :remove_comment => comment.id }, :method => :post, :confirm => _('Are you sure you want to remove this comment?')) %>
6 6 <% end %>
7 7 <% end %>
8 8  
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -114,6 +114,30 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
114 114 assert_equal feed.data, @response.body
115 115 end
116 116  
  117 + should 'display remove comment button' do
  118 + profile = create_user('testuser').person
  119 + article = profile.articles.build(:name => 'test')
  120 + article.save!
  121 + comment = article.comments.build(:author => profile, :title => 'a comment', :body => 'lalala')
  122 + comment.save!
  123 +
  124 + login_as 'testuser'
  125 + get :view_page, :profile => 'testuser', :page => [ 'test' ]
  126 + assert_tag :tag => 'a', :attributes => { :href => '/testuser/test?remove_comment=' + comment.id.to_s }
  127 + end
  128 +
  129 + should 'not add unneeded params for remove comment button' do
  130 + profile = create_user('testuser').person
  131 + article = profile.articles.build(:name => 'test')
  132 + article.save!
  133 + comment = article.comments.build(:author => profile, :title => 'a comment', :body => 'lalala')
  134 + comment.save!
  135 +
  136 + login_as 'testuser'
  137 + get :view_page, :profile => 'testuser', :page => [ 'test' ], :random_param => 'bli' # <<<<<<<<<<<<<<<
  138 + assert_tag :tag => 'a', :attributes => { :href => '/testuser/test?remove_comment=' + comment.id.to_s }
  139 + end
  140 +
117 141 should 'be able to remove comment' do
118 142 profile = create_user('testuser').person
119 143 article = profile.articles.build(:name => 'test')
... ... @@ -124,7 +148,7 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
124 148 login_as 'testuser'
125 149 assert_difference Comment, :count, -1 do
126 150 post :view_page, :profile => profile.identifier, :page => [ 'test' ], :remove_comment => comment.id
127   - assert_response :redirect
  151 + assert_redirected_to :profile => 'testuser', :action => 'view_page', :page => [ 'test' ]
128 152 end
129 153 end
130 154  
... ...