Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
garytaylor opened this issue Jul 28, 2022 · 1 comment
Open

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

garytaylor opened this issue Jul 28, 2022 · 1 comment

Comments

@garytaylor
Copy link

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

@bblimke
Copy link
Owner

bblimke commented Aug 2, 2022

perhaps WebMock::RackResponse#session should return that default_session instead of returning {} ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants