Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make flash.now more intuitive

  • Loading branch information...
commit ab895dfea857ab44fd4d4e2ed3d305c9aa14ebb8 1 parent 97fb238
@joshuaclayton joshuaclayton authored
View
7 lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb
@@ -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
View
24 test/matchers/controller/set_the_flash_matcher.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.