aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-22 15:16:28 -0700
committerYehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com>2009-05-22 15:25:13 -0700
commit72a574b5073b1debd58c954b34c54d3bdee7749f (patch)
tree994345ceb428e29ba7588ee5abc5cf2fa73de448
parent01129534cde293e3561dd7cc3cb5ae9ac3de9e8c (diff)
downloadrails-72a574b5073b1debd58c954b34c54d3bdee7749f.tar.gz
rails-72a574b5073b1debd58c954b34c54d3bdee7749f.tar.bz2
rails-72a574b5073b1debd58c954b34c54d3bdee7749f.zip
Get controller/layout_test.rb running on new base except for ActionController::Base.exempt_from_layout which is going to be deprecated.
-rw-r--r--actionpack/Rakefile13
-rw-r--r--actionpack/lib/action_controller/abstract/layouts.rb6
-rw-r--r--actionpack/lib/action_controller/new_base/layouts.rb21
-rw-r--r--actionpack/lib/action_view/template/template.rb2
-rw-r--r--actionpack/lib/action_view/template/text.rb4
-rw-r--r--actionpack/test/controller/layout_test.rb17
6 files changed, 34 insertions, 29 deletions
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index 0ce6f7823b..6c820636d5 100644
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -61,12 +61,13 @@ Rake::TestTask.new(:test_new_base_on_old_tests) do |t|
# layout
# Dir.glob( "test/{dispatch,template}/**/*_test.rb" ).sort +
t.test_files = %w(
- addresses_render base benchmark caching capture content_type dispatcher
- flash mime_responds record_identifier redirect
- render render_json render_xml
- send_file request_forgery_protection rescue url_rewriter verification webservice
- http_basic_authentication http_digest_authentication
- action_pack_assertions assert_select filter_params helper
+ action_pack_assertions addresses_render assert_select
+ base benchmark caching capture content_type dispatcher
+ filter_params flash helper http_basic_authentication
+ http_digest_authentication layout mime_responds
+ record_identifier redirect render render_json render_xml
+ send_file request_forgery_protection rescue url_rewriter
+ verification webservice
).map { |name| "test/controller/#{name}_test.rb" }
end
diff --git a/actionpack/lib/action_controller/abstract/layouts.rb b/actionpack/lib/action_controller/abstract/layouts.rb
index dec394a021..b3b743d6e8 100644
--- a/actionpack/lib/action_controller/abstract/layouts.rb
+++ b/actionpack/lib/action_controller/abstract/layouts.rb
@@ -65,12 +65,12 @@ module AbstractController
# :api: plugin
# ====
# Override this to mutate the inbound layout name
- def _layout_for_name(name)
+ def _layout_for_name(name, details = {:formats => formats})
unless [String, FalseClass, NilClass].include?(name.class)
raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}"
end
- name && view_paths.find_by_parts(name, {:formats => formats}, _layout_prefix(name))
+ name && view_paths.find_by_parts(name, details, _layout_prefix(name))
end
# TODO: Decide if this is the best hook point for the feature
@@ -78,7 +78,7 @@ module AbstractController
"layouts"
end
- def _default_layout(require_layout = false)
+ def _default_layout(require_layout = false, details = {:formats => formats})
if require_layout && _action_has_layout? && !_layout
raise ArgumentError,
"There was no default layout for #{self.class} in #{view_paths.inspect}"
diff --git a/actionpack/lib/action_controller/new_base/layouts.rb b/actionpack/lib/action_controller/new_base/layouts.rb
index bf5b14c4e1..35068db770 100644
--- a/actionpack/lib/action_controller/new_base/layouts.rb
+++ b/actionpack/lib/action_controller/new_base/layouts.rb
@@ -11,23 +11,20 @@ module ActionController
end
end
- def render_to_body(options)
- # render :text => ..., :layout => ...
- # or
- # render :anything_else
+ private
+
+ def _determine_template(options)
+ super
if (!options.key?(:text) && !options.key?(:inline) && !options.key?(:partial)) || options.key?(:layout)
- options[:_layout] = options.key?(:layout) ? _layout_for_option(options[:layout]) : _default_layout
+ options[:_layout] = _layout_for_option(options.key?(:layout) ? options[:layout] : :none, options[:_template].details)
end
-
- super
end
-
- private
- def _layout_for_option(name)
+ def _layout_for_option(name, details)
case name
- when String then _layout_for_name(name)
- when true then _default_layout(true)
+ when String then _layout_for_name(name, details)
+ when true then _default_layout(true, details)
+ when :none then _default_layout(false, details)
when false, nil then nil
else
raise ArgumentError,
diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb
index 0eedc596d2..d58f4ec19e 100644
--- a/actionpack/lib/action_view/template/template.rb
+++ b/actionpack/lib/action_view/template/template.rb
@@ -7,7 +7,7 @@ require "action_view/template/path"
module ActionView
class Template
extend TemplateHandlers
- attr_reader :source, :identifier, :handler, :mime_type
+ attr_reader :source, :identifier, :handler, :mime_type, :details
def initialize(source, identifier, handler, details)
@source = source
diff --git a/actionpack/lib/action_view/template/text.rb b/actionpack/lib/action_view/template/text.rb
index a86c3915c2..fd57b1677e 100644
--- a/actionpack/lib/action_view/template/text.rb
+++ b/actionpack/lib/action_view/template/text.rb
@@ -6,6 +6,10 @@ module ActionView #:nodoc:
@content_type = Mime[content_type]
end
+ def details
+ {:formats => [@content_type.to_sym]}
+ end
+
def identifier() self end
def render(*) self end
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index 1cd448d5e8..04da0a7f86 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -174,15 +174,18 @@ class LayoutSetInResponseTest < ActionController::TestCase
assert_nil @controller.template.layout
end
- def test_exempt_from_layout_honored_by_render_template
- ActionController::Base.exempt_from_layout :erb
- @controller = RenderWithTemplateOptionController.new
+ for_tag(:old_base) do
+ # exempt_from_layout is deprecated
+ def test_exempt_from_layout_honored_by_render_template
+ ActionController::Base.exempt_from_layout :erb
+ @controller = RenderWithTemplateOptionController.new
- get :hello
- assert_equal "alt/hello.rhtml", @response.body.strip
+ get :hello
+ assert_equal "alt/hello.rhtml", @response.body.strip
- ensure
- ActionController::Base.exempt_from_layout.delete(ERB)
+ ensure
+ ActionController::Base.exempt_from_layout.delete(ERB)
+ end
end
def test_layout_is_picked_from_the_controller_instances_view_path