2009-03-19 20:35:39 +00:00
|
|
|
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
module RenderTemplate
|
2009-05-02 00:27:44 +00:00
|
|
|
class WithoutLayoutController < ActionController::Base
|
2009-03-21 01:38:03 +00:00
|
|
|
|
2009-04-28 01:21:26 +00:00
|
|
|
self.view_paths = [ActionView::Template::FixturePath.new(
|
2009-03-21 01:38:03 +00:00
|
|
|
"test/basic.html.erb" => "Hello from basic.html.erb",
|
2009-04-29 23:33:24 +00:00
|
|
|
"shared.html.erb" => "Elastica",
|
|
|
|
"locals.html.erb" => "The secret is <%= secret %>"
|
2009-03-21 01:38:03 +00:00
|
|
|
)]
|
2009-03-19 20:35:39 +00:00
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
def index
|
2009-03-19 20:35:39 +00:00
|
|
|
render :template => "test/basic"
|
|
|
|
end
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
def in_top_directory
|
2009-03-19 20:35:39 +00:00
|
|
|
render :template => 'shared'
|
|
|
|
end
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
def in_top_directory_with_slash
|
2009-03-19 20:35:39 +00:00
|
|
|
render :template => '/shared'
|
|
|
|
end
|
2009-04-29 23:33:24 +00:00
|
|
|
|
|
|
|
def with_locals
|
|
|
|
render :template => "locals", :locals => { :secret => 'area51' }
|
|
|
|
end
|
2009-03-19 20:35:39 +00:00
|
|
|
end
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
class TestWithoutLayout < SimpleRouteCase
|
2009-03-21 01:38:03 +00:00
|
|
|
describe "rendering a normal template with full path without layout"
|
2009-03-19 20:35:39 +00:00
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
get "/render_template/without_layout"
|
2009-03-19 20:35:39 +00:00
|
|
|
assert_body "Hello from basic.html.erb"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestTemplateRenderInTopDirectory < SimpleRouteCase
|
|
|
|
describe "rendering a template not in a subdirectory"
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
get "/render_template/without_layout/in_top_directory"
|
2009-03-19 20:35:39 +00:00
|
|
|
assert_body "Elastica"
|
|
|
|
assert_status 200
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestTemplateRenderInTopDirectoryWithSlash < SimpleRouteCase
|
|
|
|
describe "rendering a template not in a subdirectory with a leading slash"
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
get "/render_template/without_layout/in_top_directory_with_slash"
|
2009-03-19 20:35:39 +00:00
|
|
|
assert_body "Elastica"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-04-29 23:33:24 +00:00
|
|
|
|
|
|
|
class TestTemplateRenderWithLocals < SimpleRouteCase
|
|
|
|
describe "rendering a template with local variables"
|
|
|
|
|
|
|
|
get "/render_template/without_layout/with_locals"
|
|
|
|
assert_body "The secret is area51"
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-04-08 00:57:20 +00:00
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
class WithLayoutController < ::ApplicationController
|
2009-03-21 01:38:03 +00:00
|
|
|
|
2009-04-28 01:21:26 +00:00
|
|
|
self.view_paths = [ActionView::Template::FixturePath.new(
|
2009-03-21 01:38:03 +00:00
|
|
|
"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."
|
|
|
|
)]
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
def index
|
2009-03-21 01:38:03 +00:00
|
|
|
render :template => "test/basic"
|
|
|
|
end
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
def with_layout
|
2009-03-21 01:38:03 +00:00
|
|
|
render :template => "test/basic", :layout => true
|
|
|
|
end
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
def with_layout_false
|
2009-03-21 01:38:03 +00:00
|
|
|
render :template => "test/basic", :layout => false
|
|
|
|
end
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
def with_layout_nil
|
2009-03-21 01:38:03 +00:00
|
|
|
render :template => "test/basic", :layout => nil
|
|
|
|
end
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
def with_custom_layout
|
2009-03-21 01:38:03 +00:00
|
|
|
render :template => "test/basic", :layout => "greetings"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestTemplateRenderWithLayout < SimpleRouteCase
|
|
|
|
describe "rendering a normal template with full path with layout"
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
get "/render_template/with_layout"
|
2009-03-21 01:38:03 +00:00
|
|
|
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"
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
get "/render_template/with_layout/with_layout"
|
2009-03-21 01:38:03 +00:00
|
|
|
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"
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
get "/render_template/with_layout/with_layout_false"
|
2009-03-21 01:38:03 +00:00
|
|
|
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"
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
get "/render_template/with_layout/with_layout_nil"
|
2009-03-21 01:38:03 +00:00
|
|
|
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'"
|
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
get "/render_template/with_layout/with_custom_layout"
|
2009-03-21 01:38:03 +00:00
|
|
|
assert_body "Hello from basic.html.erb, I wish thee well."
|
|
|
|
assert_status 200
|
|
|
|
end
|
2009-04-29 18:42:27 +00:00
|
|
|
|
|
|
|
module Compatibility
|
2009-05-02 00:27:44 +00:00
|
|
|
class WithoutLayoutController < ActionController::Base
|
2009-04-29 18:42:27 +00:00
|
|
|
self.view_paths = [ActionView::Template::FixturePath.new(
|
|
|
|
"test/basic.html.erb" => "Hello from basic.html.erb",
|
|
|
|
"shared.html.erb" => "Elastica"
|
|
|
|
)]
|
2009-03-19 20:35:39 +00:00
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
def with_forward_slash
|
|
|
|
render :template => "/test/basic"
|
|
|
|
end
|
|
|
|
end
|
2009-04-28 01:21:26 +00:00
|
|
|
|
2009-04-29 18:42:27 +00:00
|
|
|
class TestTemplateRenderWithForwardSlash < SimpleRouteCase
|
|
|
|
describe "rendering a normal template with full path starting with a leading slash"
|
|
|
|
|
|
|
|
get "/render_template/compatibility/without_layout/with_forward_slash"
|
|
|
|
assert_body "Hello from basic.html.erb"
|
|
|
|
assert_status 200
|
2009-04-28 01:21:26 +00:00
|
|
|
end
|
|
|
|
end
|
2009-03-19 20:35:39 +00:00
|
|
|
end
|