From 130fe74d17404e5c06353526c7b20beb4019cb69 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 19 Nov 2008 14:00:16 +0100 Subject: Changed the default of ActionView#render to assume partials instead of files when not given an options hash [DHH] --- actionpack/test/template/render_test.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'actionpack/test/template/render_test.rb') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 476e651757..0323c33b95 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -8,7 +8,7 @@ class ViewRenderTest < Test::Unit::TestCase end def test_render_file - assert_equal "Hello world!", @view.render("test/hello_world.erb") + assert_equal "Hello world!", @view.render(:file => "test/hello_world.erb") end def test_render_file_not_using_full_path @@ -16,11 +16,11 @@ class ViewRenderTest < Test::Unit::TestCase end def test_render_file_without_specific_extension - assert_equal "Hello world!", @view.render("test/hello_world") + assert_equal "Hello world!", @view.render(:file => "test/hello_world") end def test_render_file_at_top_level - assert_equal 'Elastica', @view.render('/shared') + assert_equal 'Elastica', @view.render(:file => '/shared') end def test_render_file_with_full_path @@ -29,20 +29,20 @@ class ViewRenderTest < Test::Unit::TestCase end def test_render_file_with_instance_variables - assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_ivar.erb") + assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_ivar.erb") end def test_render_file_with_locals locals = { :secret => 'in the sauce' } - assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_locals.erb", locals) + assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_locals.erb", :locals => locals) end def test_render_file_not_using_full_path_with_dot_in_path - assert_equal "The secret is in the sauce\n", @view.render("test/dot.directory/render_file_with_ivar") + assert_equal "The secret is in the sauce\n", @view.render(:file => "test/dot.directory/render_file_with_ivar") end def test_render_has_access_current_template - assert_equal "test/template.erb", @view.render("test/template.erb") + assert_equal "test/template.erb", @view.render(:file => "test/template.erb") end def test_render_update @@ -51,6 +51,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal 'alert("Hello, World!");', @view.render(:update) { |page| page.alert('Hello, World!') } end + def test_render_partial_from_default + assert_equal "only partial", @view.render("test/partial_only") + end + def test_render_partial assert_equal "only partial", @view.render(:partial => "test/partial_only") end @@ -73,6 +77,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 }) end + def test_render_partial_with_locals_from_default + assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5) + end + def test_render_partial_with_errors @view.render(:partial => "test/raise") flunk "Render did not raise TemplateError" -- cgit v1.2.3 From bc4d05b244c78f03ade51d8b95f16dd48ceb63d3 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 23 Nov 2008 13:57:01 -0600 Subject: A back support for legacy TemplateHandler#render API --- actionpack/test/template/render_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test/template/render_test.rb') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 0323c33b95..b316d5c23e 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -175,6 +175,17 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) end + class LegacyHandler < ActionView::TemplateHandler + def render(template, local_assigns) + "source: #{template.source}; locals: #{local_assigns.inspect}" + end + end + + def test_render_legacy_handler_with_custom_type + ActionView::Template.register_template_handler :foo, LegacyHandler + assert_equal 'source: Hello, <%= name %>!; locals: {:name=>"Josh"}', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) + end + def test_render_with_layout assert_equal %(\nHello world!\n), @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield") -- cgit v1.2.3 From 4d910b033379727e5e7355590c50c72fc75e56db Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 26 Nov 2008 20:54:47 -0600 Subject: Super lazy load view paths in development mode (no indexing or caching at all). Switch layout finders to use view path api to take advantage of cache. --- actionpack/test/template/render_test.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'actionpack/test/template/render_test.rb') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index b316d5c23e..28d38b0c76 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -4,7 +4,9 @@ require 'controller/fake_models' class ViewRenderTest < Test::Unit::TestCase def setup @assigns = { :secret => 'in the sauce' } - @view = ActionView::Base.new(ActionController::Base.view_paths, @assigns) + view_paths = ActionController::Base.view_paths + @view = ActionView::Base.new(view_paths, @assigns) + assert view_paths.first.loaded? end def test_render_file @@ -157,7 +159,7 @@ class ViewRenderTest < Test::Unit::TestCase end def test_render_fallbacks_to_erb_for_unknown_types - assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :foo) + assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :bar) end CustomHandler = lambda do |template| @@ -196,3 +198,14 @@ class ViewRenderTest < Test::Unit::TestCase @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield") end end + +class LazyViewRenderTest < ViewRenderTest + # Test the same thing as above, but make sure the view path + # is not eager loaded + def setup + @assigns = { :secret => 'in the sauce' } + view_paths = ActionView::Base.process_view_paths(FIXTURE_LOAD_PATH) + @view = ActionView::Base.new(view_paths, @assigns) + assert !view_paths.first.loaded? + end +end -- cgit v1.2.3 From 5fa0457542b0ff541d0a80ff8c3561eec8e35959 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 27 Nov 2008 21:04:24 +0100 Subject: Revert "Super lazy load view paths in development mode (no indexing or caching at all). Switch layout finders to use view path api to take advantage of cache." as it killed dev mode reloading. This reverts commit 4d910b033379727e5e7355590c50c72fc75e56db. --- actionpack/test/template/render_test.rb | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'actionpack/test/template/render_test.rb') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 28d38b0c76..b316d5c23e 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -4,9 +4,7 @@ require 'controller/fake_models' class ViewRenderTest < Test::Unit::TestCase def setup @assigns = { :secret => 'in the sauce' } - view_paths = ActionController::Base.view_paths - @view = ActionView::Base.new(view_paths, @assigns) - assert view_paths.first.loaded? + @view = ActionView::Base.new(ActionController::Base.view_paths, @assigns) end def test_render_file @@ -159,7 +157,7 @@ class ViewRenderTest < Test::Unit::TestCase end def test_render_fallbacks_to_erb_for_unknown_types - assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :bar) + assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :foo) end CustomHandler = lambda do |template| @@ -198,14 +196,3 @@ class ViewRenderTest < Test::Unit::TestCase @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield") end end - -class LazyViewRenderTest < ViewRenderTest - # Test the same thing as above, but make sure the view path - # is not eager loaded - def setup - @assigns = { :secret => 'in the sauce' } - view_paths = ActionView::Base.process_view_paths(FIXTURE_LOAD_PATH) - @view = ActionView::Base.new(view_paths, @assigns) - assert !view_paths.first.loaded? - end -end -- cgit v1.2.3 From 9fc23745f1511d8d97433828d9ca87970994d138 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 28 Nov 2008 11:18:28 -0600 Subject: Reinstate "Super lazy load view paths in development mode (no indexing or caching at all). Switch layout finders to use view path api to take advantage of cache." as it killed dev mode reloading." --- actionpack/test/template/render_test.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'actionpack/test/template/render_test.rb') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index b316d5c23e..28d38b0c76 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -4,7 +4,9 @@ require 'controller/fake_models' class ViewRenderTest < Test::Unit::TestCase def setup @assigns = { :secret => 'in the sauce' } - @view = ActionView::Base.new(ActionController::Base.view_paths, @assigns) + view_paths = ActionController::Base.view_paths + @view = ActionView::Base.new(view_paths, @assigns) + assert view_paths.first.loaded? end def test_render_file @@ -157,7 +159,7 @@ class ViewRenderTest < Test::Unit::TestCase end def test_render_fallbacks_to_erb_for_unknown_types - assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :foo) + assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :bar) end CustomHandler = lambda do |template| @@ -196,3 +198,14 @@ class ViewRenderTest < Test::Unit::TestCase @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield") end end + +class LazyViewRenderTest < ViewRenderTest + # Test the same thing as above, but make sure the view path + # is not eager loaded + def setup + @assigns = { :secret => 'in the sauce' } + view_paths = ActionView::Base.process_view_paths(FIXTURE_LOAD_PATH) + @view = ActionView::Base.new(view_paths, @assigns) + assert !view_paths.first.loaded? + end +end -- cgit v1.2.3 From 9fccf72725a72baeda508eccd6113b44329e0a7c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 28 Nov 2008 14:31:54 -0600 Subject: fixed template recompile issue with previous commit and add some better tests so we can make sure it doesn't happen again --- actionpack/test/template/render_test.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'actionpack/test/template/render_test.rb') diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 28d38b0c76..9e827abbca 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -1,12 +1,10 @@ require 'abstract_unit' require 'controller/fake_models' -class ViewRenderTest < Test::Unit::TestCase - def setup +module RenderTestCases + def setup_view(paths) @assigns = { :secret => 'in the sauce' } - view_paths = ActionController::Base.view_paths - @view = ActionView::Base.new(view_paths, @assigns) - assert view_paths.first.loaded? + @view = ActionView::Base.new(paths, @assigns) end def test_render_file @@ -199,13 +197,25 @@ class ViewRenderTest < Test::Unit::TestCase end end -class LazyViewRenderTest < ViewRenderTest +class CachedViewRenderTest < Test::Unit::TestCase + include RenderTestCases + + # Ensure view path cache is primed + def setup + view_paths = ActionController::Base.view_paths + assert view_paths.first.loaded? + setup_view(view_paths) + end +end + +class LazyViewRenderTest < Test::Unit::TestCase + include RenderTestCases + # Test the same thing as above, but make sure the view path # is not eager loaded def setup - @assigns = { :secret => 'in the sauce' } view_paths = ActionView::Base.process_view_paths(FIXTURE_LOAD_PATH) - @view = ActionView::Base.new(view_paths, @assigns) assert !view_paths.first.loaded? + setup_view(view_paths) end end -- cgit v1.2.3