test/flash_responder_test.rb in responders-0.1 vs test/flash_responder_test.rb in responders-0.2
- old
+ new
@@ -25,10 +25,20 @@
alias :new :action
alias :create :action
alias :update :action
alias :destroy :action
+ def with_block
+ respond_with(@resource) do |format|
+ format.html { render :text => "Success!" }
+ end
+ end
+
+ def another
+ respond_with(@resource, :notice => "Yes, notice this!", :alert => "Warning, warning!")
+ end
+
protected
def interpolation_options
{ :reference => 'Ocean Avenue' }
end
@@ -46,10 +56,11 @@
class FlashResponderTest < ActionController::TestCase
tests AddressesController
def setup
+ Responders::FlashResponder.flash_keys = [ :success, :failure ]
@controller.stubs(:polymorphic_url).returns("/")
end
def test_sets_success_flash_message_on_non_get_requests
post :create
@@ -88,29 +99,47 @@
def test_does_not_overwrite_the_flash_if_already_set
post :create, :set_flash => true
assert_equal "Flash is set", flash[:success]
end
+
+ def test_sets_flash_message_even_if_block_is_given
+ post :with_block
+ assert_equal "Resource with block created with success", flash[:success]
+ end
+
+ def test_sets_message_based_on_notice_key
+ Responders::FlashResponder.flash_keys = [ :notice, :alert ]
+ post :another
+ assert_equal "Yes, notice this!", flash[:notice]
+ end
+
+ def test_sets_message_based_on_alert_key
+ Responders::FlashResponder.flash_keys = [ :notice, :alert ]
+ post :another, :fail => true
+ assert_equal "Warning, warning!", flash[:alert]
+ end
end
class NamespacedFlashResponderTest < ActionController::TestCase
tests Admin::AddressesController
def setup
+ Responders::FlashResponder.flash_keys = [ :notice, :alert ]
@controller.stubs(:polymorphic_url).returns("/")
end
def test_sets_the_flash_message_based_on_the_current_controller
put :update
- assert_equal "Admin updated address with success", flash[:success]
+ assert_equal "Admin updated address with success", flash[:notice]
end
def test_sets_the_flash_message_based_on_namespace_actions
post :create
- assert_equal "Admin created address with success", flash[:success]
+ assert_equal "Admin created address with success", flash[:notice]
end
def test_fallbacks_to_non_namespaced_controller_flash_message
delete :destroy
- assert_equal "Successfully deleted the address at Ocean Avenue", flash[:success]
+ assert_equal "Successfully deleted the chosen address at Ocean Avenue", flash[:notice]
end
end
\ No newline at end of file