aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-10-21 17:47:10 -0200
committerYehuda Katz <wycats@gmail.com>2009-11-01 02:23:48 +0100
commit03960048616593c249745d1e321dbcc7f0483c76 (patch)
treee8ef23941eb4e9ea02610921c783504991edfe2a
parent0cf16ddb88b4fa28c37e576d50d835b100c3f6a1 (diff)
downloadrails-03960048616593c249745d1e321dbcc7f0483c76.tar.gz
rails-03960048616593c249745d1e321dbcc7f0483c76.tar.bz2
rails-03960048616593c249745d1e321dbcc7f0483c76.zip
Add some basic render_test to AbstractController.
-rw-r--r--actionmailer/lib/action_mailer/base.rb5
-rw-r--r--actionpack/lib/abstract_controller/layouts.rb2
-rw-r--r--actionpack/lib/abstract_controller/rendering_controller.rb7
-rw-r--r--actionpack/lib/action_controller/metal/rendering_controller.rb9
-rw-r--r--actionpack/test/abstract/render_test.rb88
5 files changed, 98 insertions, 13 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 3009d8cdfc..e3690577e1 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -386,11 +386,6 @@ module ActionMailer #:nodoc:
[:"*/*"]
end
- # Refactor out all mailer_name
- def _prefix
- mailer_name
- end
-
class << self
attr_writer :mailer_name
diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb
index f4f1d41360..8293e79b0a 100644
--- a/actionpack/lib/abstract_controller/layouts.rb
+++ b/actionpack/lib/abstract_controller/layouts.rb
@@ -195,7 +195,7 @@ module AbstractController
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
diff --git a/actionpack/lib/abstract_controller/rendering_controller.rb b/actionpack/lib/abstract_controller/rendering_controller.rb
index 07deda77a2..0aae2b18e9 100644
--- a/actionpack/lib/abstract_controller/rendering_controller.rb
+++ b/actionpack/lib/abstract_controller/rendering_controller.rb
@@ -118,9 +118,6 @@ module AbstractController
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 @@ module AbstractController
view_paths.exists?(name, details, options[:_prefix], options[:_partial])
end
- def _prefix
- self.class.name.underscore
- end
-
def with_template_cache(name)
yield
end
diff --git a/actionpack/lib/action_controller/metal/rendering_controller.rb b/actionpack/lib/action_controller/metal/rendering_controller.rb
index 9e8bc82385..c5ade26702 100644
--- a/actionpack/lib/action_controller/metal/rendering_controller.rb
+++ b/actionpack/lib/action_controller/metal/rendering_controller.rb
@@ -65,6 +65,15 @@ module ActionController
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
diff --git a/actionpack/test/abstract/render_test.rb b/actionpack/test/abstract/render_test.rb
new file mode 100644
index 0000000000..45a4763fe4
--- /dev/null
+++ b/actionpack/test/abstract/render_test.rb
@@ -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