Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

access assigns as a method or hash, with strings or symbols [#4431 st…

…ate:resolved]
  • Loading branch information...
commit 4327ad51abfddde822766702d154df11bd5b47a3 1 parent d4d352b
@dchelimsky dchelimsky authored wycats committed
View
4 actionpack/lib/action_dispatch/testing/test_process.rb
@@ -3,13 +3,13 @@
module ActionDispatch
module TestProcess
def assigns(key = nil)
- assigns = {}
+ assigns = {}.with_indifferent_access
@controller.instance_variable_names.each do |ivar|
next if ActionController::Base.protected_instance_variables.include?(ivar)
assigns[ivar[1..-1]] = @controller.instance_variable_get(ivar)
end
- key.nil? ? assigns : assigns[key.to_s]
+ key.nil? ? assigns : assigns[key]
end
def session
View
16 actionpack/test/controller/test_test.rb
@@ -113,6 +113,11 @@ def delete_cookie
render :nothing => true
end
+ def test_assigns
+ @foo = "foo"
+ render :nothing => true
+ end
+
private
def rescue_action(e)
raise e
@@ -230,6 +235,17 @@ def test_multiple_calls
assert_equal "OK", @response.body
end
+ def test_assigns
+ process :test_assigns
+ # assigns can be accessed using assigns(key)
+ # or assigns[key], where key is a string or
+ # a symbol
+ assert_equal "foo", assigns(:foo)
+ assert_equal "foo", assigns("foo")
+ assert_equal "foo", assigns[:foo]
+ assert_equal "foo", assigns["foo"]
+ end
+
def test_assert_tag_tag
process :test_html_output
Please sign in to comment.
Something went wrong with that request. Please try again.