Permalink
Browse files

Monkey patch FlashHash in test_helper to get used keys.

Return @used (Rails 3) or @discard (Rails 4) if available.
  • Loading branch information...
1 parent e3d8ee0 commit 04732d7f9095576a5caa75aebce4fc5a45b7dcfb @spectator spectator committed Mar 1, 2013
Showing with 13 additions and 2 deletions.
  1. +2 −2 test/flash_responder_test.rb
  2. +11 −0 test/test_helper.rb
@@ -181,13 +181,13 @@ def test_never_set_flash_now
# If we have flash.now, it's always marked as used.
def assert_flash_now(k)
- assert flash.instance_variable_get(:@discard).to_a.include?(k.to_sym),
+ assert flash.used_keys.include?(k.to_sym),
"Expected #{k} to be in flash.now, but it's not."
end
def assert_not_flash_now(k)
assert flash[k], "Expected #{k} to be set"
- assert !flash.instance_variable_get(:@discard).include?(k.to_sym),
+ assert !flash.used_keys.include?(k.to_sym),
"Expected #{k} to not be in flash.now, but it is."
end
end
View
@@ -40,6 +40,17 @@ class ActiveSupport::TestCase
end
end
+module ActionDispatch
+ class Flash
+ class FlashHash
+ def used_keys
+ # Rails 3 || Rails 4
+ @used || @discard
+ end
+ end
+ end
+end
+
class Model
include ActiveModel::Conversion
include ActiveModel::Validations

0 comments on commit 04732d7

Please sign in to comment.