From 6eedcf547d20dd6f18167120e2c37086b79013ba Mon Sep 17 00:00:00 2001 From: Niels Ganser Date: Fri, 23 Jan 2009 17:55:04 +0100 Subject: [PATCH] ActionController::Flash::FlashHash.use now returns either the single value or a key => value hash (actually itself) of whatever it marked as (un)used --- actionpack/lib/action_controller/flash.rb | 10 ++++------ actionpack/test/controller/flash_test.rb | 7 +++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/actionpack/lib/action_controller/flash.rb b/actionpack/lib/action_controller/flash.rb index 56ee9c6..0a2358f 100644 --- a/actionpack/lib/action_controller/flash.rb +++ b/actionpack/lib/action_controller/flash.rb @@ -126,12 +126,10 @@ module ActionController #:nodoc: # use('msg') # marks the "msg" entry as used # use(nil, false) # marks the entire flash as unused (keeps it around for one more action) # use('msg', false) # marks the "msg" entry as unused (keeps it around for one more action) - def use(k=nil, v=true) - unless k.nil? - @used[k] = v - else - keys.each{ |key| use(key, v) } - end + # Returns the value(s) marked as used + def use(key=nil, used=true) + Array(key || keys).each { |k| @used[k] = used } + key ? self[key] : self end end diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index d8a8928..d3201d9 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -139,4 +139,11 @@ class FlashTest < ActionController::TestCase get :std_action assert_nil @response.template.assigns["flash_copy"]["foo"] end + + def test_keep_and_discard_flash_return_values + flash = ActionController::Flash::FlashHash.new + flash.update(:foo => :foo_indeed, :bar => :bar_indeed) + assert_equal(:foo_indeed, flash.discard(:foo)) + assert_equal({:foo => :foo_indeed, :bar => :bar_indeed}, flash.keep) + end end -- 1.6.0.2