Commit ee97d76388ef8ddacdfb522b07f296c310ce209c

Authored by Caio Formiga
1 parent 2aeb1041

Test for destroy article with referer

app/controllers/my_profile/cms_controller.rb
... ... @@ -182,7 +182,7 @@ class CmsController < MyProfileController
182 182 if request.post?
183 183 @article.destroy
184 184 session[:notice] = _("\"#{@article.name}\" was removed.")
185   - referer = ActionController::Routing::Routes.recognize_path URI.parse(request.referer).path
  185 + referer = ActionController::Routing::Routes.recognize_path URI.parse(request.referer).path rescue nil
186 186 if referer and referer[:controller] == 'cms'
187 187 redirect_to referer
188 188 elsif @article.parent
... ...
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
... ... @@ -888,6 +906,7 @@ class CmsControllerTest &lt; ActionController::TestCase
888 906  
889 907 should 'offer confirmation to remove article' do
890 908 a = profile.articles.create!(:name => 'my-article')
  909 + @request.env['HTTP_REFERER'] = url_for :controller => 'cms', :profile => profile.identifier, :action => 'index'
891 910 post :destroy, :profile => profile.identifier, :id => a.id
892 911 assert_response :redirect
893 912 end
... ...
test/test_helper.rb
... ... @@ -272,9 +272,11 @@ module NoosferoTestHelper
272 272 def will_paginate(arg1, arg2)
273 273 end
274 274  
275   - def url_for(args = {})
276   - args
  275 + def url_for *args
  276 + url = ActionController::UrlRewriter.new(@request, nil)
  277 + url.rewrite *args
277 278 end
  279 +
278 280 def javascript_tag(any)
279 281 ''
280 282 end
... ...