From 394a7d45364abf53494fa30f48f2627adf899cf7 Mon Sep 17 00:00:00 2001 From: Chris Hanks Date: Sat, 19 Jun 2010 23:44:03 -0700 Subject: [PATCH] Let render take :notice, :alert and :flash parameters, to pass along to flash.now. --- actionpack/lib/action_controller/metal/flash.rb | 21 +++++++++++++++++ actionpack/test/controller/flash_test.rb | 27 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_controller/metal/flash.rb b/actionpack/lib/action_controller/metal/flash.rb index bd768b6..d134a57 100644 --- a/actionpack/lib/action_controller/metal/flash.rb +++ b/actionpack/lib/action_controller/metal/flash.rb @@ -24,5 +24,26 @@ module ActionController #:nodoc: super(options, response_status_and_flash) end + + def render(*args) #:doc: + options = args.extract_options! + + if alert = options.delete(:alert) + flash.now[:alert] = alert + end + + if notice = options.delete(:notice) + flash.now[:notice] = notice + end + + if other_flashes = options.delete(:flash) + other_flashes.each do |key, value| + flash.now[key] = value + end + end + + args << options + super(*args) + end end end diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index 5c636cb..bef06df 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -94,6 +94,18 @@ class FlashTest < ActionController::TestCase def redirect_with_other_flashes redirect_to '/wonderland', :flash => { :joyride => "Horses!" } end + + def render_with_alert + render :inline => "hello", :alert => "Beware the nowheres!" + end + + def render_with_notice + render :inline => "hello", :notice => "Good luck in the somewheres!" + end + + def render_with_other_flashes + render :inline => "hello", :flash => { :joyride => "Horses!" } + end end tests TestController @@ -207,6 +219,21 @@ class FlashTest < ActionController::TestCase get :redirect_with_other_flashes assert_equal "Horses!", @controller.send(:flash)[:joyride] end + + def test_redirect_to_with_alert + get :render_with_alert + assert_equal "Beware the nowheres!", @controller.send(:flash)[:alert] + end + + def test_redirect_to_with_notice + get :render_with_notice + assert_equal "Good luck in the somewheres!", @controller.send(:flash)[:notice] + end + + def test_redirect_to_with_other_flashes + get :render_with_other_flashes + assert_equal "Horses!", @controller.send(:flash)[:joyride] + end end class FlashIntegrationTest < ActionController::IntegrationTest -- 1.7.0.4