Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

session is not preserved between requests in integration tests

#4941

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

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

State: resolved
Milestone: none
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: Low

Activity

  1. epochwolf
    epochwolf

    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
    

    June 24th, 2010 @ 03:39 PM

  2. Rohit Arondekar
    Rohit Arondekar
    • 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.

    June 24th, 2010 @ 03:41 PM

  3. Neeraj Singh
    Neeraj Singh
    • 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
    

    June 24th, 2010 @ 04:39 PM

  4. Alex Farrill
    Alex Farrill

    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

    June 24th, 2010 @ 04:54 PM

  5. ronin-110977 (at lighthouseapp)
    ronin-110977 (at lighthouseapp)
    • 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.

    August 10th, 2010 @ 03:06 PM

  6. Teflon Ted
    Teflon Ted

    ditto here.

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

    August 10th, 2010 @ 05:16 PM

  7. birkirb
    birkirb

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

    August 19th, 2010 @ 11:06 AM

  8. Pascal Friederich
    Pascal Friederich

    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 ;-)

    August 25th, 2010 @ 04:27 PM

  9. Pascal Friederich
    Pascal Friederich
    • Title changed from session is not preserved between requests in integration tests to [PATCH] session is not preserved between requests in integration tests

    August 25th, 2010 @ 05:01 PM

  10. Sebastian Röbke
    Sebastian Röbke
    • 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?

    September 6th, 2010 @ 10:34 AM

  11. Christian Seiler
  12. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • 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. :)

    October 10th, 2010 @ 08:11 PM

  13. Ryan Bigg
    Ryan Bigg
    • 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.

    October 11th, 2010 @ 03:00 AM

  14. Andrea Campi
    Andrea Campi
    • 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

    October 16th, 2010 @ 11:47 PM

  15. Karol Bucek
    Karol Bucek

    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

    November 8th, 2010 @ 01:48 PM

  16. Jan
    Jan

    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?!

    November 28th, 2010 @ 08:06 PM

  17. Jan
    Jan

    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
    

    November 28th, 2010 @ 09:04 PM

  18. Repository
    Repository
    • 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 session is not preserved between requests in integration tests state:resolved]

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

    December 1st, 2010 @ 11:01 AM