Commit 5e9787c812ab81070a702a97afdbc9b762ee502b

Authored by Rodrigo Souto
2 parents 8e9c9d70 ee97d763

Merge commit 'refs/merge-requests/291' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/291
app/controllers/my_profile/cms_controller.rb
... ... @@ -182,7 +182,14 @@ class CmsController < MyProfileController
182 182 if request.post?
183 183 @article.destroy
184 184 session[:notice] = _("\"#{@article.name}\" was removed.")
185   - redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent
  185 + referer = ActionController::Routing::Routes.recognize_path URI.parse(request.referer).path rescue nil
  186 + if referer and referer[:controller] == 'cms'
  187 + redirect_to referer
  188 + elsif @article.parent
  189 + redirect_to @article.parent.url
  190 + else
  191 + redirect_to profile.url
  192 + end
186 193 end
187 194 end
188 195  
... ...
test/functional/cms_controller_test.rb
... ... @@ -6,6 +6,8 @@ class CmsController; def rescue_action(e) raise e end; end
6 6  
7 7 class CmsControllerTest < ActionController::TestCase
8 8  
  9 + include NoosferoTestHelper
  10 +
9 11 fixtures :environments
10 12  
11 13 def setup
... ... @@ -199,13 +201,29 @@ class CmsControllerTest &lt; ActionController::TestCase
199 201 should 'be able to remove article' do
200 202 a = profile.articles.build(:name => 'my-article')
201 203 a.save!
202   -
203 204 assert_difference Article, :count, -1 do
  205 + @request.env['HTTP_REFERER'] = url_for :controller => 'cms', :profile => profile.identifier, :action => 'index'
204 206 post :destroy, :profile => profile.identifier, :id => a.id
205 207 assert_redirected_to :controller => 'cms', :profile => profile.identifier, :action => 'index'
206 208 end
207 209 end
208 210  
  211 + should 'redirect to cms after remove article from content management' do
  212 + a = profile.articles.build(:name => 'my-article')
  213 + a.save!
  214 + @request.env['HTTP_REFERER'] = url_for :controller => 'cms', :profile => profile.identifier, :action => 'index'
  215 + post :destroy, :profile => profile.identifier, :id => a.id
  216 + assert_redirected_to :controller => 'cms', :profile => profile.identifier, :action => 'index'
  217 + end
  218 +
  219 + should 'redirect to blog after remove article from content viewer' do
  220 + a = profile.articles.build(:name => 'my-article')
  221 + a.save!
  222 + @request.env['HTTP_REFERER'] = url_for :controller => 'content_viewer', :action => 'view_page'
  223 + post :destroy, :profile => profile.identifier, :id => a.id
  224 + assert_redirected_to :controller => 'content_viewer', :action => 'view_page'
  225 + end
  226 +
209 227 should 'be able to acess Rss feed creation page' do
210 228 login_as(profile.identifier)
211 229 assert_nothing_raised do
... ... @@ -887,6 +905,7 @@ class CmsControllerTest &lt; ActionController::TestCase
887 905  
888 906 should 'offer confirmation to remove article' do
889 907 a = profile.articles.create!(:name => 'my-article')
  908 + @request.env['HTTP_REFERER'] = url_for :controller => 'cms', :profile => profile.identifier, :action => 'index'
890 909 post :destroy, :profile => profile.identifier, :id => a.id
891 910 assert_response :redirect
892 911 end
... ...
test/test_helper.rb
... ... @@ -256,9 +256,11 @@ module NoosferoTestHelper
256 256 def will_paginate(arg1, arg2)
257 257 end
258 258  
259   - def url_for(args = {})
260   - args
  259 + def url_for *args
  260 + url = ActionController::UrlRewriter.new(@request, nil)
  261 + url.rewrite *args
261 262 end
  263 +
262 264 def javascript_tag(any)
263 265 ''
264 266 end
... ...