Permalink
Browse files

Set default of flash_now to :on_failure

Since the usual pattern is that a page gets rerendered after failure,
the proper behavior would be to set the flash directly, so that it
doesn't stick around if you give up and leave the page.
  • Loading branch information...
1 parent 7e0bb76 commit fc4737a5b8c8fa058315a18480dc0723c22d1aeb @iain committed Jul 8, 2011
Showing with 8 additions and 3 deletions.
  1. +2 −2 lib/responders/flash_responder.rb
  2. +6 −1 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)
+ @flash_now = options.delete(:flash_now) || :on_failure
end
def to_html
@@ -164,4 +164,4 @@ def flash_defaults_by_namespace(status) #:nodoc:
defaults << ""
end
end
-end
+end
@@ -135,6 +135,11 @@ def test_sets_message_based_on_alert_key
assert_equal "Warning, warning!", flash[:alert]
end
+ def test_sets_flash_now_on_failure_by_default
+ post :another, :fail => true
+ assert_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),
@@ -169,4 +174,4 @@ def test_fallbacks_to_non_namespaced_controller_flash_message
delete :destroy
assert_equal "Successfully deleted the chosen address at Ocean Avenue", flash[:notice]
end
-end
+end

0 comments on commit fc4737a

Please sign in to comment.