2009-10-21 19:47:10 +00:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
module AbstractController
|
|
|
|
module Testing
|
|
|
|
|
|
|
|
class ControllerRenderer < AbstractController::Base
|
2009-12-21 01:15:31 +00:00
|
|
|
include AbstractController::Rendering
|
2009-10-21 19:47:10 +00:00
|
|
|
|
2010-01-22 16:57:36 +00:00
|
|
|
def _prefix
|
|
|
|
"renderer"
|
|
|
|
end
|
|
|
|
|
2009-10-21 19:47:10 +00:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
|
|
|
"default.erb" => "With Default",
|
|
|
|
"template.erb" => "With Template",
|
2010-01-22 16:57:36 +00:00
|
|
|
"renderer/string.erb" => "With String",
|
|
|
|
"renderer/symbol.erb" => "With Symbol",
|
|
|
|
"string/with_path.erb" => "With String With Path",
|
2009-10-21 19:47:10 +00:00
|
|
|
"some/file.erb" => "With File",
|
|
|
|
"template_name.erb" => "With Template Name"
|
|
|
|
)]
|
|
|
|
|
|
|
|
def template
|
|
|
|
render :template => "template"
|
|
|
|
end
|
|
|
|
|
|
|
|
def file
|
|
|
|
render :file => "some/file"
|
|
|
|
end
|
|
|
|
|
|
|
|
def inline
|
|
|
|
render :inline => "With <%= :Inline %>"
|
|
|
|
end
|
|
|
|
|
|
|
|
def text
|
|
|
|
render :text => "With Text"
|
|
|
|
end
|
|
|
|
|
|
|
|
def default
|
|
|
|
render
|
|
|
|
end
|
|
|
|
|
2010-01-22 16:57:36 +00:00
|
|
|
def string
|
|
|
|
render "string"
|
|
|
|
end
|
|
|
|
|
|
|
|
def string_with_path
|
|
|
|
render "string/with_path"
|
|
|
|
end
|
|
|
|
|
|
|
|
def symbol
|
|
|
|
render :symbol
|
2010-01-21 11:12:10 +00:00
|
|
|
end
|
|
|
|
|
2009-10-21 19:47:10 +00:00
|
|
|
def template_name
|
|
|
|
render :_template_name => :template_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def object
|
2009-12-03 04:01:01 +00:00
|
|
|
render :_template => ActionView::Template::Text.new("With Object")
|
2009-10-21 19:47:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestRenderer < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@controller = ControllerRenderer.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_template
|
|
|
|
@controller.process(:template)
|
|
|
|
assert_equal "With Template", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_file
|
|
|
|
@controller.process(:file)
|
|
|
|
assert_equal "With File", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_inline
|
|
|
|
@controller.process(:inline)
|
|
|
|
assert_equal "With Inline", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_text
|
|
|
|
@controller.process(:text)
|
|
|
|
assert_equal "With Text", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_default
|
|
|
|
@controller.process(:default)
|
|
|
|
assert_equal "With Default", @controller.response_body
|
|
|
|
end
|
|
|
|
|
2010-01-22 16:57:36 +00:00
|
|
|
def test_render_string
|
|
|
|
@controller.process(:string)
|
|
|
|
assert_equal "With String", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_symbol
|
|
|
|
@controller.process(:symbol)
|
|
|
|
assert_equal "With Symbol", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_string_with_path
|
|
|
|
@controller.process(:string_with_path)
|
|
|
|
assert_equal "With String With Path", @controller.response_body
|
2010-01-21 11:12:10 +00:00
|
|
|
end
|
|
|
|
|
2009-10-21 19:47:10 +00:00
|
|
|
def test_render_template_name
|
|
|
|
@controller.process(:template_name)
|
|
|
|
assert_equal "With Template Name", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_object
|
|
|
|
@controller.process(:object)
|
|
|
|
assert_equal "With Object", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|