Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix flash setting with custom keys #46

Merged
merged 1 commit into from

2 participants

@marcandre

With custom keys and providing :notice/:alert option, flash_responder was not setting the right flash.

Thanks

@josevalim josevalim merged commit b176bb2 into from
@marcandre

@josevalim I hope you realize how awesome it is to have pull requests merged in so quickly :-)

Thanks!

@josevalim
Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 7, 2012
  1. @marcandre
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 4 deletions.
  1. +2 −2 lib/responders/flash_responder.rb
  2. +12 −2 test/flash_responder_test.rb
View
4 lib/responders/flash_responder.rb
@@ -113,11 +113,11 @@ def to_js
def set_flash_message!
if has_errors?
- set_flash(:alert, @alert)
status = Responders::FlashResponder.flash_keys.last
+ set_flash(status, @alert)
else
- set_flash(:notice, @notice)
status = Responders::FlashResponder.flash_keys.first
+ set_flash(status, @notice)
end
return if controller.flash[status].present?
View
14 test/flash_responder_test.rb
@@ -131,6 +131,16 @@ def test_sets_flash_message_can_be_set_to_now_only_on_failure
assert_not_flash_now :success
end
+ def test_sets_message_based_on_notice_key_with_custom_keys
+ post :another
+ assert_equal "Yes, notice this!", flash[:success]
+ end
+
+ def test_sets_message_based_on_alert_key_with_custom_keys
+ post :another, :fail => true
+ assert_equal "Warning, warning!", flash[:failure]
+ end
+
def test_sets_message_based_on_notice_key
Responders::FlashResponder.flash_keys = [ :notice, :alert ]
post :another
@@ -161,12 +171,12 @@ def test_escapes_html_interpolations
def test_sets_flash_now_on_failure_by_default
post :another, :fail => true
- assert_flash_now :alert
+ assert_flash_now :failure
end
def test_never_set_flash_now
post :flexible, :fail => true, :responder_options => { :flash_now => false, :alert => "Warning" }
- assert_not_flash_now :alert
+ assert_not_flash_now :failure
end
# If we have flash.now, it's always marked as used.
Something went wrong with that request. Please try again.