This project is archived and is in readonly mode.

#4941 ✓resolved
Alex Farrill

session is not preserved between requests in integration tests

Reported by Alex Farrill | June 23rd, 2010 @ 01:26 AM

Make an integration test:

test "index" do

get "/"
s1 = @response.session[:session_id]

get "/"
s2 = @response.session[:session_id]

assert_equal s1, s2

end

Passes in Rails 2.3.5, fails in Rails 2.3.8

Haven't been following the development around session very closely, am I missing a setting in my integration tests or has this behavior intentionally changed?

Thanks,

Alex

Comments and changes to this ticket

  • epochwolf

    epochwolf June 24th, 2010 @ 03:39 PM

    The following test passes. (Using rails 2.3.8 and ruby 1.8.7)

    require 'test_helper'
    
    class SessionTest < ActionController::IntegrationTest
      
      def test_session
        get "/home/index"
        s1 = @response.session[:session_id]
        
    
        get "/home/index"
        s2 = @response.session[:session_id]
        
        assert_equal s1, s2
      end
    end
    
  • Rohit Arondekar

    Rohit Arondekar June 24th, 2010 @ 03:41 PM

    • State changed from “new” to “invalid”

    Thanks epochwolf. :)

    Closing ticket, if this is still an issue for somebody please make a comment and I'll reopen.

  • Neeraj Singh

    Neeraj Singh June 24th, 2010 @ 04:39 PM

    • State changed from “invalid” to “open”

    I am able to reproduce it.

    <"d265f9bd3feaf92460d4e4803913f114"> expected but was
    <"8a577f9faf4c0b2f5d1a5f07907b8c56">.
    
    class UsersController < ApplicationController
      def index
        session[:foo] = :bar
        @users = User.all
      end
    end
    
    require "#{File.dirname(__FILE__)}/../test_helper"
    class SessionTest < ActionController::IntegrationTest
      def test_session
        get "/"
        s1 = @response.session[:session_id]
        get "/"
        s2 = @response.session[:session_id]
        assert_equal s1, s2
      end
    end
    
  • Alex Farrill

    Alex Farrill June 24th, 2010 @ 04:54 PM

    Ruby versions where I observe this behavior:
    ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
    ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.7.0] Ruby Enterprise Edition 20090610

  • ronin-110977 (at lighthouseapp)

    ronin-110977 (at lighthouseapp) August 10th, 2010 @ 03:06 PM

    • Importance changed from “” to “Low”

    We are running ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux] with Rails 2.3.8 and we are having the same problems with the session not persisting in integration tests.

  • Teflon Ted

    Teflon Ted August 10th, 2010 @ 05:16 PM

    ditto here.

    »ruby -v
    ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
    »rails -v
    Rails 2.3.8
    
  • birkirb

    birkirb August 19th, 2010 @ 11:06 AM

    Same here, broke all integration tests that depend on sessions.
    That's low priority?

  • Pascal Friederich

    Pascal Friederich August 25th, 2010 @ 04:27 PM

    I've added a patch which fixes the issue and also removes some code that has found its way into Rack in the meantime anyway. What it basically does is use Rack::Utils.set_cookie_header! to generate the Set-Cookie header and don't rely on manually constructing the header anymore. That also eliminates this ticket because set_cookie_header! already knows how to deal with header["Set-Cookie"] no matter if it's a String or an Array.

    The patch is for 2-3-stable.

    Note: if you are applying the patch, keep in mind that unfortunately the "stable" branch currently (with commit 0fcb4302e1a1193b2a59dd76abb436b24c93e3ac being the latest) is not as stable as you would expect it, because it has some failing test (already before applying my patch) which are unrelated to my patch ;-)

  • Pascal Friederich

    Pascal Friederich August 25th, 2010 @ 05:01 PM

    • Title changed from “session is not preserved between requests in integration tests” to “[PATCH] session is not preserved between requests in integration tests”
  • Sebastian Röbke

    Sebastian Röbke September 6th, 2010 @ 10:34 AM

    • Assigned user set to “Jeremy Kemper”
    • Tag changed from rails 2.3.8, integration_test, sessions to rails 2.3.8, 2.3.10, 2.3.9, 2.3.x, integration_test, sessions

    Any chance to get this into 2.3.10?

  • Christian Seiler
  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer October 10th, 2010 @ 08:11 PM

    • Title changed from “[PATCH] session is not preserved between requests in integration tests” to “session is not preserved between requests in integration tests”
    • Tag changed from rails 2.3.8, 2.3.10, 2.3.9, 2.3.x, integration_test, sessions to rails 2.3.8, 2.3.10, 2.3.9, 2.3.x, integration_test, patch, sessions

    Using the "patch" tag instead of prefixing the ticket title with "[PATCH]" to make sure patched tickets end up in the open patches bin. :)

  • Ryan Bigg

    Ryan Bigg October 11th, 2010 @ 03:00 AM

    • Tag changed from rails 2.3.8, 2, integration_test, patch, sessions to 2.3.10 2.3.9 2.3.x integration_test patch rails 2.3.8 sessions

    Automatic cleanup of spam.

  • Andrea Campi

    Andrea Campi October 16th, 2010 @ 11:47 PM

    • Tag changed from 2.3.10 2.3.9 2.3.x integration_test patch rails 2.3.8 sessions to 2-3-stable, integration_test, paths, sessions
  • Karol Bucek

    Karol Bucek November 8th, 2010 @ 01:48 PM

    I've extracted some code from the provided patch that is usable as a workaround:

    https://gist.github.com/646602

    require 'integration_test_session_patch' in Your test_helper.rb

  • Jan

    Jan November 28th, 2010 @ 08:06 PM

    I am having this or a similar issue with Rails 3.0.3 and ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9].

    Having your integration tests rendered useless is a killer for migrating our app to Rails 3. Priority low?!

  • Jan

    Jan November 28th, 2010 @ 09:04 PM

    Sorry. My problem was that I have set a cookie domain even in test, but did not set the host for my integration tests.

    I guess, it's not related to this issue. The following helped:

    def setup
      host! THE_HOST_EQUAL_TO_MY_SESSION_STORE_DOMAIN
    end
    
  • Repository

    Repository December 1st, 2010 @ 11:01 AM

    • State changed from “open” to “resolved”

    (from [e0eb8e9c65ededce64169948d4dd51b0079cdd10]) Let Rack::Utils.set_cookie_header! create the Set-Cookie header instead of manually fiddling with the response headers [#4941 state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    https://github.com/rails/rails/commit/e0eb8e9c65ededce64169948d4dd5...

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages