Skip to content

Commit

Permalink
Make flash.now more intuitive
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Aug 2, 2010
1 parent 97fb238 commit ab895df
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Expand Up @@ -66,10 +66,11 @@ def regexp_value_matches?
end

def flash
flash_and_now = @controller.request.session["flash"]
return @flash if @flash
flash_and_now = @controller.request.session["flash"].dup if @controller.request.session["flash"]
flash = @controller.send(:flash)

if @now
@flash = if @now
flash.keys.each {|key| flash_and_now.delete(key) }
flash_and_now
else
Expand All @@ -78,7 +79,7 @@ def flash
end

def expectation
expectation = "the flash to be set"
expectation = "the flash#{".now" if @now} to be set"
expectation << " to #{@value.inspect}" unless @value.nil?
expectation << ", but #{flash_description}"
expectation
Expand Down
24 changes: 24 additions & 0 deletions test/matchers/controller/set_the_flash_matcher.rb
Expand Up @@ -58,6 +58,30 @@ class SetTheFlashMatcherTest < ActionController::TestCase # :nodoc:
end
end

context "a controller that sets multiple flash messages" do
setup do
@controller = build_response {
flash.now[:notice] = 'value'
flash[:success] = 'great job'
}
end

should "accept setting any flash.now message" do
assert_accepts set_the_flash.now, @controller
assert_accepts set_the_flash, @controller
end

should "accept setting a matched flash.now message" do
assert_accepts set_the_flash.to(/value/).now, @controller
assert_accepts set_the_flash.to(/great/), @controller
end

should "reject setting a different flash.now message" do
assert_rejects set_the_flash.to('other').now, @controller
assert_rejects set_the_flash.to('other'), @controller
end
end

context "a controller that doesn't set a flash message" do
setup do
@controller = build_response
Expand Down

0 comments on commit ab895df

Please sign in to comment.