flash.values not supported in Rails 3.1.0RC1 #172

davidsf opened this Issue May 23, 2011 · 9 comments


None yet

6 participants

davidsf commented May 23, 2011

In Rails 3.1 the flash hash no longer support .values method

diff --git a/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb b/lib/shoulda/matchers/action_controller/set_the_
index 175b552..e5fc3e7 100644
--- a/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb
+++ b/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb
@@ -57,12 +57,12 @@ module Shoulda # :nodoc:

         def string_value_matches?
           return true unless String === @value
-          flash.values.any? {|value| value == @value }
+          flash.select { |key, value| value == @value }.size > 0

         def regexp_value_matches?
           return true unless Regexp === @value
-          flash.values.any? {|value| value =~ @value }
+          flash.select { |key, value| value =~ @value }.size > 0

         def flash

+1 - I put this in as a monkey patch in config/initializers and it solved the problem but would be nice if this were merged into the gem.

sermoa commented Jun 27, 2011

It seems we can no longer do flash.each_pair either :(

sermoa commented Jun 27, 2011

Aha, but we can just use each and it takes two block parameters: type and message. Perfect.

wanchic commented Jul 20, 2011

Thanks for post. Sorry for the amateur question, but if I say:
should set_the_flash.to("Patient was successfully created.")

And it now needs two values |key, value|, how should I access this instead?

wanchic commented Jul 22, 2011

I figured it out. If you have a shoulda statement to set_the_flash, which originally worked in rails 3.0.x:
should set_the_flash.to("Patient was successfully created.")

but does not work in rails 3.1, getting the error:
NoMethodError: undefined method `values' for #ActionDispatch::Flash::FlashHash:0x000000046c4ec8

then add the :notice to indicate the new hash assignment:
should set_the_flash.to(:notice => "Patient was successfully updated.")

That should fix the problem.


With :notice pass the test but it doesn't fix the problem:
you can write :notice => "ASASDASDASDWHATEVER YOU WANT" and pass the test. It's an error.


The last version works! Thx!


gem 'shoulda', :git => 'https://github.com/thoughtbot/shoulda.git'

jasonm commented Nov 1, 2011

This issue belongs against the shoulda-matchers project https://github.com/thoughtbot/shoulda-matchers, looks like it's fixed in master thoughtbot/shoulda-matchers@71c47f7 which should be available in shoulda-matchers gem >=1.0.0.beta3 https://rubygems.org/gems/shoulda-matchers

Not sure why that is still in a prerelease gem version, but that's a Q for the shoulda-matchers project.

@jasonm jasonm closed this Nov 1, 2011
jasonm commented Nov 1, 2011

Created issue to cut 1.0 release of shoulda-matchers: thoughtbot/shoulda-matchers#32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment