From 692dbbf79387b56e241e1acd05f74f7d71ff79a6 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Wed, 6 Feb 2008 04:26:40 +0000 Subject: Introduce a Template class to ActionView. Closes #11024 [lifofifo] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8805 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/custom_handler_test.rb | 10 +++-- actionpack/test/controller/render_test.rb | 13 ------ .../test/template/compiled_templates_test.rb | 52 ++++++++++++---------- 3 files changed, 35 insertions(+), 40 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/custom_handler_test.rb b/actionpack/test/controller/custom_handler_test.rb index f3f2625daa..932b8c15c3 100644 --- a/actionpack/test/controller/custom_handler_test.rb +++ b/actionpack/test/controller/custom_handler_test.rb @@ -20,14 +20,17 @@ class CustomHandlerTest < Test::Unit::TestCase end def test_custom_render - result = @view.render_template( "foo", "hello <%= one %>", nil, :one => "two" ) + template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "foo") + + result = @view.render_template(template) assert_equal( [ "hello <%= one %>", { :one => "two" }, @view ], result ) end def test_custom_render2 - result = @view.render_template( "foo2", "hello <%= one %>", nil, :one => "two" ) + template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "foo2") + result = @view.render_template(template) assert_equal( [ "hello <%= one %>", { :one => "two" }, @view ], result ) @@ -35,7 +38,8 @@ class CustomHandlerTest < Test::Unit::TestCase def test_unhandled_extension # uses the ERb handler by default if the extension isn't recognized - result = @view.render_template( "bar", "hello <%= one %>", nil, :one => "two" ) + template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "bar") + result = @view.render_template(template) assert_equal "hello two", result end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 4768dffba2..01a7ad6eec 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -140,14 +140,6 @@ class TestController < ActionController::Base :locals => { :local_name => name } end - def accessing_local_assigns_in_inline_template_with_string_keys - name = params[:local_name] - ActionView::Base.local_assigns_support_string_keys = true - render :inline => "<%= 'Goodbye, ' + local_name %>", - :locals => { "local_name" => name } - ActionView::Base.local_assigns_support_string_keys = false - end - def formatted_html_erb end @@ -387,11 +379,6 @@ class RenderTest < Test::Unit::TestCase assert_equal "Goodbye, Local David", @response.body end - def test_accessing_local_assigns_in_inline_template_with_string_keys - get :accessing_local_assigns_in_inline_template_with_string_keys, :local_name => "Local David" - assert_equal "Goodbye, Local David", @response.body - end - def test_render_200_should_set_etag get :render_hello_world_from_variable assert_equal etag_for("hello david"), @response.headers['ETag'] diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb index c46eed0775..ad002e4cce 100644 --- a/actionpack/test/template/compiled_templates_test.rb +++ b/actionpack/test/template/compiled_templates_test.rb @@ -87,6 +87,10 @@ class CompiledTemplateTests < Test::Unit::TestCase v.base_path = '.' v.cache_template_loading = false + ta = ActionView::Template.new(v, @a, false, {}) + tb = ActionView::Template.new(v, @b, false, {}) + ts = ActionView::Template.new(v, @s, false, {}) + @handler_class = ActionView::Base.handler_class_for_extension(:rhtml) @handler = @handler_class.new(v) @@ -99,15 +103,15 @@ class CompiledTemplateTests < Test::Unit::TestCase assert @handler.send(:template_changed_since?, @b, t) assert @handler.send(:template_changed_since?, @s, t) unless windows - assert @handler.send(:compile_template?, nil, @a, {}) - assert @handler.send(:compile_template?, nil, @b, {}) - assert @handler.send(:compile_template?, nil, @s, {}) unless windows + assert @handler.send(:compile_template?, ta) + assert @handler.send(:compile_template?, tb) + assert @handler.send(:compile_template?, ts) unless windows # All templates are rendered at t+2 Time.expects(:now).times(windows ? 2 : 3).returns(t + 2.seconds) - v.send(:compile_and_render_template, @handler, '', @a) - v.send(:compile_and_render_template, @handler, '', @b) - v.send(:compile_and_render_template, @handler, '', @s) unless windows + v.send(:compile_and_render_template, @handler, ta) + v.send(:compile_and_render_template, @handler, tb) + v.send(:compile_and_render_template, @handler, ts) unless windows a_n = v.method_names[@a] b_n = v.method_names[@b] s_n = v.method_names[@s] unless windows @@ -122,12 +126,12 @@ class CompiledTemplateTests < Test::Unit::TestCase assert !@handler.send(:template_changed_since?, @a, @handler.compile_time[a_n]) assert !@handler.send(:template_changed_since?, @b, @handler.compile_time[b_n]) assert !@handler.send(:template_changed_since?, @s, @handler.compile_time[s_n]) unless windows - assert !@handler.send(:compile_template?, nil, @a, {}) - assert !@handler.send(:compile_template?, nil, @b, {}) - assert !@handler.send(:compile_template?, nil, @s, {}) unless windows - v.send(:compile_and_render_template, @handler, '', @a) - v.send(:compile_and_render_template, @handler, '', @b) - v.send(:compile_and_render_template, @handler, '', @s) unless windows + assert !@handler.send(:compile_template?, ta) + assert !@handler.send(:compile_template?, tb) + assert !@handler.send(:compile_template?, ts) unless windows + v.send(:compile_and_render_template, @handler, ta) + v.send(:compile_and_render_template, @handler, tb) + v.send(:compile_and_render_template, @handler, ts) unless windows # none of the files have changed since last compile assert @handler.compile_time[a_n] < t + 3.seconds assert @handler.compile_time[b_n] < t + 3.seconds @@ -144,15 +148,15 @@ class CompiledTemplateTests < Test::Unit::TestCase assert !@handler.send(:template_changed_since?, @a, @handler.compile_time[a_n]) assert !@handler.send(:template_changed_since?, @b, @handler.compile_time[b_n]) assert @handler.send(:template_changed_since?, @s, @handler.compile_time[s_n]) unless windows - assert !@handler.send(:compile_template?, nil, @a, {}) - assert !@handler.send(:compile_template?, nil, @b, {}) - assert @handler.send(:compile_template?, nil, @s, {}) unless windows + assert !@handler.send(:compile_template?, ta) + assert !@handler.send(:compile_template?, tb) + assert @handler.send(:compile_template?, ts) unless windows # Only the symlink template gets rendered at t+3 Time.stubs(:now).returns(t + 3.seconds) unless windows - v.send(:compile_and_render_template, @handler, '', @a) - v.send(:compile_and_render_template, @handler, '', @b) - v.send(:compile_and_render_template, @handler, '', @s) unless windows + v.send(:compile_and_render_template, @handler, ta) + v.send(:compile_and_render_template, @handler, tb) + v.send(:compile_and_render_template, @handler, ts) unless windows # the symlink has changed since last compile assert @handler.compile_time[a_n] < t + 3.seconds assert @handler.compile_time[b_n] < t + 3.seconds @@ -170,14 +174,14 @@ class CompiledTemplateTests < Test::Unit::TestCase assert !@handler.send(:template_changed_since?, @a, @handler.compile_time[a_n]) assert @handler.send(:template_changed_since?, @b, @handler.compile_time[b_n]) assert @handler.send(:template_changed_since?, @s, @handler.compile_time[s_n]) unless windows - assert !@handler.send(:compile_template?, nil, @a, {}) - assert @handler.send(:compile_template?, nil, @b, {}) - assert @handler.send(:compile_template?, nil, @s, {}) unless windows + assert !@handler.send(:compile_template?, ta) + assert @handler.send(:compile_template?, tb) + assert @handler.send(:compile_template?, ts) unless windows Time.expects(:now).times(windows ? 1 : 2).returns(t + 5.seconds) - v.send(:compile_and_render_template, @handler, '', @a) - v.send(:compile_and_render_template, @handler, '', @b) - v.send(:compile_and_render_template, @handler, '', @s) unless windows + v.send(:compile_and_render_template, @handler, ta) + v.send(:compile_and_render_template, @handler, tb) + v.send(:compile_and_render_template, @handler, ts) unless windows # the file at the end of the symlink has changed since last compile # both the symlink and the file at the end of it should be recompiled assert @handler.compile_time[a_n] < t + 5.seconds -- cgit v1.2.3