Skip to content

Commit 226d7c6

Browse files
viralpraxiszzakskipkayhil
committed
Add ActionDispatch::Request::Session#store method.
Rack specification states that a hash-like object stored in environment with `rack.session` key MUST implement `store/2` method. Without the alias, this test fails with the following: ``` Exception while processing request: Rack::Lint::LintError: session #<ActionDispatch::Request::Session:0x3570 not yet loaded> must respond to store and []= /home/zzak/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rack-3.1.8/lib/rack/lint.rb:206:in `check_environment' /home/zzak/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rack-3.1.8/lib/rack/lint.rb:63:in `response' /home/zzak/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rack-3.1.8/lib/rack/lint.rb:41:in `call' lib/action_dispatch/middleware/cookies.rb:706:in `call' /home/zzak/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rack-session-2.0.0/lib/rack/session/abstract/id.rb:272:in `context' /home/zzak/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rack-session-2.0.0/lib/rack/session/abstract/id.rb:266:in `call' /home/zzak/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rack-3.1.8/lib/rack/head.rb:15:in `call' /home/zzak/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rack-3.1.8/lib/rack/method_override.rb:28:in `call' lib/action_dispatch/middleware/cookies.rb:706:in `call' lib/action_dispatch/middleware/callbacks.rb:31:in `block in call' /home/zzak/code/rails/activesupport/lib/active_support/callbacks.rb:100:in `run_callbacks' lib/action_dispatch/middleware/callbacks.rb:30:in `call' lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call' lib/action_dispatch/middleware/debug_exceptions.rb:31:in `call' lib/action_dispatch/middleware/show_exceptions.rb:32:in `call' test/abstract_unit.rb:110:in `call' /home/zzak/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rack-test-2.1.0/lib/rack/test.rb:360:in `process_request' /home/zzak/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/rack-test-2.1.0/lib/rack/test.rb:153:in `request' lib/action_dispatch/testing/integration.rb:297:in `process' lib/action_dispatch/testing/integration.rb:19:in `get' lib/action_dispatch/testing/integration.rb:388:in `get' test/dispatch/request/session_test.rb:224:in `test_session_follows_rack_api_contract_1' ``` Co-authored-by: viralpraxis <[email protected]> Co-authored-by: zzak <[email protected]> Co-authored-by: Hartley McGuire <[email protected]>
1 parent 67c6ef2 commit 226d7c6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

actionpack/lib/action_dispatch/request/session.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def []=(key, value)
155155
load_for_write!
156156
@delegate[key.to_s] = value
157157
end
158+
alias store []=
158159

159160
# Clears the session.
160161
def clear

actionpack/test/dispatch/request/session_test.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ def test_destroy
5050
assert_empty s
5151
end
5252

53+
def test_store
54+
s = Session.create(store, req, {})
55+
s.store("foo", "bar")
56+
assert_equal "bar", s["foo"]
57+
end
58+
5359
def test_keys
5460
s = Session.create(store, req, {})
5561
s["rails"] = "ftw"
@@ -205,7 +211,11 @@ def call(env)
205211
end
206212

207213
def app
208-
@app ||= RoutedRackApp.new(Router)
214+
@app ||= RoutedRackApp.new(Router) do |middleware|
215+
@cache = ActiveSupport::Cache::MemoryStore.new
216+
middleware.use ActionDispatch::Session::CacheStore, key: "_session_id", cache: @cache
217+
middleware.use Rack::Lint
218+
end
209219
end
210220

211221
def test_session_follows_rack_api_contract_1

0 commit comments

Comments
 (0)