diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2019-02-25 15:14:53 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2019-02-25 15:14:53 -0800 |
commit | d4015a7f0609f12a5f7be4c794e5c5eaf2c748d5 (patch) | |
tree | e7dec5d02c596de76602c623032020cd7edeb27c /actionview/test | |
parent | a92e5eb4ae566b973ebb6fcf85d9d4d6e6fffcb0 (diff) | |
download | rails-d4015a7f0609f12a5f7be4c794e5c5eaf2c748d5.tar.gz rails-d4015a7f0609f12a5f7be4c794e5c5eaf2c748d5.tar.bz2 rails-d4015a7f0609f12a5f7be4c794e5c5eaf2c748d5.zip |
Pass locals in to the template object on construction
This commit ensures that locals are passed in to the template objects
when they are constructed, then removes the `locals=` mutator on the
template object. This means we don't need to mutate Template objects
with locals in the `decorate` method.
Diffstat (limited to 'actionview/test')
-rw-r--r-- | actionview/test/abstract_unit.rb | 2 | ||||
-rw-r--r-- | actionview/test/actionpack/controller/view_paths_test.rb | 5 | ||||
-rw-r--r-- | actionview/test/template/template_test.rb | 14 |
3 files changed, 10 insertions, 11 deletions
diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb index e0a1f59755..fe317bf39e 100644 --- a/actionview/test/abstract_unit.rb +++ b/actionview/test/abstract_unit.rb @@ -60,7 +60,7 @@ module RenderERBUtils string.strip, "test template", ActionView::Template.handler_for_extension(:erb), - format: :html) + format: :html, locals: []) view = ActionView::Base.with_empty_template_cache template.render(view.empty, {}).strip diff --git a/actionview/test/actionpack/controller/view_paths_test.rb b/actionview/test/actionpack/controller/view_paths_test.rb index a7a58a78cc..4449d08496 100644 --- a/actionview/test/actionpack/controller/view_paths_test.rb +++ b/actionview/test/actionpack/controller/view_paths_test.rb @@ -143,8 +143,9 @@ class ViewLoadPathsTest < ActionController::TestCase "Decorated body", template.identifier, template.handler, - virtual_path: template.virtual_path, - format: template.format + virtual_path: template.virtual_path, + format: template.format, + locals: template.locals ) end end diff --git a/actionview/test/template/template_test.rb b/actionview/test/template/template_test.rb index c74305fb42..5a24aea173 100644 --- a/actionview/test/template/template_test.rb +++ b/actionview/test/template/template_test.rb @@ -39,7 +39,8 @@ class TestERBTemplate < ActiveSupport::TestCase "partial", ERBHandler, virtual_path: "partial", - format: :html + format: :html, + locals: [] ) end @@ -57,7 +58,7 @@ class TestERBTemplate < ActiveSupport::TestCase end def new_template(body = "<%= hello %>", details = {}) - details = { format: :html }.merge details + details = { format: :html, locals: [] }.merge details ActionView::Template.new(body.dup, "hello template", details.fetch(:handler) { ERBHandler }, { virtual_path: "hello" }.merge!(details)) end @@ -103,8 +104,7 @@ class TestERBTemplate < ActiveSupport::TestCase end def test_locals - @template = new_template("<%= my_local %>") - @template.locals = [:my_local] + @template = new_template("<%= my_local %>", locals: [:my_local]) assert_equal "I am a local", render(my_local: "I am a local") end @@ -122,16 +122,14 @@ class TestERBTemplate < ActiveSupport::TestCase end def test_refresh_with_templates - @template = new_template("Hello", virtual_path: "test/foo/bar") - @template.locals = [:key] + @template = new_template("Hello", virtual_path: "test/foo/bar", locals: [:key]) assert_called_with(@context.lookup_context, :find_template, ["bar", %w(test/foo), false, [:key]], returns: "template") do assert_equal "template", @template.refresh(@context) end end def test_refresh_with_partials - @template = new_template("Hello", virtual_path: "test/_foo") - @template.locals = [:key] + @template = new_template("Hello", virtual_path: "test/_foo", locals: [:key]) assert_called_with(@context.lookup_context, :find_template, ["foo", %w(test), true, [:key]], returns: "partial") do assert_equal "partial", @template.refresh(@context) end |