mirror of
https://github.com/github/rails.git
synced 2026-02-11 22:55:05 -05:00
Deprecated implicit local assignments when rendering partials
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*Edge*
|
||||
|
||||
* Deprecated implicit local assignments when rendering partials [Josh Peek]
|
||||
|
||||
* Introduce current_cycle helper method to return the current value without bumping the cycle. #417 [Ken Collins]
|
||||
|
||||
* Allow polymorphic_url helper to take url options. #880 [Tarmo Tänav]
|
||||
|
||||
@@ -27,8 +27,14 @@ module ActionView
|
||||
|
||||
def render_partial(view, object = nil, local_assigns = {}, as = nil)
|
||||
object ||= local_assigns[:object] ||
|
||||
local_assigns[variable_name] ||
|
||||
view.controller.instance_variable_get("@#{variable_name}") if view.respond_to?(:controller)
|
||||
local_assigns[variable_name]
|
||||
|
||||
if view.respond_to?(:controller)
|
||||
object ||= ActiveSupport::Deprecation::DeprecatedObjectProxy.new(
|
||||
view.controller.instance_variable_get("@#{variable_name}"),
|
||||
"@#{variable_name} will no longer be implicitly assigned to #{variable_name}"
|
||||
)
|
||||
end
|
||||
|
||||
# Ensure correct object is reassigned to other accessors
|
||||
local_assigns[:object] = local_assigns[variable_name] = object
|
||||
|
||||
@@ -832,8 +832,10 @@ EOS
|
||||
end
|
||||
|
||||
def test_partial_with_implicit_local_assignment
|
||||
get :partial_with_implicit_local_assignment
|
||||
assert_equal "Hello: Marcel", @response.body
|
||||
assert_deprecated do
|
||||
get :partial_with_implicit_local_assignment
|
||||
assert_equal "Hello: Marcel", @response.body
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_missing_partial_template
|
||||
|
||||
@@ -162,6 +162,22 @@ module ActiveSupport
|
||||
end
|
||||
end
|
||||
|
||||
class DeprecatedObjectProxy < DeprecationProxy
|
||||
def initialize(object, message)
|
||||
@object = object
|
||||
@message = message
|
||||
end
|
||||
|
||||
private
|
||||
def target
|
||||
@object
|
||||
end
|
||||
|
||||
def warn(callstack, called, args)
|
||||
ActiveSupport::Deprecation.warn(@message, callstack)
|
||||
end
|
||||
end
|
||||
|
||||
# Stand-in for <tt>@request</tt>, <tt>@attributes</tt>, <tt>@params</tt>, etc.
|
||||
# which emits deprecation warnings on any method call (except +inspect+).
|
||||
class DeprecatedInstanceVariableProxy < DeprecationProxy #:nodoc:
|
||||
|
||||
Reference in New Issue
Block a user