Permalink
Browse files

Revert "Merge pull request #8017 from jcoglan/objectless_sessions"

This reverts commit 3637656, reversing
changes made to 3148ed9.

Conflicts:
	actionpack/lib/action_dispatch/middleware/flash.rb

Reason: it broke Sam's CI

#8017 (comment)
  • Loading branch information...
1 parent 648a95b commit 484283968e8ad7dc8a7864b65603671bec4f2850 @jonleighton jonleighton committed Nov 9, 2012
@@ -509,7 +509,7 @@ def process(action, http_method = 'GET', *args)
@request.assign_parameters(@routes, controller_class_name, action.to_s, parameters)
@request.session.update(session) if session
- @request.flash.update(flash || {})
+ @request.session["flash"] = @request.flash.update(flash || {})
@controller.request = @request
@controller.response = @response
@@ -526,7 +526,6 @@ def process(action, http_method = 'GET', *args)
@response.prepare!
@assigns = @controller.respond_to?(:view_assigns) ? @controller.view_assigns : {}
- @request.session['flash'] = @request.flash.to_session_value
@request.session.delete('flash') if @request.session['flash'].blank?
@response
end
@@ -4,7 +4,7 @@ class Request < Rack::Request
# read a notice you put there or <tt>flash["notice"] = "hello"</tt>
# to put a new one.
def flash
- @env[Flash::KEY] ||= Flash::FlashHash.from_session_value(session["flash"])
+ @env[Flash::KEY] ||= (session["flash"] || Flash::FlashHash.new).tap(&:sweep)
end
end
@@ -70,31 +70,16 @@ def notice=(message)
end
end
+ # Implementation detail: please do not change the signature of the
+ # FlashHash class. Doing that will likely affect all Rails apps in
+ # production as the FlashHash currently stored in their sessions will
+ # become invalid.
class FlashHash
include Enumerable
- def self.from_session_value(value)
- flash = case value
- when FlashHash # Rails 3.1, 3.2
- new(value.instance_variable_get(:@flashes), value.instance_variable_get(:@used))
- when Hash # Rails 4.0
- new(value['flashes'], value['discard'])
- else
- new
- end
-
- flash.sweep
- flash
- end
-
- def to_session_value
- return nil if empty?
- { 'discard' => @discard.to_a, 'flashes' => @flashes }
- end
-
- def initialize(flashes = {}, discard = []) #:nodoc:
- @discard = Set.new(discard)
- @flashes = flashes
+ def initialize #:nodoc:
+ @discard = Set.new
+ @flashes = {}
@now = nil
end
@@ -238,7 +223,7 @@ def call(env)
if flash_hash
if !flash_hash.empty? || session.key?('flash')
- session["flash"] = flash_hash.to_session_value
+ session["flash"] = flash_hash
new_hash = flash_hash.dup
else
new_hash = flash_hash
@@ -46,27 +46,6 @@ def test_to_hash
assert_equal({'foo' => 'bar'}, @hash.to_hash)
end
- def test_to_session_value
- @hash['foo'] = 'bar'
- assert_equal({'flashes' => {'foo' => 'bar'}, 'discard' => []}, @hash.to_session_value)
-
- @hash.discard('foo')
- assert_equal({'flashes' => {'foo' => 'bar'}, 'discard' => %w[foo]}, @hash.to_session_value)
-
- @hash.now['qux'] = 1
- assert_equal({'flashes' => {'foo' => 'bar', 'qux' => 1}, 'discard' => %w[foo qux]}, @hash.to_session_value)
-
- @hash.sweep
- assert_equal(nil, @hash.to_session_value)
- end
-
- def test_from_session_value
- rails_3_2_cookie = 'BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWY4ZTFiODE1MmJhNzYwOWMyOGJiYjE3ZWM5MjYzYmE3BjsAVEkiCmZsYXNoBjsARm86JUFjdGlvbkRpc3BhdGNoOjpGbGFzaDo6Rmxhc2hIYXNoCToKQHVzZWRvOghTZXQGOgpAaGFzaHsAOgxAY2xvc2VkRjoNQGZsYXNoZXN7BkkiDG1lc3NhZ2UGOwBGSSIKSGVsbG8GOwBGOglAbm93MA=='
- session = Marshal.load(Base64.decode64(rails_3_2_cookie))
- hash = Flash::FlashHash.from_session_value(session['flash'])
- assert_equal({'flashes' => {'message' => 'Hello'}, 'discard' => %w[message]}, hash.to_session_value)
- end
-
def test_empty?
assert @hash.empty?
@hash['zomg'] = 'bears'

0 comments on commit 4842839

Please sign in to comment.