Skip to content

Commit

Permalink
do not set flash.now with redirect action
Browse files Browse the repository at this point in the history
closes #61
  • Loading branch information
nashby committed Apr 2, 2013
1 parent d2639f8 commit fc7a49b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/responders/flash_responder.rb
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions test/flash_responder_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit fc7a49b

Please sign in to comment.