Permalink
Browse files

Make flash.now more intuitive

  • Loading branch information...
1 parent 97fb238 commit ab895dfea857ab44fd4d4e2ed3d305c9aa14ebb8 @joshuaclayton joshuaclayton committed Aug 2, 2010
@@ -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
@@ -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
@@ -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

0 comments on commit ab895df

Please sign in to comment.