From 90c079a7814a9a996c8cbe353015c080fafce2bc Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 20 Mar 2009 14:43:19 -0700 Subject: Modified the action layout tests to use the new FixtureTemplate class --- actionpack/test/new_base/fixture_view_path_test.rb | 55 ++++++++++++++++------ actionpack/test/new_base/render_action_test.rb | 17 +++++-- actionpack/test/new_base/test_helper.rb | 36 ++++++++++++++ .../render_action_with_layout/hello_world.html.erb | 1 - .../layouts/application.html.erb | 1 - .../hello_world.html.erb | 1 - .../with_both_layouts/layouts/application.html.erb | 1 - ...er_action_with_controller_layout_first.html.erb | 1 - .../hello_world.html.erb | 1 - .../render_action_with_controller_layout.html.erb | 1 - 10 files changed, 89 insertions(+), 26 deletions(-) delete mode 100644 actionpack/test/new_base/views/with_application_layout/happy_path/render_action_with_layout/hello_world.html.erb delete mode 100644 actionpack/test/new_base/views/with_application_layout/layouts/application.html.erb delete mode 100644 actionpack/test/new_base/views/with_both_layouts/happy_path/render_action_with_controller_layout_first/hello_world.html.erb delete mode 100644 actionpack/test/new_base/views/with_both_layouts/layouts/application.html.erb delete mode 100644 actionpack/test/new_base/views/with_both_layouts/layouts/happy_path/render_action_with_controller_layout_first.html.erb delete mode 100644 actionpack/test/new_base/views/with_controller_layout/happy_path/render_action_with_controller_layout/hello_world.html.erb delete mode 100644 actionpack/test/new_base/views/with_controller_layout/layouts/happy_path/render_action_with_controller_layout.html.erb (limited to 'actionpack') diff --git a/actionpack/test/new_base/fixture_view_path_test.rb b/actionpack/test/new_base/fixture_view_path_test.rb index 482607474f..e350de9d45 100644 --- a/actionpack/test/new_base/fixture_view_path_test.rb +++ b/actionpack/test/new_base/fixture_view_path_test.rb @@ -18,30 +18,28 @@ module ActionView #:nodoc: end end - def initialize(body, template_path, load_paths = []) + def initialize(body, *args) @body = body - end - - def relative_path - "fail" - end - - def filename - "fail" - end - - def method_name_without_locals - "abc" + super(*args) end def source @body end + + private + + def find_full_path(path, load_paths) + return '/', path + end + end end OMG = { - "happy_path/render_action/hello_world.html.erb" => "Hello world!" + "happy_path/render_action/hello_world.html.erb" => "Hello world!", + "happy_path/render_action/goodbye_world.html.erb" => "Goodbye world!", + "happy_path/sexy_time/borat.html.erb" => "I LIKE!!!" } module HappyPath @@ -55,9 +53,21 @@ module HappyPath render :action => "hello_world" end + def render_action_goodbye_world + render :action => "goodbye_world" + end + end - class TestRenderAction < SimpleRouteCase + class SexyTimeController < ActionController::Base2 + self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(OMG)] + + def borat + render "borat" + end + end + + class TestRenderHelloAction < SimpleRouteCase describe "Rendering an action using :action => " @@ -66,4 +76,19 @@ module HappyPath assert_status 200 end + + class TestRenderGoodbyeAction < SimpleRouteCase + describe "Goodbye" + + get "/happy_path/render_action/render_action_goodbye_world" + assert_body "Goodbye world!" + assert_status 200 + end + + class TestRenderBorat < SimpleRouteCase + describe "Borat yo" + get "/happy_path/sexy_time/borat" + assert_body "I LIKE!!!" + assert_status 200 + end end \ No newline at end of file diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb index 188fb44265..a5ad78be75 100644 --- a/actionpack/test/new_base/render_action_test.rb +++ b/actionpack/test/new_base/render_action_test.rb @@ -77,7 +77,10 @@ module HappyPath class RenderActionWithLayoutController < ActionController::Base2 # Set the view path to an application view structure with layouts - self.view_paths = [File.join(File.dirname(__FILE__), 'views', 'with_application_layout')] + self.view_paths = self.view_paths = [ActionView::FixtureTemplate::FixturePath.new({ + "happy_path/render_action_with_layout/hello_world.html.erb" => "Hello World!", + "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI" + })] def hello_world render :action => "hello_world" @@ -85,7 +88,10 @@ module HappyPath end class RenderActionWithControllerLayoutController < ActionController::Base2 - self.view_paths = [File.join(File.dirname(__FILE__), 'views', 'with_controller_layout')] + self.view_paths = self.view_paths = [ActionView::FixtureTemplate::FixturePath.new({ + "happy_path/render_action_with_controller_layout/hello_world.html.erb" => "Hello World!", + "layouts/happy_path/render_action_with_controller_layout.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI" + })] def hello_world render :action => "hello_world" @@ -93,7 +99,11 @@ module HappyPath end class RenderActionWithControllerLayoutFirstController < ActionController::Base2 - self.view_paths = [File.join(File.dirname(__FILE__), 'views', 'with_both_layouts')] + self.view_paths = self.view_paths = [ActionView::FixtureTemplate::FixturePath.new({ + "happy_path/render_action_with_controller_layout_first/hello_world.html.erb" => "Hello World!", + "layouts/application.html.erb" => "OHAI <%= yield %> KTHXBAI", + "layouts/happy_path/render_action_with_controller_layout_first.html.erb" => "With Controller Layout! <%= yield %> KTHXBAI" + })] def hello_world render :action => "hello_world" @@ -127,5 +137,4 @@ module HappyPath assert_status 200 end - # TODO: Implement a FixtureViewPath end \ No newline at end of file diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb index af790aa5dd..affb52a432 100644 --- a/actionpack/test/new_base/test_helper.rb +++ b/actionpack/test/new_base/test_helper.rb @@ -50,6 +50,42 @@ module ActionController end end +module ActionView #:nodoc: + class FixtureTemplate < Template + class FixturePath < Template::Path + def initialize(hash) + @hash = {} + + hash.each do |k, v| + @hash[k.sub(/\.\w+$/, '')] = FixtureTemplate.new(v, k.split("/").last, self) + end + + super("") + end + + def find_template(path) + @hash[path] + end + end + + def initialize(body, *args) + @body = body + super(*args) + end + + def source + @body + end + + private + + def find_full_path(path, load_paths) + return '/', path + end + + end +end + # Temporary base class class Rack::TestCase < ActiveSupport::TestCase include Rack::Test::Methods diff --git a/actionpack/test/new_base/views/with_application_layout/happy_path/render_action_with_layout/hello_world.html.erb b/actionpack/test/new_base/views/with_application_layout/happy_path/render_action_with_layout/hello_world.html.erb deleted file mode 100644 index c57eff55eb..0000000000 --- a/actionpack/test/new_base/views/with_application_layout/happy_path/render_action_with_layout/hello_world.html.erb +++ /dev/null @@ -1 +0,0 @@ -Hello World! \ No newline at end of file diff --git a/actionpack/test/new_base/views/with_application_layout/layouts/application.html.erb b/actionpack/test/new_base/views/with_application_layout/layouts/application.html.erb deleted file mode 100644 index 25f839fded..0000000000 --- a/actionpack/test/new_base/views/with_application_layout/layouts/application.html.erb +++ /dev/null @@ -1 +0,0 @@ -OHAI <%= yield %> KTHXBAI \ No newline at end of file diff --git a/actionpack/test/new_base/views/with_both_layouts/happy_path/render_action_with_controller_layout_first/hello_world.html.erb b/actionpack/test/new_base/views/with_both_layouts/happy_path/render_action_with_controller_layout_first/hello_world.html.erb deleted file mode 100644 index c57eff55eb..0000000000 --- a/actionpack/test/new_base/views/with_both_layouts/happy_path/render_action_with_controller_layout_first/hello_world.html.erb +++ /dev/null @@ -1 +0,0 @@ -Hello World! \ No newline at end of file diff --git a/actionpack/test/new_base/views/with_both_layouts/layouts/application.html.erb b/actionpack/test/new_base/views/with_both_layouts/layouts/application.html.erb deleted file mode 100644 index 25f839fded..0000000000 --- a/actionpack/test/new_base/views/with_both_layouts/layouts/application.html.erb +++ /dev/null @@ -1 +0,0 @@ -OHAI <%= yield %> KTHXBAI \ No newline at end of file diff --git a/actionpack/test/new_base/views/with_both_layouts/layouts/happy_path/render_action_with_controller_layout_first.html.erb b/actionpack/test/new_base/views/with_both_layouts/layouts/happy_path/render_action_with_controller_layout_first.html.erb deleted file mode 100644 index 43d89fde52..0000000000 --- a/actionpack/test/new_base/views/with_both_layouts/layouts/happy_path/render_action_with_controller_layout_first.html.erb +++ /dev/null @@ -1 +0,0 @@ -With Controller Layout! <%= yield %> KTHXBAI \ No newline at end of file diff --git a/actionpack/test/new_base/views/with_controller_layout/happy_path/render_action_with_controller_layout/hello_world.html.erb b/actionpack/test/new_base/views/with_controller_layout/happy_path/render_action_with_controller_layout/hello_world.html.erb deleted file mode 100644 index c57eff55eb..0000000000 --- a/actionpack/test/new_base/views/with_controller_layout/happy_path/render_action_with_controller_layout/hello_world.html.erb +++ /dev/null @@ -1 +0,0 @@ -Hello World! \ No newline at end of file diff --git a/actionpack/test/new_base/views/with_controller_layout/layouts/happy_path/render_action_with_controller_layout.html.erb b/actionpack/test/new_base/views/with_controller_layout/layouts/happy_path/render_action_with_controller_layout.html.erb deleted file mode 100644 index 43d89fde52..0000000000 --- a/actionpack/test/new_base/views/with_controller_layout/layouts/happy_path/render_action_with_controller_layout.html.erb +++ /dev/null @@ -1 +0,0 @@ -With Controller Layout! <%= yield %> KTHXBAI \ No newline at end of file -- cgit v1.2.3