From 99369b2b0eae51bb187efdd23a04c2a4c7235e3f Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Fri, 15 Oct 2010 08:17:36 -0500 Subject: [PATCH] Hack to ensure view_assigns does the right thing without checking the Rails version. --- lib/rspec/rails/view_assigns.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/rspec/rails/view_assigns.rb b/lib/rspec/rails/view_assigns.rb index 288af2dca2..4fa8b91bfb 100644 --- a/lib/rspec/rails/view_assigns.rb +++ b/lib/rspec/rails/view_assigns.rb @@ -13,17 +13,26 @@ def assign(key, value) _encapsulated_assigns[key] = value end - if ::Rails::VERSION::STRING =~ /3\.0\.[01]/ - def _assigns + def view_assigns + begin + # TODO: _assigns was deprecated in favor of view_assigns after + # Rails-3.0.0 was released. Since we are not able to predict when + # the _assigns/view_assigns patch will be released (I thought it + # would have been in 3.0.1, but 3.0.1 bypassed this change for a + # security fix), this bit ensures that we do the right thing without + # knowing anything about the Rails version we are dealing with. + # + # Once that change _is_ released, this can be changed to something + # that checks for the Rails version when the module is being + # interpreted, as it was before commit dd0095. super.merge(_encapsulated_assigns) - end - def view_assigns + rescue _assigns end - else # >= 3.0.2 maybe... - def view_assigns - super.merge(_encapsulated_assigns) - end + end + + def _assigns + super.merge(_encapsulated_assigns) end private @@ -32,6 +41,7 @@ def _encapsulated_assigns @_encapsulated_assigns ||= {} end end + end end end