Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

flash.values not supported in Rails 3.1.0RC1 #172

Closed
davidsf opened this Issue · 9 comments

6 participants

@davidsf

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
         end

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

         def flash
@alexrothenberg

+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

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

@sermoa

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

@wanchic

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

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.

@linuxonrails

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.

@linuxonrails

The last version works! Thx!

Gemfile:

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

@jasonm

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
@jasonm

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
Something went wrong with that request. Please try again.