提交 8e9c48b5 编写于 作者: I IWASE

Add AC::TestSession#dig method like AD::Request::Session

上级 09fbee82
......@@ -202,6 +202,11 @@ def destroy
clear
end
def dig(*keys)
keys = keys.map.with_index { |key, i| i.zero? ? key.to_s : key }
@data.dig(*keys)
end
def fetch(key, *args, &block)
@data.fetch(key.to_s, *args, &block)
end
......
......@@ -43,6 +43,12 @@ def test_keys_and_values
assert_equal %w(1 2), session.values
end
def test_dig
session = ActionController::TestSession.new(one: { two: { three: "3" } })
assert_equal("3", session.dig(:one, :two, :three))
assert_nil(session.dig(:ruby, :on, :rails))
end
def test_fetch_returns_default
session = ActionController::TestSession.new(one: "1")
assert_equal("2", session.fetch(:two, "2"))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册