提交 09159d85 编写于 作者: J Jon Moss

Ensure compatibility between ActionDispatch::Request::Session and Rack

Adding the `each` method is required for ensuring compatibility between
Rails, and other Rack frameworks (like Sinatra, etc.), that are mounted
within Rails, and wish to use its session tooling. Prior to this, there
was an inconsistency between ActionDispatch::Request::Session and
Rack::Session::Cookie, due to the absence of the `each` method. This
should hopefully fix that error. :)

For a full integration test with Sinatra and a standalone Rack
application, you can check out the gist for that here: https://gist.github.com/maclover7/08cd95b0bfe259465314311941326470.

Solves #15843.
上级 08e86b4b
......@@ -9,7 +9,7 @@ class Session # :nodoc:
# Singleton object used to determine if an optional param wasn't specified
Unspecified = Object.new
# Creates a session hash, merging the properties of the previous session if any
def self.create(store, req, default_options)
session_was = find req
......@@ -198,6 +198,10 @@ def merge!(other)
@delegate.merge!(other)
end
def each(&block)
to_hash.each(&block)
end
private
def load_for_read!
......
......@@ -114,5 +114,31 @@ def delete_session(env, id, options); 123; end
}.new
end
end
class SessionIntegrationTest < ActionDispatch::IntegrationTest
class MySessionApp
def call(env)
request = Rack::Request.new(env)
request.session['hello'] = 'Hello from MySessionApp!'
[ 200, {}, ['Hello from MySessionApp!'] ]
end
end
Router = ActionDispatch::Routing::RouteSet.new
Router.draw do
get '/mysessionapp' => MySessionApp.new
end
def app
@app ||= RoutedRackApp.new(Router)
end
def test_session_follows_rack_api_contract_1
get '/mysessionapp'
assert_response :ok
assert_equal 'Hello from MySessionApp!', @response.body
assert_equal 'Hello from MySessionApp!', session['hello']
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册