From 935b9eb2f6c465ad5f0ce6f322399dd2b03dd298 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Mon, 31 Aug 2015 10:57:03 -0700 Subject: [PATCH] Monkeypatch Rails session store to support `each`, #2460 --- lib/sidekiq/web.rb | 13 +++++++++++++ myapp/config/initializers/session_store.rb | 15 --------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/sidekiq/web.rb b/lib/sidekiq/web.rb index 71c541b4..bf2b8406 100644 --- a/lib/sidekiq/web.rb +++ b/lib/sidekiq/web.rb @@ -262,3 +262,16 @@ module Sidekiq end end end + +if defined?(::ActionDispatch::Request::Session) && + !::ActionDispatch::Request::Session.respond_to?(:each) + # mperham/sidekiq#2460 + # Rack apps can't reuse the Rails session store without + # this monkeypatch + class ActionDispatch::Request::Session + def each(&block) + hash = self.to_hash + hash.each(&block) + end + end +end diff --git a/myapp/config/initializers/session_store.rb b/myapp/config/initializers/session_store.rb index 12441f01..efa55838 100644 --- a/myapp/config/initializers/session_store.rb +++ b/myapp/config/initializers/session_store.rb @@ -6,18 +6,3 @@ Myapp::Application.config.session_store :cookie_store, key: '_myapp_session' # which shouldn't be used to store highly confidential information # (create the session table with "rails generate session_migration") # Myapp::Application.config.session_store :active_record_store - - -# Monkeypatch necessary due to https://github.com/rails/rails/issues/15843 -require 'rack/session/abstract/id' -class Rack::Session::Abstract::SessionHash - private - def stringify_keys(other) - hash = {} - other = other.to_hash unless other.is_a?(Hash) # hack hack hack - other.each do |key, value| - hash[key.to_s] = value - end - hash - end -end