Permalink
Browse files

Use a default for flash_now, enabling it to be set to false.

The previous behavior to never set flash.now can now be used again.
  • Loading branch information...
1 parent b706e7e commit d36fc1a41357f07deb492d4dacabd2bf4d1cdef1 @iain committed Jul 9, 2011
Showing with 12 additions and 1 deletion.
  1. +1 −1 lib/responders/flash_responder.rb
  2. +11 −0 test/flash_responder_test.rb
@@ -85,7 +85,7 @@ def initialize(controller, resources, options={})
@flash = options.delete(:flash)
@notice = options.delete(:notice)
@alert = options.delete(:alert)
- @flash_now = options.delete(:flash_now) || :on_failure
+ @flash_now = options.delete(:flash_now) { :on_failure }
end
def to_html
@@ -30,6 +30,11 @@ def another
respond_with(@resource, :notice => "Yes, notice this!", :alert => "Warning, warning!")
end
+ def flexible
+ options = params[:responder_options] || {}
+ respond_with(@resource, options)
+ end
+
protected
def interpolation_options
@@ -140,6 +145,12 @@ def test_sets_flash_now_on_failure_by_default
assert_flash_now :alert
end
+ def test_never_set_flash_now
+ post :flexible, :fail => true, :responder_options => { :flash_now => false, :alert => "Warning" }
+ assert flash[:alert].present?, "Flash should be present"
+ assert_not_flash_now :alert
+ end
+
# If we have flash.now, it's always marked as used.
def assert_flash_now(k)
assert flash.instance_variable_get(:@used).include?(k.to_sym),

0 comments on commit d36fc1a

Please sign in to comment.