Commit 5e9787c812ab81070a702a97afdbc9b762ee502b
Exists in
master
and in
22 other branches
Merge commit 'refs/merge-requests/291' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/291
Showing
3 changed files
with
32 additions
and
4 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
| @@ -182,7 +182,14 @@ class CmsController < MyProfileController | @@ -182,7 +182,14 @@ 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 | - 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 | end | 193 | end |
| 187 | end | 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 +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 |
| @@ -887,6 +905,7 @@ class CmsControllerTest < ActionController::TestCase | @@ -887,6 +905,7 @@ class CmsControllerTest < ActionController::TestCase | ||
| 887 | 905 | ||
| 888 | should 'offer confirmation to remove article' do | 906 | should 'offer confirmation to remove article' do |
| 889 | a = profile.articles.create!(:name => 'my-article') | 907 | a = profile.articles.create!(:name => 'my-article') |
| 908 | + @request.env['HTTP_REFERER'] = url_for :controller => 'cms', :profile => profile.identifier, :action => 'index' | ||
| 890 | post :destroy, :profile => profile.identifier, :id => a.id | 909 | post :destroy, :profile => profile.identifier, :id => a.id |
| 891 | assert_response :redirect | 910 | assert_response :redirect |
| 892 | end | 911 | end |
test/test_helper.rb
| @@ -256,9 +256,11 @@ module NoosferoTestHelper | @@ -256,9 +256,11 @@ module NoosferoTestHelper | ||
| 256 | def will_paginate(arg1, arg2) | 256 | def will_paginate(arg1, arg2) |
| 257 | end | 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 | end | 262 | end |
| 263 | + | ||
| 262 | def javascript_tag(any) | 264 | def javascript_tag(any) |
| 263 | '' | 265 | '' |
| 264 | end | 266 | end |