Skip to content

Commit

Permalink
Hack to ensure view_assigns does the right thing without checking the
Browse files Browse the repository at this point in the history
Rails version.
  • Loading branch information
dchelimsky committed Oct 15, 2010
1 parent dd0095a commit 99369b2
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/rspec/rails/view_assigns.rb
Expand Up @@ -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
Expand All @@ -32,6 +41,7 @@ def _encapsulated_assigns
@_encapsulated_assigns ||= {}
end
end

end
end
end

0 comments on commit 99369b2

Please sign in to comment.