Skip to content

Commit

Permalink
Remove deprecated support to instance variables as locals to partials
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Mar 3, 2023
1 parent 23344d4 commit 8241178
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 deletions.
4 changes: 4 additions & 0 deletions actionview/CHANGELOG.md
@@ -1,3 +1,7 @@
* Remove deprecated support to passing instance variables as locals to partials.

*Rafael Mendonça França*

* Remove deprecated constant `ActionView::Path`.

*Rafael Mendonça França*
Expand Down
12 changes: 2 additions & 10 deletions actionview/lib/action_view/template.rb
Expand Up @@ -457,16 +457,8 @@ def locals_code
# Only locals with valid variable names get set directly. Others will
# still be available in local_assigns.
locals = @locals - Module::RUBY_RESERVED_KEYWORDS
deprecated_locals = locals.grep(/\A@+/)
if deprecated_locals.any?
ActionView.deprecator.warn(<<~MSG)
Passing instance variables to `render` is deprecated.
In Rails 7.1, #{deprecated_locals.to_sentence} will be ignored.
MSG
locals = locals.grep(/\A@?(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
else
locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
end

locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)

# Assign for the same variable is to suppress unused variable warning
locals.each_with_object(+"") { |key, code| code << "#{key} = local_assigns[:#{key}]; #{key} = #{key};" }
Expand Down

This file was deleted.

7 changes: 0 additions & 7 deletions actionview/test/template/compiled_templates_test.rb
Expand Up @@ -50,13 +50,6 @@ def test_template_with_unicode_identifier
assert_equal "🎂", render(template: "test/render_file_unicode_local", locals: { 🎃: "🎂" })
end

def test_template_with_instance_variable_identifier
expected_deprecation = "In Rails 7.1, @foo will be ignored."
assert_deprecated(expected_deprecation, ActionView.deprecator) do
assert_equal "bar", render(template: "test/render_file_instance_variable", locals: { "@foo": "bar" })
end
end

def test_template_gets_recompiled_when_using_different_keys_in_local_assigns
assert_equal "one", render(template: "test/render_file_with_locals_and_default")
assert_equal "two", render(template: "test/render_file_with_locals_and_default", locals: { secret: "two" })
Expand Down
2 changes: 2 additions & 0 deletions guides/source/7_1_release_notes.md
Expand Up @@ -75,6 +75,8 @@ Please refer to the [Changelog][action-view] for detailed changes.

* Remove deprecated constant `ActionView::Path`.

* Remove deprecated support to passing instance variables as locals to partials.

### Deprecations

### Notable changes
Expand Down

0 comments on commit 8241178

Please sign in to comment.