mirror of https://github.com/rails/rails
Merge pull request #28895 from codeforkjeff/fix-session-keys-and-values-methods
Add lazy loading to #keys and #values methods in Session
This commit is contained in:
commit
cfd2eff46c
|
@ -101,11 +101,13 @@ module ActionDispatch
|
||||||
|
|
||||||
# Returns keys of the session as Array.
|
# Returns keys of the session as Array.
|
||||||
def keys
|
def keys
|
||||||
|
load_for_read!
|
||||||
@delegate.keys
|
@delegate.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns values of the session as Array.
|
# Returns values of the session as Array.
|
||||||
def values
|
def values
|
||||||
|
load_for_read!
|
||||||
@delegate.values
|
@delegate.values
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,11 @@ module ActionDispatch
|
||||||
assert_equal %w[rails adequate], s.keys
|
assert_equal %w[rails adequate], s.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_keys_with_deferred_loading
|
||||||
|
s = Session.create(store_with_data, req, {})
|
||||||
|
assert_equal %w[sample_key], s.keys
|
||||||
|
end
|
||||||
|
|
||||||
def test_values
|
def test_values
|
||||||
s = Session.create(store, req, {})
|
s = Session.create(store, req, {})
|
||||||
s["rails"] = "ftw"
|
s["rails"] = "ftw"
|
||||||
|
@ -61,6 +66,11 @@ module ActionDispatch
|
||||||
assert_equal %w[ftw awesome], s.values
|
assert_equal %w[ftw awesome], s.values
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_values_with_deferred_loading
|
||||||
|
s = Session.create(store_with_data, req, {})
|
||||||
|
assert_equal %w[sample_value], s.values
|
||||||
|
end
|
||||||
|
|
||||||
def test_clear
|
def test_clear
|
||||||
s = Session.create(store, req, {})
|
s = Session.create(store, req, {})
|
||||||
s["rails"] = "ftw"
|
s["rails"] = "ftw"
|
||||||
|
@ -113,6 +123,14 @@ module ActionDispatch
|
||||||
def delete_session(env, id, options); 123; end
|
def delete_session(env, id, options); 123; end
|
||||||
}.new
|
}.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def store_with_data
|
||||||
|
Class.new {
|
||||||
|
def load_session(env); [1, { "sample_key" => "sample_value" }]; end
|
||||||
|
def session_exists?(env); true; end
|
||||||
|
def delete_session(env, id, options); 123; end
|
||||||
|
}.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class SessionIntegrationTest < ActionDispatch::IntegrationTest
|
class SessionIntegrationTest < ActionDispatch::IntegrationTest
|
||||||
|
|
Loading…
Reference in New Issue