test/flash_responder_test.rb in responders-0.8.0 vs test/flash_responder_test.rb in responders-0.9.0
- old
+ new
@@ -32,10 +32,15 @@
def with_html
respond_with(@resource)
end
+ def flexible
+ options = params[:responder_options] || {}
+ respond_with(@resource, options)
+ end
+
protected
def interpolation_options
{ :reference => 'Ocean Avenue', :xss => '<script>alert(1)</script>' }
end
@@ -152,18 +157,29 @@
Responders::FlashResponder.flash_keys = [ :xss, :xss ]
post :with_html
assert_equal "<strong>Yay!</strong> <script>alert(1)</script>", flash[:xss]
end
+ def test_sets_flash_now_on_failure_by_default
+ post :another, :fail => true
+ assert_flash_now :alert
+ end
+
+ def test_never_set_flash_now
+ post :flexible, :fail => true, :responder_options => { :flash_now => false, :alert => "Warning" }
+ assert_not_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).to_a.include?(k.to_sym),
"Expected #{k} to be in flash.now, but it's not."
end
def assert_not_flash_now(k)
- assert !flash.instance_variable_get(:@used).to_a.include?(k.to_sym),
+ assert flash[k], "Expected #{k} to be set"
+ assert !flash.instance_variable_get(:@used).include?(k.to_sym),
"Expected #{k} to not be in flash.now, but it is."
end
end
class NamespacedFlashResponderTest < ActionController::TestCase
@@ -183,9 +199,17 @@
post :create
assert_equal "Admin created address with success", flash[:notice]
end
def test_fallbacks_to_non_namespaced_controller_flash_message
+ Responders::FlashResponder.namespace_lookup = true
delete :destroy
assert_equal "Successfully deleted the chosen address at Ocean Avenue", flash[:notice]
+ ensure
+ Responders::FlashResponder.namespace_lookup = false
end
-end
\ No newline at end of file
+
+ def test_does_not_fallbacks_to_non_namespaced_controller_flash_message_if_disabled
+ delete :destroy
+ assert_equal nil, flash[:notice]
+ end
+end