Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed Aug 28, 2008
2 parents 293f997 + acbf2b7 commit ce4d138
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -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]
Expand Down
10 changes: 8 additions & 2 deletions actionpack/lib/action_view/renderable_partial.rb
Expand Up @@ -27,8 +27,14 @@ def render(view, local_assigns = {})

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
Expand Down
6 changes: 4 additions & 2 deletions actionpack/test/controller/new_render_test.rb
Expand Up @@ -832,8 +832,10 @@ def test_partial_hash_collection_with_locals
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
Expand Down
16 changes: 16 additions & 0 deletions activesupport/lib/active_support/deprecation.rb
Expand Up @@ -162,6 +162,22 @@ def method_missing(called, *args, &block)
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:
Expand Down
4 changes: 3 additions & 1 deletion railties/test/secret_key_generation_test.rb
Expand Up @@ -31,6 +31,8 @@ def setup
end

def test_secret_key_generation
assert @generator.generate_secret.length >= SECRET_KEY_MIN_LENGTH
assert_deprecated /ActiveSupport::SecureRandom\.hex\(64\)/ do
assert @generator.generate_secret.length >= SECRET_KEY_MIN_LENGTH
end
end
end

0 comments on commit ce4d138

Please sign in to comment.