Get controller/layout_test.rb running on new base except for ActionController::Base.exempt_from_layout which is going to be deprecated.

This commit is contained in:
Yehuda Katz + Carl Lerche 2009-05-22 15:16:28 -07:00
parent 01129534cd
commit 72a574b507
6 changed files with 36 additions and 31 deletions

@ -61,12 +61,13 @@ Rake::TestTask.new(:test_new_base_on_old_tests) do |t|
# layout # layout
# Dir.glob( "test/{dispatch,template}/**/*_test.rb" ).sort + # Dir.glob( "test/{dispatch,template}/**/*_test.rb" ).sort +
t.test_files = %w( t.test_files = %w(
addresses_render base benchmark caching capture content_type dispatcher action_pack_assertions addresses_render assert_select
flash mime_responds record_identifier redirect base benchmark caching capture content_type dispatcher
render render_json render_xml filter_params flash helper http_basic_authentication
send_file request_forgery_protection rescue url_rewriter verification webservice http_digest_authentication layout mime_responds
http_basic_authentication http_digest_authentication record_identifier redirect render render_json render_xml
action_pack_assertions assert_select filter_params helper send_file request_forgery_protection rescue url_rewriter
verification webservice
).map { |name| "test/controller/#{name}_test.rb" } ).map { |name| "test/controller/#{name}_test.rb" }
end end

@ -65,12 +65,12 @@ def _layout() end # This will be overwritten
# :api: plugin # :api: plugin
# ==== # ====
# Override this to mutate the inbound layout name # 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) unless [String, FalseClass, NilClass].include?(name.class)
raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}" raise ArgumentError, "String, false, or nil expected; you passed #{name.inspect}"
end 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 end
# TODO: Decide if this is the best hook point for the feature # TODO: Decide if this is the best hook point for the feature
@ -78,7 +78,7 @@ def _layout_prefix(name)
"layouts" "layouts"
end end
def _default_layout(require_layout = false) def _default_layout(require_layout = false, details = {:formats => formats})
if require_layout && _action_has_layout? && !_layout if require_layout && _action_has_layout? && !_layout
raise ArgumentError, raise ArgumentError,
"There was no default layout for #{self.class} in #{view_paths.inspect}" "There was no default layout for #{self.class} in #{view_paths.inspect}"

@ -11,23 +11,20 @@ def _implied_layout_name
end end
end end
def render_to_body(options)
# render :text => ..., :layout => ...
# or
# render :anything_else
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
end
super
end
private private
def _layout_for_option(name) def _determine_template(options)
super
if (!options.key?(:text) && !options.key?(:inline) && !options.key?(:partial)) || options.key?(:layout)
options[:_layout] = _layout_for_option(options.key?(:layout) ? options[:layout] : :none, options[:_template].details)
end
end
def _layout_for_option(name, details)
case name case name
when String then _layout_for_name(name) when String then _layout_for_name(name, details)
when true then _default_layout(true) when true then _default_layout(true, details)
when :none then _default_layout(false, details)
when false, nil then nil when false, nil then nil
else else
raise ArgumentError, raise ArgumentError,

@ -7,7 +7,7 @@
module ActionView module ActionView
class Template class Template
extend TemplateHandlers extend TemplateHandlers
attr_reader :source, :identifier, :handler, :mime_type attr_reader :source, :identifier, :handler, :mime_type, :details
def initialize(source, identifier, handler, details) def initialize(source, identifier, handler, details)
@source = source @source = source

@ -6,6 +6,10 @@ def initialize(string, content_type = Mime[:html])
@content_type = Mime[content_type] @content_type = Mime[content_type]
end end
def details
{:formats => [@content_type.to_sym]}
end
def identifier() self end def identifier() self end
def render(*) self end def render(*) self end

@ -174,6 +174,8 @@ def test_layout_is_not_set_when_none_rendered
assert_nil @controller.template.layout assert_nil @controller.template.layout
end end
for_tag(:old_base) do
# exempt_from_layout is deprecated
def test_exempt_from_layout_honored_by_render_template def test_exempt_from_layout_honored_by_render_template
ActionController::Base.exempt_from_layout :erb ActionController::Base.exempt_from_layout :erb
@controller = RenderWithTemplateOptionController.new @controller = RenderWithTemplateOptionController.new
@ -184,6 +186,7 @@ def test_exempt_from_layout_honored_by_render_template
ensure ensure
ActionController::Base.exempt_from_layout.delete(ERB) ActionController::Base.exempt_from_layout.delete(ERB)
end end
end
def test_layout_is_picked_from_the_controller_instances_view_path def test_layout_is_picked_from_the_controller_instances_view_path
pending do pending do