Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

TestCase should respect the view_assigns API instead of pulling varia…

…bles on its own.
  • Loading branch information...
commit 6e8fe1bf021139a2fbd06a10778ad2c6b67930ef 1 parent 63f6da0
@josevalim josevalim authored
View
4 actionpack/lib/abstract_controller/rendering.rb
@@ -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)
View
7 actionpack/lib/action_dispatch/testing/test_process.rb
@@ -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
View
20 actionpack/test/controller/test_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.