lib/hanami/action/base_params.rb in hanami-controller-0.8.1 vs lib/hanami/action/base_params.rb in hanami-controller-1.0.0.beta1
- old
+ new
@@ -13,10 +13,22 @@
# This is a builtin integration for Hanami::Router
#
# @since 0.7.0
ROUTER_PARAMS = 'router.params'.freeze
+ # The key that returns Rack session params from the Rack env
+ # Please note that this is used only when an action is unit tested.
+ #
+ # @since 1.0.0.beta1
+ # @api private
+ #
+ # @example
+ # # action unit test
+ # action.call('rack.session' => { 'foo' => 'bar' })
+ # action.session[:foo] # => "bar"
+ RACK_SESSION = 'rack.session'.freeze
+
# @attr_reader env [Hash] the Rack env
#
# @since 0.7.0
# @api private
attr_reader :env
@@ -35,11 +47,11 @@
#
# @since 0.7.0
def initialize(env)
@env = env
@raw = _extract_params
- @params = Utils::Hash.new(@raw).deep_dup.symbolize!.to_h
+ @params = Utils::Hash.new(@raw).deep_dup.deep_symbolize!.to_h
freeze
end
# Returns the object associated with the given key
#
@@ -141,10 +153,16 @@
end
# @since 0.7.0
# @api private
def _router_params(fallback = {})
- env.fetch(ROUTER_PARAMS, fallback)
+ env.fetch(ROUTER_PARAMS) do
+ if session = fallback.delete(RACK_SESSION) # rubocop:disable Lint/AssignmentInCondition
+ fallback[RACK_SESSION] = Utils::Hash.new(session).symbolize!.to_hash
+ end
+
+ fallback
+ end
end
end
end
end