aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2009-03-20 18:38:03 -0700
committerYehuda Katz <wycats@gmail.com>2009-03-23 10:23:14 -0700
commitab17ecfe5d97d5026d67688ddefe11a458701076 (patch)
tree1aa5e9ba238e0b9a2cc9e7bfc19a750ebc5ebd0b
parentc6123c37030b715d088860ea1ca79060659b0e3c (diff)
downloadrails-ab17ecfe5d97d5026d67688ddefe11a458701076.tar.gz
rails-ab17ecfe5d97d5026d67688ddefe11a458701076.tar.bz2
rails-ab17ecfe5d97d5026d67688ddefe11a458701076.zip
Finished implementing :layout for most of the render options
-rw-r--r--actionpack/test/new_base/fixture_view_path_test.rb64
-rw-r--r--actionpack/test/new_base/render_action_test.rb10
-rw-r--r--actionpack/test/new_base/render_template_test.rb91
-rw-r--r--actionpack/test/new_base/render_text_test.rb38
-rw-r--r--actionpack/test/new_base/test_helper.rb4
5 files changed, 132 insertions, 75 deletions
diff --git a/actionpack/test/new_base/fixture_view_path_test.rb b/actionpack/test/new_base/fixture_view_path_test.rb
index e350de9d45..7792a14a20 100644
--- a/actionpack/test/new_base/fixture_view_path_test.rb
+++ b/actionpack/test/new_base/fixture_view_path_test.rb
@@ -1,53 +1,15 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
-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
-
-OMG = {
- "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
# This has no layout and it works
- class RenderActionController < ActionController::Base2
+ class RenderActionLolController < ActionController::Base2
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(OMG)]
+ self.view_paths = [ActionView::FixtureTemplate::FixturePath.new({
+ "happy_path/render_action_lol/hello_world.html.erb" => "Hello world!",
+ "happy_path/render_action_lol/goodbye_world.html.erb" => "Goodbye world!",
+ "happy_path/sexy_time/borat.html.erb" => "I LIKE!!!"
+ })]
def render_action_hello_world
render :action => "hello_world"
@@ -60,7 +22,11 @@ module HappyPath
end
class SexyTimeController < ActionController::Base2
- self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(OMG)]
+ self.view_paths = [ActionView::FixtureTemplate::FixturePath.new({
+ "happy_path/render_action_lol/hello_world.html.erb" => "Hello world!",
+ "happy_path/render_action_lol/goodbye_world.html.erb" => "Goodbye world!",
+ "happy_path/sexy_time/borat.html.erb" => "I LIKE!!!"
+ })]
def borat
render "borat"
@@ -68,19 +34,19 @@ module HappyPath
end
class TestRenderHelloAction < SimpleRouteCase
-
+
describe "Rendering an action using :action => <String>"
-
+
get "/happy_path/render_action/render_action_hello_world"
assert_body "Hello world!"
assert_status 200
-
+
end
class TestRenderGoodbyeAction < SimpleRouteCase
describe "Goodbye"
- get "/happy_path/render_action/render_action_goodbye_world"
+ get "/happy_path/render_action_lol/render_action_goodbye_world"
assert_body "Goodbye world!"
assert_status 200
end
diff --git a/actionpack/test/new_base/render_action_test.rb b/actionpack/test/new_base/render_action_test.rb
index a5ad78be75..99dbfb878b 100644
--- a/actionpack/test/new_base/render_action_test.rb
+++ b/actionpack/test/new_base/render_action_test.rb
@@ -5,6 +5,10 @@ module HappyPath
# This has no layout and it works
class RenderActionController < ActionController::Base2
+ self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ "happy_path/render_action/hello_world.html.erb" => "Hello world!"
+ )]
+
def render_action_hello_world
render :action => "hello_world"
end
@@ -28,33 +32,27 @@ module HappyPath
end
class TestRenderAction < SimpleRouteCase
-
describe "Rendering an action using :action => <String>"
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
diff --git a/actionpack/test/new_base/render_template_test.rb b/actionpack/test/new_base/render_template_test.rb
index 758a206dbb..273e26b83f 100644
--- a/actionpack/test/new_base/render_template_test.rb
+++ b/actionpack/test/new_base/render_template_test.rb
@@ -2,7 +2,12 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
module HappyPath
- class RenderTemplateController < ActionController::Base2
+ class RenderTemplateWithoutLayoutController < ActionController::Base2
+
+ self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ "test/basic.html.erb" => "Hello from basic.html.erb",
+ "shared.html.erb" => "Elastica"
+ )]
def render_hello_world
render :template => "test/basic"
@@ -21,10 +26,10 @@ module HappyPath
end
end
- class TestTemplateRender < SimpleRouteCase
- describe "rendering a normal template with full path"
+ class TestTemplateRenderWithoutLayout < SimpleRouteCase
+ describe "rendering a normal template with full path without layout"
- get "/happy_path/render_template/render_hello_world"
+ get "/happy_path/render_template_without_layout/render_hello_world"
assert_body "Hello from basic.html.erb"
assert_status 200
end
@@ -32,7 +37,7 @@ module HappyPath
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"
+ get "/happy_path/render_template_without_layout/render_hello_world_with_forward_slash"
assert_body "Hello from basic.html.erb"
assert_status 200
end
@@ -40,7 +45,7 @@ module HappyPath
class TestTemplateRenderInTopDirectory < SimpleRouteCase
describe "rendering a template not in a subdirectory"
- get "/happy_path/render_template/render_template_in_top_directory"
+ get "/happy_path/render_template_without_layout/render_template_in_top_directory"
assert_body "Elastica"
assert_status 200
end
@@ -48,9 +53,81 @@ module HappyPath
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"
+ get "/happy_path/render_template_without_layout/render_template_in_top_directory_with_slash"
assert_body "Elastica"
assert_status 200
end
+
+ class RenderTemplateWithLayoutController < ActionController::Base2
+
+ self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
+ "test/basic.html.erb" => "Hello from basic.html.erb",
+ "shared.html.erb" => "Elastica",
+ "layouts/application.html.erb" => "<%= yield %>, I'm here!",
+ "layouts/greetings.html.erb" => "<%= yield %>, I wish thee well."
+ )]
+
+ def render_hello_world
+ render :template => "test/basic"
+ end
+
+ def render_hello_world_with_layout
+ render :template => "test/basic", :layout => true
+ end
+
+ def render_hello_world_with_layout_false
+ render :template => "test/basic", :layout => false
+ end
+
+ def render_hello_world_with_layout_nil
+ render :template => "test/basic", :layout => nil
+ end
+
+ def render_hello_world_with_custom_layout
+ render :template => "test/basic", :layout => "greetings"
+ end
+ end
+
+ class TestTemplateRenderWithLayout < SimpleRouteCase
+ describe "rendering a normal template with full path with layout"
+
+ get "/happy_path/render_template_with_layout/render_hello_world"
+ assert_body "Hello from basic.html.erb, I'm here!"
+ assert_status 200
+ end
+
+ class TestTemplateRenderWithLayoutTrue < SimpleRouteCase
+ describe "rendering a normal template with full path with layout => :true"
+
+ get "/happy_path/render_template_with_layout/render_hello_world_with_layout"
+ assert_body "Hello from basic.html.erb, I'm here!"
+ assert_status 200
+ end
+
+ class TestTemplateRenderWithLayoutFalse < SimpleRouteCase
+ describe "rendering a normal template with full path with layout => :false"
+
+ get "/happy_path/render_template_with_layout/render_hello_world_with_layout_false"
+ assert_body "Hello from basic.html.erb"
+ assert_status 200
+ end
+
+ class TestTemplateRenderWithLayoutNil < SimpleRouteCase
+ describe "rendering a normal template with full path with layout => :nil"
+
+ get "/happy_path/render_template_with_layout/render_hello_world_with_layout_nil"
+ assert_body "Hello from basic.html.erb"
+ assert_status 200
+ end
+
+ class TestTemplateRenderWithCustomLayout < SimpleRouteCase
+ describe "rendering a normal template with full path with layout => 'greetings'"
+
+ get "/happy_path/render_template_with_layout/render_hello_world_with_custom_layout"
+ assert_body "Hello from basic.html.erb, I wish thee well."
+ assert_status 200
+ end
+
+
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
index f91e6bd644..b80a9b4a79 100644
--- a/actionpack/test/new_base/render_text_test.rb
+++ b/actionpack/test/new_base/render_text_test.rb
@@ -2,7 +2,15 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
module HappyPath
- class RenderTextController < ActionController::Base2
+ class RenderTextWithoutLayoutsController < ActionController::Base2
+ self.view_paths = [ActionView::FixtureTemplate::FixturePath.new]
+
+ def render_hello_world
+ render :text => "hello david"
+ end
+ end
+
+ class RenderTextWithLayoutsController < ActionController::Base2
self.view_paths = [ActionView::FixtureTemplate::FixturePath.new(
"layouts/application.html.erb" => "<%= yield %>, I'm here!",
"layouts/greetings.html.erb" => "<%= yield %>, I wish thee well."
@@ -49,10 +57,18 @@ module HappyPath
end
end
- class TestSimpleTextRender < SimpleRouteCase
+ class TestSimpleTextRenderWithNoLayout < SimpleRouteCase
+ describe "Rendering text from a action with default options renders the text with the layout"
+
+ get "/happy_path/render_text_without_layouts/render_hello_world"
+ assert_body "hello david"
+ assert_status 200
+ end
+
+ class TestSimpleTextRenderWithLayout < SimpleRouteCase
describe "Rendering text from a action with default options renders the text without the layout"
- get "/happy_path/render_text/render_hello_world"
+ get "/happy_path/render_text_with_layouts/render_hello_world"
assert_body "hello david"
assert_status 200
end
@@ -60,7 +76,7 @@ module HappyPath
class TestTextRenderWithStatus < SimpleRouteCase
describe "Rendering text, while also providing a custom status code"
- get "/happy_path/render_text/render_custom_code"
+ get "/happy_path/render_text_with_layouts/render_custom_code"
assert_body "hello world"
assert_status 404
end
@@ -68,7 +84,7 @@ module HappyPath
class TestTextRenderWithNil < SimpleRouteCase
describe "Rendering text with nil returns a single space character"
- get "/happy_path/render_text/render_text_with_nil"
+ get "/happy_path/render_text_with_layouts/render_text_with_nil"
assert_body " "
assert_status 200
end
@@ -76,7 +92,7 @@ module HappyPath
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"
+ get "/happy_path/render_text_with_layouts/render_text_with_nil_and_status"
assert_body " "
assert_status 403
end
@@ -84,7 +100,7 @@ module HappyPath
class TestTextRenderWithFalse < SimpleRouteCase
describe "Rendering text with false returns the string 'false'"
- get "/happy_path/render_text/render_text_with_false"
+ get "/happy_path/render_text_with_layouts/render_text_with_false"
assert_body "false"
assert_status 200
end
@@ -92,7 +108,7 @@ module HappyPath
class TestTextRenderWithLayoutTrue < SimpleRouteCase
describe "Rendering text with :layout => true"
- get "/happy_path/render_text/render_text_with_layout"
+ get "/happy_path/render_text_with_layouts/render_text_with_layout"
assert_body "hello world, I'm here!"
assert_status 200
end
@@ -100,7 +116,7 @@ module HappyPath
class TestTextRenderWithCustomLayout < SimpleRouteCase
describe "Rendering text with :layout => 'greetings'"
- get "/happy_path/render_text/render_text_with_custom_layout"
+ get "/happy_path/render_text_with_layouts/render_text_with_custom_layout"
assert_body "hello world, I wish thee well."
assert_status 200
end
@@ -108,7 +124,7 @@ module HappyPath
class TestTextRenderWithLayoutFalse < SimpleRouteCase
describe "Rendering text with :layout => false"
- get "/happy_path/render_text/render_text_with_layout_false"
+ get "/happy_path/render_text_with_layouts/render_text_with_layout_false"
assert_body "hello world"
assert_status 200
end
@@ -116,7 +132,7 @@ module HappyPath
class TestTextRenderWithLayoutNil < SimpleRouteCase
describe "Rendering text with :layout => nil"
- get "/happy_path/render_text/render_text_with_layout_nil"
+ get "/happy_path/render_text_with_layouts/render_text_with_layout_nil"
assert_body "hello world"
assert_status 200
end
diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb
index a66fc321e6..969ae56f05 100644
--- a/actionpack/test/new_base/test_helper.rb
+++ b/actionpack/test/new_base/test_helper.rb
@@ -44,7 +44,7 @@ module ActionController
@subclasses
end
- append_view_path File.join(File.dirname(__FILE__), '..', 'fixtures')
+ # append_view_path File.join(File.dirname(__FILE__), '..', 'fixtures')
CORE_METHODS = self.public_instance_methods
end
@@ -53,7 +53,7 @@ end
module ActionView #:nodoc:
class FixtureTemplate < Template
class FixturePath < Template::Path
- def initialize(hash)
+ def initialize(hash = {})
@hash = {}
hash.each do |k, v|