diff options
author | Aaron Patterson <tenderlove@github.com> | 2019-02-26 11:03:46 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-26 11:03:46 -0800 |
commit | 383efb0138a8e8b69c85d787fae5fc28e214e6a3 (patch) | |
tree | ff71d847c92f379b08796189559ddae7621669b1 /actionview/test/template | |
parent | d333d85254d27cd572e6ecce8ee850c107a4f340 (diff) | |
parent | 082130d1d43620ca29c2f2f169a5059fa0065a8c (diff) | |
download | rails-383efb0138a8e8b69c85d787fae5fc28e214e6a3.tar.gz rails-383efb0138a8e8b69c85d787fae5fc28e214e6a3.tar.bz2 rails-383efb0138a8e8b69c85d787fae5fc28e214e6a3.zip |
Merge pull request #35411 from rails/pass-locals-to-template
Pass locals in to the template object on construction
Diffstat (limited to 'actionview/test/template')
-rw-r--r-- | actionview/test/template/template_test.rb | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/actionview/test/template/template_test.rb b/actionview/test/template/template_test.rb index c74305fb42..71fb99115b 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,8 +58,8 @@ class TestERBTemplate < ActiveSupport::TestCase end def new_template(body = "<%= hello %>", details = {}) - details = { format: :html }.merge details - ActionView::Template.new(body.dup, "hello template", details.fetch(:handler) { ERBHandler }, { virtual_path: "hello" }.merge!(details)) + details = { format: :html, locals: [] }.merge details + ActionView::Template.new(body.dup, "hello template", details.delete(:handler) || ERBHandler, { virtual_path: "hello" }.merge!(details)) end def render(locals = {}) @@ -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 |