2016-08-06 12:50:17 -04:00
|
|
|
require "abstract_unit"
|
2009-10-21 15:47:10 -04:00
|
|
|
|
|
|
|
module AbstractController
|
|
|
|
module Testing
|
|
|
|
class ControllerRenderer < AbstractController::Base
|
2013-07-05 08:34:39 -04:00
|
|
|
include AbstractController::Rendering
|
2013-06-28 10:46:10 -04:00
|
|
|
include ActionView::Rendering
|
2009-10-21 15:47:10 -04:00
|
|
|
|
2010-09-17 16:39:14 -04:00
|
|
|
def _prefixes
|
|
|
|
%w[renderer]
|
2010-01-22 11:57:36 -05:00
|
|
|
end
|
|
|
|
|
2009-10-21 15:47:10 -04:00
|
|
|
self.view_paths = [ActionView::FixtureResolver.new(
|
|
|
|
"template.erb" => "With Template",
|
2010-01-29 10:49:26 -05:00
|
|
|
"renderer/default.erb" => "With Default",
|
2010-01-22 11:57:36 -05:00
|
|
|
"renderer/string.erb" => "With String",
|
|
|
|
"renderer/symbol.erb" => "With Symbol",
|
|
|
|
"string/with_path.erb" => "With String With Path",
|
2010-03-08 14:39:15 -05:00
|
|
|
"some/file.erb" => "With File"
|
2009-10-21 15:47:10 -04:00
|
|
|
)]
|
|
|
|
|
|
|
|
def template
|
2016-08-06 13:36:34 -04:00
|
|
|
render template: "template"
|
2009-10-21 15:47:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def file
|
2016-08-06 13:36:34 -04:00
|
|
|
render file: "some/file"
|
2009-10-21 15:47:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def inline
|
2016-08-06 13:36:34 -04:00
|
|
|
render inline: "With <%= :Inline %>"
|
2009-10-21 15:47:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def text
|
2015-07-17 21:48:00 -04:00
|
|
|
render plain: "With Text"
|
2009-10-21 15:47:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def default
|
|
|
|
render
|
|
|
|
end
|
|
|
|
|
2010-01-22 11:57:36 -05:00
|
|
|
def string
|
|
|
|
render "string"
|
|
|
|
end
|
|
|
|
|
|
|
|
def string_with_path
|
|
|
|
render "string/with_path"
|
|
|
|
end
|
|
|
|
|
|
|
|
def symbol
|
|
|
|
render :symbol
|
2010-01-21 06:12:10 -05:00
|
|
|
end
|
2009-10-21 15:47:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TestRenderer < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@controller = ControllerRenderer.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_template
|
2014-05-06 15:35:25 -04:00
|
|
|
assert_equal "With Template", @controller.process(:template)
|
2009-10-21 15:47:10 -04:00
|
|
|
assert_equal "With Template", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_file
|
2014-05-06 15:35:25 -04:00
|
|
|
assert_equal "With File", @controller.process(:file)
|
2009-10-21 15:47:10 -04:00
|
|
|
assert_equal "With File", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_inline
|
2014-05-06 15:35:25 -04:00
|
|
|
assert_equal "With Inline", @controller.process(:inline)
|
2009-10-21 15:47:10 -04:00
|
|
|
assert_equal "With Inline", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_text
|
2014-05-06 15:35:25 -04:00
|
|
|
assert_equal "With Text", @controller.process(:text)
|
2009-10-21 15:47:10 -04:00
|
|
|
assert_equal "With Text", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_default
|
2014-05-06 15:35:25 -04:00
|
|
|
assert_equal "With Default", @controller.process(:default)
|
2009-10-21 15:47:10 -04:00
|
|
|
assert_equal "With Default", @controller.response_body
|
|
|
|
end
|
|
|
|
|
2010-01-22 11:57:36 -05:00
|
|
|
def test_render_string
|
2014-05-06 15:35:25 -04:00
|
|
|
assert_equal "With String", @controller.process(:string)
|
2010-01-22 11:57:36 -05:00
|
|
|
assert_equal "With String", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_symbol
|
2014-05-06 15:35:25 -04:00
|
|
|
assert_equal "With Symbol", @controller.process(:symbol)
|
2010-01-22 11:57:36 -05:00
|
|
|
assert_equal "With Symbol", @controller.response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_render_string_with_path
|
2014-05-06 15:35:25 -04:00
|
|
|
assert_equal "With String With Path", @controller.process(:string_with_path)
|
2010-01-22 11:57:36 -05:00
|
|
|
assert_equal "With String With Path", @controller.response_body
|
2010-01-21 06:12:10 -05:00
|
|
|
end
|
2009-10-21 15:47:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|