Skip to content

Setting rack.session to hash by default when using to_rack #985

Open
@garytaylor

Description

@garytaylor

In rails 7, if there is no session in the request, it now defaults to an object that responds to enabled?

However, because rack.session is set to {} in webmock (WebMock::RackResponse#session), when webmock us used in a way that mounts this rails app (using to_rack), this causes a failure in the following line in the rails app

ActionDispatch::Flash::RequestMethods#commit_flash

return unless session.enabled?

where 'session' is defined as

      def session
        fetch_header(RACK_SESSION) do |k|
          set_header RACK_SESSION, default_session
        end
      end

and fetch_header will return the session if already defined in env['rack.session'] therefore 'default_session' is not being called. The return value is therefore an empty hash which does not respond to enabled?

I am not sure if this is really a webmock issue or if rails are being a bit naughty setting rack.session to anything but a hash

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions