提交 e22a3d89 编写于 作者: Y Yehuda Katz

Slightly modify things to get content type matching working without breaking other code

上级 3ac6d8f8
......@@ -68,11 +68,11 @@ def initialize
self.response_obj = {}
end
def process(action_name)
@_action_name = action_name = action_name.to_s
def process(action)
@_action_name = action_name = action.to_s
unless action_name = method_for_action(action_name)
raise ActionNotFound, "The action '#{action_name}' could not be found"
raise ActionNotFound, "The action '#{action}' could not be found"
end
process_action(action_name)
......
......@@ -39,15 +39,15 @@ def _implied_layout_name
def _write_layout_method
case @_layout
when String
self.class_eval %{def _layout() #{@_layout.inspect} end}
self.class_eval %{def _layout(details) #{@_layout.inspect} end}
when Symbol
self.class_eval %{def _layout() #{@_layout} end}
self.class_eval %{def _layout(details) #{@_layout} end}
when false
self.class_eval %{def _layout() end}
self.class_eval %{def _layout(details) end}
else
self.class_eval %{
def _layout
if view_paths.find_by_parts?("#{_implied_layout_name}", {:formats => formats}, "layouts")
def _layout(details)
if view_paths.find_by_parts?("#{_implied_layout_name}", details, "layouts")
"#{_implied_layout_name}"
else
super
......@@ -60,7 +60,7 @@ def _layout
private
def _layout() end # This will be overwritten
def _layout(details) end # This will be overwritten
# :api: plugin
# ====
......@@ -79,13 +79,13 @@ def _layout_prefix(name)
end
def _default_layout(require_layout = false, details = {:formats => formats})
if require_layout && _action_has_layout? && !_layout
if require_layout && _action_has_layout? && !_layout(details)
raise ArgumentError,
"There was no default layout for #{self.class} in #{view_paths.inspect}"
end
begin
_layout_for_name(_layout, details) if _action_has_layout?
_layout_for_name(_layout(details), details) if _action_has_layout?
rescue NameError => e
raise NoMethodError,
"You specified #{@_layout.inspect} as the layout, but no such method was found"
......
......@@ -173,9 +173,15 @@ def format(view_path = [])
def formats
if ActionController::Base.use_accept_header
Array(Mime[parameters[:format]] || accepts)
ret = Array(Mime[parameters[:format]] || accepts)
if defined?(ActionController::Http)
if all = ret.index(Mime::ALL)
ret.delete(Mime::ALL) && ret.insert(all, *Mime::SET)
end
end
ret
else
[format, Mime[:all]]
[format] + Mime::SET
end
end
......
......@@ -66,4 +66,36 @@ class LayoutOptionsTest < SimpleRouteCase
assert_response "hai(layout_false.html.erb)"
end
end
class MismatchFormatController < ::ApplicationController
self.view_paths = [ActionView::Template::FixturePath.new(
"layouts/application.html.erb" => "<html><%= yield %></html>",
"controller_layouts/mismatch_format/index.js.rjs" => "page[:test].omg",
"controller_layouts/mismatch_format/implicit.rjs" => "page[:test].omg"
)]
def explicit
render :layout => "application"
end
end
class MismatchFormatTest < SimpleRouteCase
testing ControllerLayouts::MismatchFormatController
test "if JS is selected, an HTML template is not also selected" do
get :index
assert_response "$(\"test\").omg();"
end
test "if JS is implicitly selected, an HTML template is not also selected" do
get :implicit
assert_response "$(\"test\").omg();"
end
test "if an HTML template is explicitly provides for a JS template, an error is raised" do
assert_raises ActionView::MissingTemplate do
get :explicit, {}, "action_dispatch.show_exceptions" => false
end
end
end
end
\ No newline at end of file
......@@ -67,7 +67,7 @@ def self.testing(klass = nil)
def get(thing, *args)
if thing.is_a?(Symbol)
super("#{self.class.testing}/#{thing}")
super("#{self.class.testing}/#{thing}", *args)
else
super
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册