aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJon Moss <me@jonathanmoss.me>2016-05-02 17:56:57 -0400
committerJon Moss <me@jonathanmoss.me>2016-05-04 15:49:25 -0400
commit09159d8530069ded68d1d5455dbe5009fb44c1c7 (patch)
tree06dda1a1c0f7a5751c704df22efd9f09c5479034 /actionpack
parent08e86b4b055c3b527ebc3f3fdaaa2198ce919cd4 (diff)
downloadrails-09159d8530069ded68d1d5455dbe5009fb44c1c7.tar.gz
rails-09159d8530069ded68d1d5455dbe5009fb44c1c7.tar.bz2
rails-09159d8530069ded68d1d5455dbe5009fb44c1c7.zip
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.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/request/session.rb6
-rw-r--r--actionpack/test/dispatch/request/session_test.rb26
2 files changed, 31 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb
index 42890225fa..47568f6ad0 100644
--- a/actionpack/lib/action_dispatch/request/session.rb
+++ b/actionpack/lib/action_dispatch/request/session.rb
@@ -9,7 +9,7 @@ module ActionDispatch
# 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 @@ module ActionDispatch
@delegate.merge!(other)
end
+ def each(&block)
+ to_hash.each(&block)
+ end
+
private
def load_for_read!
diff --git a/actionpack/test/dispatch/request/session_test.rb b/actionpack/test/dispatch/request/session_test.rb
index 7dcbcc5c21..e022e7e21e 100644
--- a/actionpack/test/dispatch/request/session_test.rb
+++ b/actionpack/test/dispatch/request/session_test.rb
@@ -114,5 +114,31 @@ module ActionDispatch
}.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