Commit 8c19102049a874cf490b7e69b9a03b72e1403026

Authored by AntonioTerceiro
1 parent 265f85f7

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
app/controllers/application.rb
... ... @@ -35,7 +35,7 @@ class ApplicationController < ActionController::Base
35 35 end
36 36 def check_ssl
37 37 return true if (request.ssl? || ENV['RAILS_ENV'] == 'development')
38   - redirect_to :protocol => 'https://'
  38 + redirect_to(params.merge(:protocol => 'https://'))
39 39 end
40 40  
41 41 def self.refuse_ssl(*options)
... ... @@ -43,7 +43,7 @@ class ApplicationController < ActionController::Base
43 43 end
44 44 def avoid_ssl
45 45 return true if (!request.ssl? || ENV['RAILS_ENV'] == 'development')
46   - redirect_to :protocol => 'http://'
  46 + redirect_to(params.merge(:protocol => 'http://'))
47 47 end
48 48  
49 49 before_init_gettext :maybe_save_locale
... ...
app/controllers/my_profile/cms_controller.rb
... ... @@ -8,7 +8,6 @@ class CmsController < MyProfileController
8 8 # publication" button on article's public view.
9 9 def check_ssl
10 10 if ((params[:action] == 'new') && (!request.xhr?)) || (params[:action] != 'new')
11   - #raise 'bli'
12 11 check_ssl_orig
13 12 end
14 13 end
... ...
test/functional/application_controller_test.rb
... ... @@ -249,6 +249,12 @@ class ApplicationControllerTest < Test::Unit::TestCase
249 249 assert_response :success
250 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 258 should 'refuse ssl when told to' do
253 259 @request.expects(:ssl?).returns(true).at_least_once
254 260 get :nossl
... ... @@ -272,4 +278,10 @@ class ApplicationControllerTest < Test::Unit::TestCase
272 278 assert_response :success
273 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 287 end
... ...
test/functional/cms_controller_test.rb
... ... @@ -604,6 +604,12 @@ class CmsControllerTest < Test::Unit::TestCase
604 604 assert_response :success
605 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 613 should 'not accept non-ajax connections to new action without ssl' do
608 614 @request.expects(:ssl?).returns(false).at_least_once
609 615 get :new, :profile => 'testinguser'
... ...
test/functional/edit_template_controller_test.rb
... ... @@ -11,6 +11,7 @@ class EditTemplateControllerTest < Test::Unit::TestCase
11 11 def setup
12 12 @controller = EditTemplateController.new
13 13 @request = ActionController::TestRequest.new
  14 + @request.stubs(:ssl?).returns(true)
14 15 @response = ActionController::TestResponse.new
15 16 login_as 'ze'
16 17 end
... ...