Commit ee97d76388ef8ddacdfb522b07f296c310ce209c
1 parent
2aeb1041
Exists in
master
and in
29 other branches
Test for destroy article with referer
Showing
3 changed files
with
25 additions
and
4 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -182,7 +182,7 @@ class CmsController < MyProfileController | @@ -182,7 +182,7 @@ class CmsController < MyProfileController | ||
182 | if request.post? | 182 | if request.post? |
183 | @article.destroy | 183 | @article.destroy |
184 | session[:notice] = _("\"#{@article.name}\" was removed.") | 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 | if referer and referer[:controller] == 'cms' | 186 | if referer and referer[:controller] == 'cms' |
187 | redirect_to referer | 187 | redirect_to referer |
188 | elsif @article.parent | 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 +6,8 @@ class CmsController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class CmsControllerTest < ActionController::TestCase | 7 | class CmsControllerTest < ActionController::TestCase |
8 | 8 | ||
9 | + include NoosferoTestHelper | ||
10 | + | ||
9 | fixtures :environments | 11 | fixtures :environments |
10 | 12 | ||
11 | def setup | 13 | def setup |
@@ -199,13 +201,29 @@ class CmsControllerTest < ActionController::TestCase | @@ -199,13 +201,29 @@ class CmsControllerTest < ActionController::TestCase | ||
199 | should 'be able to remove article' do | 201 | should 'be able to remove article' do |
200 | a = profile.articles.build(:name => 'my-article') | 202 | a = profile.articles.build(:name => 'my-article') |
201 | a.save! | 203 | a.save! |
202 | - | ||
203 | assert_difference Article, :count, -1 do | 204 | assert_difference Article, :count, -1 do |
205 | + @request.env['HTTP_REFERER'] = url_for :controller => 'cms', :profile => profile.identifier, :action => 'index' | ||
204 | post :destroy, :profile => profile.identifier, :id => a.id | 206 | post :destroy, :profile => profile.identifier, :id => a.id |
205 | assert_redirected_to :controller => 'cms', :profile => profile.identifier, :action => 'index' | 207 | assert_redirected_to :controller => 'cms', :profile => profile.identifier, :action => 'index' |
206 | end | 208 | end |
207 | end | 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 | should 'be able to acess Rss feed creation page' do | 227 | should 'be able to acess Rss feed creation page' do |
210 | login_as(profile.identifier) | 228 | login_as(profile.identifier) |
211 | assert_nothing_raised do | 229 | assert_nothing_raised do |
@@ -888,6 +906,7 @@ class CmsControllerTest < ActionController::TestCase | @@ -888,6 +906,7 @@ class CmsControllerTest < ActionController::TestCase | ||
888 | 906 | ||
889 | should 'offer confirmation to remove article' do | 907 | should 'offer confirmation to remove article' do |
890 | a = profile.articles.create!(:name => 'my-article') | 908 | a = profile.articles.create!(:name => 'my-article') |
909 | + @request.env['HTTP_REFERER'] = url_for :controller => 'cms', :profile => profile.identifier, :action => 'index' | ||
891 | post :destroy, :profile => profile.identifier, :id => a.id | 910 | post :destroy, :profile => profile.identifier, :id => a.id |
892 | assert_response :redirect | 911 | assert_response :redirect |
893 | end | 912 | end |
test/test_helper.rb
@@ -272,9 +272,11 @@ module NoosferoTestHelper | @@ -272,9 +272,11 @@ module NoosferoTestHelper | ||
272 | def will_paginate(arg1, arg2) | 272 | def will_paginate(arg1, arg2) |
273 | end | 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 | end | 278 | end |
279 | + | ||
278 | def javascript_tag(any) | 280 | def javascript_tag(any) |
279 | '' | 281 | '' |
280 | end | 282 | end |