mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:08 -05:00
📗? Update tests and FlashHash cleanup
* Make FlashHash more like 4.1 (654a2de7a9) * Move tests to stringified keys (b97e087321) * Fix tests to properly load / store to session
This commit is contained in:
committed by
Charlie Somerville
parent
c9a54ce81d
commit
f0895f838f
@@ -480,8 +480,7 @@ module ActionController
|
||||
@request.assign_parameters(@routes, controller_class_name, action.to_s, parameters)
|
||||
|
||||
@request.session = ActionController::TestSession.new(session) if session
|
||||
@request.session["flash"] = @request.flash.update(flash || {})
|
||||
@request.session["flash"].sweep
|
||||
@request.flash.update(flash || {})
|
||||
|
||||
@controller.request = @request
|
||||
build_request_uri(action, parameters)
|
||||
@@ -489,6 +488,7 @@ module ActionController
|
||||
@controller.recycle!
|
||||
@controller.process_with_new_base_test(@request, @response)
|
||||
@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 @@ module ActionDispatch
|
||||
# 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"]).tap(&:sweep)
|
||||
@env[Flash::KEY] ||= Flash::FlashHash.from_session_value(session["flash"])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,23 +78,24 @@ module ActionDispatch
|
||||
include Enumerable
|
||||
|
||||
def self.from_session_value(value)
|
||||
case value
|
||||
when Hash # Rails 4.0
|
||||
flashes = value['flashes'] || {}
|
||||
flashes.stringify_keys!
|
||||
discard = value['discard'] || []
|
||||
discard = discard.map do |item|
|
||||
item.kind_of?(Symbol) ? item.to_s : item
|
||||
end
|
||||
new_from_values(flashes, Set.new(discard))
|
||||
else
|
||||
new
|
||||
end
|
||||
flash = case value
|
||||
when Hash # Rails 4.0
|
||||
flashes = value['flashes'] || {}
|
||||
flashes.stringify_keys!
|
||||
discard = value['discard'] || []
|
||||
discard = discard.map do |item|
|
||||
item.kind_of?(Symbol) ? item.to_s : item
|
||||
end
|
||||
new_from_values(flashes, Set.new(discard))
|
||||
else
|
||||
new
|
||||
end
|
||||
flash.tap(&:sweep)
|
||||
end
|
||||
|
||||
def to_session_value
|
||||
return nil if empty?
|
||||
{'discard' => @used, 'flashes' => Hash[to_a]}
|
||||
{'discard' => @used.to_a, 'flashes' => Hash[to_a]}
|
||||
end
|
||||
|
||||
def initialize #:nodoc:
|
||||
|
||||
@@ -174,13 +174,13 @@ class FlashTest < ActionController::TestCase
|
||||
|
||||
assert_equal(:foo_indeed, flash.discard(:foo)) # valid key passed
|
||||
assert_nil flash.discard(:unknown) # non existant key passed
|
||||
assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.discard().to_hash) # nothing passed
|
||||
assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.discard(nil).to_hash) # nothing passed
|
||||
assert_equal({"foo" => :foo_indeed, "bar" => :bar_indeed}, flash.discard().to_hash) # nothing passed
|
||||
assert_equal({"foo" => :foo_indeed, "bar" => :bar_indeed}, flash.discard(nil).to_hash) # nothing passed
|
||||
|
||||
assert_equal(:foo_indeed, flash.keep(:foo)) # valid key passed
|
||||
assert_nil flash.keep(:unknown) # non existant key passed
|
||||
assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.keep().to_hash) # nothing passed
|
||||
assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.keep(nil).to_hash) # nothing passed
|
||||
assert_equal({"foo" => :foo_indeed, "bar" => :bar_indeed}, flash.keep().to_hash) # nothing passed
|
||||
assert_equal({"foo" => :foo_indeed, "bar" => :bar_indeed}, flash.keep(nil).to_hash) # nothing passed
|
||||
end
|
||||
|
||||
def test_redirect_to_with_alert
|
||||
|
||||
Reference in New Issue
Block a user