Permalink
Browse files

Merge pull request #63 from nashby/issue-61

do not set flash.now with redirect action
  • Loading branch information...
2 parents d2639f8 + fc7a49b commit 3368cb76e993e029e7262d436b66c463cf13b321 @rafaelfranca rafaelfranca committed Apr 2, 2013
Showing with 9 additions and 1 deletion.
  1. +3 −1 lib/responders/flash_responder.rb
  2. +6 −0 test/flash_responder_test.rb
View
4 lib/responders/flash_responder.rb
@@ -135,7 +135,9 @@ def set_flash(key, value)
end
def set_flash_now?
- (@flash_now == true) || (has_errors? ? @flash_now == :on_failure : @flash_now == :on_success) || (format == :js)
+ return true if @flash_now == true || format == :js
+
+ default_action && (has_errors? ? @flash_now == :on_failure : @flash_now == :on_success)
end
def set_flash_message? #:nodoc:
View
6 test/flash_responder_test.rb
@@ -174,6 +174,12 @@ def test_sets_flash_now_on_failure_by_default
assert_flash_now :failure
end
+ def test_does_not_set_flash_message_to_now_with_errors_and_redirect
+ delete :with_html, :fail => true
+ assert_not_flash_now :failure
+ assert_equal "<strong>OH NOES!</strong> You did it wrong!", flash[:failure]
+ end
+
def test_never_set_flash_now
post :flexible, :fail => true, :responder_options => { :flash_now => false, :alert => "Warning" }
assert_not_flash_now :failure

0 comments on commit 3368cb7

Please sign in to comment.