Add some basic render_test to AbstractController.
This commit is contained in:
parent
0cf16ddb88
commit
0396004861
@ -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
|
||||
|
88
actionpack/test/abstract/render_test.rb
Normal file
88
actionpack/test/abstract/render_test.rb
Normal file
@ -0,0 +1,88 @@
|
||||
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
|
Loading…
Reference in New Issue
Block a user