Commit 8c19102049a874cf490b7e69b9a03b72e1403026
1 parent
265f85f7
Exists in
master
and in
29 other branches
ActionItem438: keeping all arguments when redirecting, adapting tests
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2475 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
21 additions
and
3 deletions
Show diff stats
app/controllers/application.rb
@@ -35,7 +35,7 @@ class ApplicationController < ActionController::Base | @@ -35,7 +35,7 @@ class ApplicationController < ActionController::Base | ||
35 | end | 35 | end |
36 | def check_ssl | 36 | def check_ssl |
37 | return true if (request.ssl? || ENV['RAILS_ENV'] == 'development') | 37 | return true if (request.ssl? || ENV['RAILS_ENV'] == 'development') |
38 | - redirect_to :protocol => 'https://' | 38 | + redirect_to(params.merge(:protocol => 'https://')) |
39 | end | 39 | end |
40 | 40 | ||
41 | def self.refuse_ssl(*options) | 41 | def self.refuse_ssl(*options) |
@@ -43,7 +43,7 @@ class ApplicationController < ActionController::Base | @@ -43,7 +43,7 @@ class ApplicationController < ActionController::Base | ||
43 | end | 43 | end |
44 | def avoid_ssl | 44 | def avoid_ssl |
45 | return true if (!request.ssl? || ENV['RAILS_ENV'] == 'development') | 45 | return true if (!request.ssl? || ENV['RAILS_ENV'] == 'development') |
46 | - redirect_to :protocol => 'http://' | 46 | + redirect_to(params.merge(:protocol => 'http://')) |
47 | end | 47 | end |
48 | 48 | ||
49 | before_init_gettext :maybe_save_locale | 49 | before_init_gettext :maybe_save_locale |
app/controllers/my_profile/cms_controller.rb
@@ -8,7 +8,6 @@ class CmsController < MyProfileController | @@ -8,7 +8,6 @@ class CmsController < MyProfileController | ||
8 | # publication" button on article's public view. | 8 | # publication" button on article's public view. |
9 | def check_ssl | 9 | def check_ssl |
10 | if ((params[:action] == 'new') && (!request.xhr?)) || (params[:action] != 'new') | 10 | if ((params[:action] == 'new') && (!request.xhr?)) || (params[:action] != 'new') |
11 | - #raise 'bli' | ||
12 | check_ssl_orig | 11 | check_ssl_orig |
13 | end | 12 | end |
14 | end | 13 | end |
test/functional/application_controller_test.rb
@@ -249,6 +249,12 @@ class ApplicationControllerTest < Test::Unit::TestCase | @@ -249,6 +249,12 @@ class ApplicationControllerTest < Test::Unit::TestCase | ||
249 | assert_response :success | 249 | assert_response :success |
250 | end | 250 | end |
251 | 251 | ||
252 | + should 'keep arguments when redirecting to ssl' do | ||
253 | + @request.expects(:ssl?).returns(false).at_least_once | ||
254 | + get :sslonly, :x => '1', :y => '2' | ||
255 | + assert_redirected_to :protocol => 'https://', :x => '1', :y => '2' | ||
256 | + end | ||
257 | + | ||
252 | should 'refuse ssl when told to' do | 258 | should 'refuse ssl when told to' do |
253 | @request.expects(:ssl?).returns(true).at_least_once | 259 | @request.expects(:ssl?).returns(true).at_least_once |
254 | get :nossl | 260 | get :nossl |
@@ -272,4 +278,10 @@ class ApplicationControllerTest < Test::Unit::TestCase | @@ -272,4 +278,10 @@ class ApplicationControllerTest < Test::Unit::TestCase | ||
272 | assert_response :success | 278 | assert_response :success |
273 | end | 279 | end |
274 | 280 | ||
281 | + should 'keep arguments when redirecting to non-ssl' do | ||
282 | + @request.expects(:ssl?).returns(true).at_least_once | ||
283 | + get :nossl, :x => '1', :y => '2' | ||
284 | + assert_redirected_to :protocol => 'http://', :x => '1', :y => '2' | ||
285 | + end | ||
286 | + | ||
275 | end | 287 | end |
test/functional/cms_controller_test.rb
@@ -604,6 +604,12 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -604,6 +604,12 @@ class CmsControllerTest < Test::Unit::TestCase | ||
604 | assert_response :success | 604 | assert_response :success |
605 | end | 605 | end |
606 | 606 | ||
607 | + should 'not loose type argument in new action when redirecting to ssl' do | ||
608 | + @request.expects(:ssl?).returns(false).at_least_once | ||
609 | + get :new, :profile => 'testinguser', :type => 'Folder' | ||
610 | + assert_redirected_to :protocol => 'https://', :action => 'new', :type => 'Folder' | ||
611 | + end | ||
612 | + | ||
607 | should 'not accept non-ajax connections to new action without ssl' do | 613 | should 'not accept non-ajax connections to new action without ssl' do |
608 | @request.expects(:ssl?).returns(false).at_least_once | 614 | @request.expects(:ssl?).returns(false).at_least_once |
609 | get :new, :profile => 'testinguser' | 615 | get :new, :profile => 'testinguser' |
test/functional/edit_template_controller_test.rb
@@ -11,6 +11,7 @@ class EditTemplateControllerTest < Test::Unit::TestCase | @@ -11,6 +11,7 @@ class EditTemplateControllerTest < Test::Unit::TestCase | ||
11 | def setup | 11 | def setup |
12 | @controller = EditTemplateController.new | 12 | @controller = EditTemplateController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
14 | + @request.stubs(:ssl?).returns(true) | ||
14 | @response = ActionController::TestResponse.new | 15 | @response = ActionController::TestResponse.new |
15 | login_as 'ze' | 16 | login_as 'ze' |
16 | end | 17 | end |