提交 6e8fe1bf 编写于 作者: J José Valim

TestCase should respect the view_assigns API instead of pulling variables on its own.

上级 63f6da05
......@@ -120,8 +120,6 @@ def _render_template(options) #:nodoc:
view_renderer.render(view_context, options)
end
private
DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w(
@_action_name @_response_body @_formats @_prefixes @_config
@_view_context_class @_view_renderer @_lookup_context
......@@ -139,6 +137,8 @@ def view_assigns
hash
end
private
# Normalize args and options.
# :api: private
def _normalize_render(*args, &block)
......
......@@ -5,12 +5,7 @@
module ActionDispatch
module TestProcess
def assigns(key = nil)
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
assigns = @controller.view_assigns.with_indifferent_access
key.nil? ? assigns : assigns[key]
end
......
......@@ -146,6 +146,17 @@ def setup
end
end
class ViewAssignsController < ActionController::Base
def test_assigns
@foo = "foo"
render :nothing => true
end
def view_assigns
{ "bar" => "bar" }
end
end
def test_raw_post_handling
params = ActiveSupport::OrderedHash[:page, {:name => 'page name'}, 'some key', 123]
post :render_raw_post, params.dup
......@@ -256,6 +267,15 @@ def test_assigns
assert_equal "foo", assigns["foo"]
end
def test_view_assigns
@controller = ViewAssignsController.new
process :test_assigns
assert_equal nil, assigns(:foo)
assert_equal nil, assigns[:foo]
assert_equal "bar", assigns(:bar)
assert_equal "bar", assigns[:bar]
end
def test_assert_tag_tag
process :test_html_output
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册