mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Slightly modify things to get content type matching working without breaking other code
This commit is contained in:
@@ -68,11 +68,11 @@ module AbstractController
|
||||
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 @@ module AbstractController
|
||||
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 @@ module AbstractController
|
||||
|
||||
private
|
||||
|
||||
def _layout() end # This will be overwritten
|
||||
def _layout(details) end # This will be overwritten
|
||||
|
||||
# :api: plugin
|
||||
# ====
|
||||
@@ -79,13 +79,13 @@ module AbstractController
|
||||
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 @@ module ActionDispatch
|
||||
|
||||
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 @@ module ControllerLayouts
|
||||
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
|
||||
@@ -67,7 +67,7 @@ class Rack::TestCase < ActionController::IntegrationTest
|
||||
|
||||
def get(thing, *args)
|
||||
if thing.is_a?(Symbol)
|
||||
super("#{self.class.testing}/#{thing}")
|
||||
super("#{self.class.testing}/#{thing}", *args)
|
||||
else
|
||||
super
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user