Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11558 (new defect)

Opened 8 months ago

ssl_requirement breaks assert_redirect_to

Reported by: foudfou Assigned to: core
Priority: normal Milestone: 2.x
Component: ActionPack Version: edge
Severity: normal Keywords: ssl functional testing
Cc:

Description

assert_redirect_to behaves abnormally if redirected to https (through ss_required).

Example below:

in login_controller.rb :

#...
class LoginController < ApplicationController

  layout "products"
  before_filter :authorize, :except => :login
  ssl_required :login, :add_user
#...
  def login
    session[:user_id] = nil
    if request.post?
      user = User.authenticate(params[:name], params[:password])
      if user
        session[:user_id] = user.id
        uri = session[:original_uri]
        session[:original_uri] = nil
        redirect_to(uri || {  :action => "index" })
      else
        flash[:notice] = "incorrect user or password"
      end
    end
  end
#...

in test/functional/login_controller_test.rb:

#...
  def test_correct_login
    dave = users(:dave)
    post :login, :name => dave.name, :password => 'secret'
    assert_redirected_to :action => "index"
    assert_equal dave.id, session[:user_id]
  end
#...

incomprehensible output :

> ruby ./test/functional/login_controller_test.rb
Loaded suite ./test/functional/login_controller_test
Started
Finished in 1.382436 seconds.

  1) Error:
test_correct_login(LoginControllerTest):
TypeError: can't convert Hash into String
    /home/foo/src/ror/depot/vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb:115:in `=~'
    /home/foo/src/ror/depot/vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb:115:in `assert_redirected_to'
    /home/foo/src/ror/depot/vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb:114:in `collect'
    /home/foo/src/ror/depot/vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb:114:in `assert_redirected_to'
    /home/foo/src/ror/depot/vendor/rails/actionpack/lib/action_controller/assertions.rb:54:in `clean_backtrace'
    /home/foo/src/ror/depot/vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb:54:in `assert_redirected_to'
    ./test/functional/login_controller_test.rb:25:in `test_correct_login'
    /home/foo/src/ror/depot/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/testing/default.rb:7:in `run'