From 8ab37c76608d7105c47566e79b85fcf72cb11e4b Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Thu, 19 Mar 2009 13:35:39 -0700 Subject: Started implementing render :action --- .../happy_path/render_action/hello_world.erb | 1 + actionpack/test/new_base/render_action_test.rb | 75 +++++++++++++ .../test/new_base/render_implicit_action_test.rb | 16 +++ actionpack/test/new_base/render_template_test.rb | 56 ++++++++++ actionpack/test/new_base/render_test.rb | 124 --------------------- actionpack/test/new_base/render_text_test.rb | 71 ++++++++++++ 6 files changed, 219 insertions(+), 124 deletions(-) create mode 100644 actionpack/test/fixtures/happy_path/render_action/hello_world.erb create mode 100644 actionpack/test/new_base/render_action_test.rb create mode 100644 actionpack/test/new_base/render_implicit_action_test.rb create mode 100644 actionpack/test/new_base/render_template_test.rb delete mode 100644 actionpack/test/new_base/render_test.rb create mode 100644 actionpack/test/new_base/render_text_test.rb (limited to 'actionpack/test') diff --git a/actionpack/test/fixtures/happy_path/render_action/hello_world.erb b/actionpack/test/fixtures/happy_path/render_action/hello_world.erb new file mode 100644 index 0000000000..6769dd60bd --- /dev/null +++ b/actionpack/test/fixtures/happy_path/render_action/hello_world.erb @@ -0,0 +1 @@ +Hello world! \ 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 new file mode 100644 index 0000000000..b6e98f82aa --- /dev/null +++ b/actionpack/test/new_base/render_action_test.rb @@ -0,0 +1,75 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module HappyPath + + class RenderActionController < ActionController::Base2 + + def render_action_hello_world + render :action => "hello_world" + end + + def render_action_hello_world_as_string + render "hello_world" + end + + def render_action_hello_world_as_string_with_options + render "hello_world", :status => 404 + end + + def render_action_hello_world_as_symbol + render :hello_world + end + + def render_action_hello_world_with_symbol + render :action => :hello_world + end + + end + + class TestRenderAction < SimpleRouteCase + + describe "Rendering an action using :action => " + + get "/happy_path/render_action/render_action_hello_world" + assert_body "Hello world!" + assert_status 200 + + end + + class TestRenderActionWithString < SimpleRouteCase + + describe "Render an action using 'hello_world'" + + get "/happy_path/render_action/render_action_hello_world_as_string" + assert_body "Hello world!" + assert_status 200 + + end + + class TestRenderActionWithStringAndOptions < SimpleRouteCase + + describe "Render an action using 'hello_world'" + + get "/happy_path/render_action/render_action_hello_world_as_string_with_options" + assert_body "Hello world!" + assert_status 404 + + end + + class TestRenderActionAsSymbol < SimpleRouteCase + describe "Render an action using :hello_world" + + get "/happy_path/render_action/render_action_hello_world_as_symbol" + assert_body "Hello world!" + assert_status 200 + end + + class TestRenderActionWithSymbol < SimpleRouteCase + describe "Render an action using :action => :hello_world" + + get "/happy_path/render_action/render_action_hello_world_with_symbol" + assert_body "Hello world!" + assert_status 200 + end + +end \ No newline at end of file diff --git a/actionpack/test/new_base/render_implicit_action_test.rb b/actionpack/test/new_base/render_implicit_action_test.rb new file mode 100644 index 0000000000..798505b539 --- /dev/null +++ b/actionpack/test/new_base/render_implicit_action_test.rb @@ -0,0 +1,16 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module HappyPath + + class RenderImplicitActionController < ActionController::Base2 + # No actions yet, they are implicit + end + + class TestRendersActionImplicitly < SimpleRouteCase + + test "renders action implicitly" do + assert true + end + + end +end \ No newline at end of file diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb new file mode 100644 index 0000000000..758a206dbb --- /dev/null +++ b/actionpack/test/new_base/render_template_test.rb @@ -0,0 +1,56 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module HappyPath + + class RenderTemplateController < ActionController::Base2 + + def render_hello_world + render :template => "test/basic" + end + + def render_hello_world_with_forward_slash + render :template => "/test/basic" + end + + def render_template_in_top_directory + render :template => 'shared' + end + + def render_template_in_top_directory_with_slash + render :template => '/shared' + end + end + + class TestTemplateRender < SimpleRouteCase + describe "rendering a normal template with full path" + + get "/happy_path/render_template/render_hello_world" + assert_body "Hello from basic.html.erb" + assert_status 200 + end + + class TestTemplateRenderWithForwardSlash < SimpleRouteCase + describe "rendering a normal template with full path starting with a leading slash" + + get "/happy_path/render_template/render_hello_world_with_forward_slash" + assert_body "Hello from basic.html.erb" + assert_status 200 + end + + class TestTemplateRenderInTopDirectory < SimpleRouteCase + describe "rendering a template not in a subdirectory" + + get "/happy_path/render_template/render_template_in_top_directory" + assert_body "Elastica" + assert_status 200 + end + + class TestTemplateRenderInTopDirectoryWithSlash < SimpleRouteCase + describe "rendering a template not in a subdirectory with a leading slash" + + get "/happy_path/render_template/render_template_in_top_directory_with_slash" + assert_body "Elastica" + assert_status 200 + end + +end \ No newline at end of file diff --git a/actionpack/test/new_base/render_test.rb b/actionpack/test/new_base/render_test.rb deleted file mode 100644 index 2f43bc1fc6..0000000000 --- a/actionpack/test/new_base/render_test.rb +++ /dev/null @@ -1,124 +0,0 @@ -require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") - -module HappyPath - - class RenderTextController < ActionController::Base2 - def render_hello_world_from_variable - @person = "david" - render :text => "hello #{@person}" - end - - def render_custom_code - render :text => "hello world", :status => 404 - end - - def render_with_custom_code_as_string - render :text => "hello world", :status => "404 Not Found" - end - - def render_text_with_nil - render :text => nil - end - - def render_text_with_nil_and_status - render :text => nil, :status => 403 - end - - def render_text_with_false - render :text => false - end - end - - class TestSimpleTextRender < SimpleRouteCase - describe "Rendering text from a action with default options" - - get "/happy_path/render_text/render_hello_world_from_variable" - assert_body "hello david" - assert_status 200 - end - - class TestTextRenderWithStatus < SimpleRouteCase - describe "Rendering text, while also providing a custom status code" - - get "/happy_path/render_text/render_custom_code" - assert_body "hello world" - assert_status 404 - end - - class TestTextRenderWithNil < SimpleRouteCase - describe "Rendering text with nil returns a single space character" - - get "/happy_path/render_text/render_text_with_nil" - assert_body " " - assert_status 200 - end - - class TestTextRenderWithNilAndStatus < SimpleRouteCase - describe "Rendering text with nil and custom status code returns a single space character with the status" - - get "/happy_path/render_text/render_text_with_nil_and_status" - assert_body " " - assert_status 403 - end - - class TestTextRenderWithFalse < SimpleRouteCase - describe "Rendering text with false returns the string 'false'" - - get "/happy_path/render_text/render_text_with_false" - assert_body "false" - assert_status 200 - end - - class RenderTemplateController < ActionController::Base2 - - def render_hello_world - render :template => "test/basic" - end - - def render_hello_world_with_forward_slash - render :template => "/test/basic" - end - - def render_template_in_top_directory - render :template => 'shared' - end - - def render_template_in_top_directory_with_slash - render :template => '/shared' - end - end - - class TestTemplateRender < SimpleRouteCase - describe "rendering a normal template with full path" - - get "/happy_path/render_template/render_hello_world" - assert_body "Hello from basic.html.erb" - assert_status 200 - end - - class TestTemplateRenderWithForwardSlash < SimpleRouteCase - describe "rendering a normal template with full path starting with a leading slash" - - get "/happy_path/render_template/render_hello_world_with_forward_slash" - assert_body "Hello from basic.html.erb" - assert_status 200 - end - - class TestTemplateRenderInTopDirectory < SimpleRouteCase - describe "rendering a template not in a subdirectory" - - get "/happy_path/render_template/render_template_in_top_directory" - assert_body "Elastica" - assert_status 200 - end - - class TestTemplateRenderInTopDirectoryWithSlash < SimpleRouteCase - describe "rendering a template not in a subdirectory with a leading slash" - - get "/happy_path/render_template/render_template_in_top_directory_with_slash" - assert_body "Elastica" - assert_status 200 - end - - # TODO: Other language craziness -end \ No newline at end of file diff --git a/actionpack/test/new_base/render_text_test.rb b/actionpack/test/new_base/render_text_test.rb new file mode 100644 index 0000000000..f845b4c9cc --- /dev/null +++ b/actionpack/test/new_base/render_text_test.rb @@ -0,0 +1,71 @@ +require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper") + +module HappyPath + + class RenderTextController < ActionController::Base2 + def render_hello_world_from_variable + @person = "david" + render :text => "hello #{@person}" + end + + def render_custom_code + render :text => "hello world", :status => 404 + end + + def render_with_custom_code_as_string + render :text => "hello world", :status => "404 Not Found" + end + + def render_text_with_nil + render :text => nil + end + + def render_text_with_nil_and_status + render :text => nil, :status => 403 + end + + def render_text_with_false + render :text => false + end + end + + class TestSimpleTextRender < SimpleRouteCase + describe "Rendering text from a action with default options" + + get "/happy_path/render_text/render_hello_world_from_variable" + assert_body "hello david" + assert_status 200 + end + + class TestTextRenderWithStatus < SimpleRouteCase + describe "Rendering text, while also providing a custom status code" + + get "/happy_path/render_text/render_custom_code" + assert_body "hello world" + assert_status 404 + end + + class TestTextRenderWithNil < SimpleRouteCase + describe "Rendering text with nil returns a single space character" + + get "/happy_path/render_text/render_text_with_nil" + assert_body " " + assert_status 200 + end + + class TestTextRenderWithNilAndStatus < SimpleRouteCase + describe "Rendering text with nil and custom status code returns a single space character with the status" + + get "/happy_path/render_text/render_text_with_nil_and_status" + assert_body " " + assert_status 403 + end + + class TestTextRenderWithFalse < SimpleRouteCase + describe "Rendering text with false returns the string 'false'" + + get "/happy_path/render_text/render_text_with_false" + assert_body "false" + assert_status 200 + end +end \ No newline at end of file -- cgit v1.2.3