Permalink
Browse files

Fix flash setting with custom keys

  • Loading branch information...
1 parent 1ed31e4 commit 23996d0e36e5e559dc7f41d1e18c2e5f47ed9b42 @marcandre committed Jun 7, 2012
Showing with 14 additions and 4 deletions.
  1. +2 −2 lib/responders/flash_responder.rb
  2. +12 −2 test/flash_responder_test.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?
@@ -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.

0 comments on commit 23996d0

Please sign in to comment.