Created
February 27, 2013 11:03
-
-
Save troelskn/5047135 to your computer and use it in GitHub Desktop.
Mock out sessions with Rack::Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.join(File.dirname(__FILE__), 'test_helper.rb') | |
class AppTest < Test::Unit::TestCase | |
def test_get_root_path | |
current_session.rack_session[:user_id] = "1337" | |
get "/" | |
assert last_response.ok? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rack | |
module Test | |
class Session | |
alias_method :old_env_for, :env_for | |
def rack_session | |
@rack_session ||= {} | |
end | |
def rack_session=(hash) | |
@rack_session = hash | |
end | |
def env_for(path, env) | |
old_env_for(path, env).merge({'rack.session' => rack_session}) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, I use Rack::Session::Redis in my application and adding this patch in my test_helper.rb save my time.