When trying to access or assign to the session in a functional test, I get a TypeError saying it cannot convert the session key to an Integer. When I print the class of the session, it returns "Array".
Here's a simple test case that illustrates this (this is from a fresh new Rails 1.2.3 project with nothing more than a test controller generated for it):
require File.dirname(__FILE__) + '/../test_helper'
require 'test_controller'
# Re-raise errors caught by the controller.
class TestController; def rescue_action(e) raise e end; end
class TestControllerTest < Test::Unit::TestCase
def setup
@controller = TestController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_session
puts session.class
puts @response.session.class
session["test_user"] = "testuser1"
end
end
When I run this test, I get the following:
Loaded suite test_controller_test
Started
Array
Array
E
Finished in 0.047 seconds.
1) Error:
test_session(TestControllerTest):
TypeError: can't convert String into Integer
test_controller_test.rb:18:in `[]='
test_controller_test.rb:18:in `test_session'
1 tests, 0 assertions, 0 failures, 1 errors