Skip to content

Commit

Permalink
Use a default for flash_now, enabling it to be set to false.
Browse files Browse the repository at this point in the history
The previous behavior to never set flash.now can now be used again.
  • Loading branch information
iain committed Jul 9, 2011
1 parent b706e7e commit d36fc1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/responders/flash_responder.rb
Expand Up @@ -85,7 +85,7 @@ def initialize(controller, resources, options={})
@flash = options.delete(:flash) @flash = options.delete(:flash)
@notice = options.delete(:notice) @notice = options.delete(:notice)
@alert = options.delete(:alert) @alert = options.delete(:alert)
@flash_now = options.delete(:flash_now) || :on_failure @flash_now = options.delete(:flash_now) { :on_failure }
end end


def to_html def to_html
Expand Down
11 changes: 11 additions & 0 deletions test/flash_responder_test.rb
Expand Up @@ -30,6 +30,11 @@ def another
respond_with(@resource, :notice => "Yes, notice this!", :alert => "Warning, warning!") respond_with(@resource, :notice => "Yes, notice this!", :alert => "Warning, warning!")
end end


def flexible
options = params[:responder_options] || {}
respond_with(@resource, options)
end

protected protected


def interpolation_options def interpolation_options
Expand Down Expand Up @@ -140,6 +145,12 @@ def test_sets_flash_now_on_failure_by_default
assert_flash_now :alert assert_flash_now :alert
end end


def test_never_set_flash_now
post :flexible, :fail => true, :responder_options => { :flash_now => false, :alert => "Warning" }
assert flash[:alert].present?, "Flash should be present"
assert_not_flash_now :alert
end

# If we have flash.now, it's always marked as used. # If we have flash.now, it's always marked as used.
def assert_flash_now(k) def assert_flash_now(k)
assert flash.instance_variable_get(:@used).include?(k.to_sym), assert flash.instance_variable_get(:@used).include?(k.to_sym),
Expand Down

0 comments on commit d36fc1a

Please sign in to comment.