提交 03960048 编写于 作者: J José Valim 提交者: Yehuda Katz

Add some basic render_test to AbstractController.

上级 0cf16ddb
......@@ -386,11 +386,6 @@ def formats
[:"*/*"]
end
# Refactor out all mailer_name
def _prefix
mailer_name
end
class << self
attr_writer :mailer_name
......
......@@ -195,7 +195,7 @@ def _layout_for_option(name, details)
def _determine_template(options)
super
return if (options.key?(:text) || options.key?(:inline) || options.key?(:partial)) && !options.key?(:layout)
return unless (options.keys & [:text, :inline, :partial]).empty? || options.key?(:layout)
layout = options.key?(:layout) ? options[:layout] : :default
options[:_layout] = _layout_for_option(layout, options[:_template].details)
end
......
......@@ -118,9 +118,6 @@ def _determine_template(options)
options[:_template_name] = options[:template]
elsif options.key?(:file)
options[:_template_name] = options[:file]
elsif !options.key?(:partial)
options[:_template_name] ||= options[:action]
options[:_prefix] = _prefix
end
name = (options[:_template_name] || action_name).to_s
......@@ -138,10 +135,6 @@ def template_exists?(name, details, options)
view_paths.exists?(name, details, options[:_prefix], options[:_partial])
end
def _prefix
self.class.name.underscore
end
def with_template_cache(name)
yield
end
......
......@@ -65,6 +65,15 @@ def _prefix
controller_path
end
def _determine_template(options)
if (options.keys & [:partial, :file, :template, :text, :inline]).empty?
options[:_template_name] ||= options[:action]
options[:_prefix] = _prefix
end
super
end
def format_for_text
formats.first
end
......
require 'abstract_unit'
module AbstractController
module Testing
class ControllerRenderer < AbstractController::Base
include AbstractController::RenderingController
self.view_paths = [ActionView::FixtureResolver.new(
"default.erb" => "With Default",
"template.erb" => "With Template",
"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
def template_name
render :_template_name => :template_name
end
def object
render :_template => ActionView::TextTemplate.new("With Object")
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
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册