diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 96bafacdcbff10e04b08d2c0c1d7e9053d32183f..917be84b3bd9f3a1a862ad607c1e52edbf4daa99 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* respond_to .html now always renders #{action_name}.rhtml so that registered custom template handlers do not override it in priority. Custom mime types require a block and throw proper error now. [Tobias Luetke] + * Deprecation: test deprecated instance vars in partials. [Jeremy Kemper] * Add UrlWriter to allow writing urls from Mailers and scripts. [Nicholas Seckar] diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 2c91266f6f7707374a9b8ef0bef3ad0cc8089731..1ceb58711bdef4ac1a8e2d86f67c50c9ee86ade5 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -27,6 +27,8 @@ class UnknownAction < ActionControllerError #:nodoc: end class MissingFile < ActionControllerError #:nodoc: end + class RenderError < ActionControllerError #:nodoc: + end class SessionOverflowError < ActionControllerError #:nodoc: DEFAULT_MESSAGE = 'Your session data is larger than the data column in which it is to be stored. You must increase the size of your data column if you intend to store large data.' diff --git a/actionpack/lib/action_controller/mime_responds.rb b/actionpack/lib/action_controller/mime_responds.rb index fd9af0590517d8bd02c109519bf6782b1a9b0aff..21905b26c8a282777c19d81b1a55ae56d430c54b 100644 --- a/actionpack/lib/action_controller/mime_responds.rb +++ b/actionpack/lib/action_controller/mime_responds.rb @@ -108,11 +108,9 @@ def respond_to(*types, &block) end class Responder #:nodoc: - DEFAULT_BLOCKS = { - :html => 'Proc.new { render }', - :js => 'Proc.new { render :action => "#{action_name}.rjs" }', - :xml => 'Proc.new { render :action => "#{action_name}.rxml" }' - } + DEFAULT_BLOCKS = [:html, :js, :xml].inject({}) do |blocks, ext| + blocks.update ext => %(Proc.new { render :action => "\#{action_name}.r#{ext}" }) + end def initialize(block_binding) @block_binding = block_binding @@ -134,7 +132,11 @@ def custom(mime_type, &block) if block_given? @responses[mime_type] = block else - @responses[mime_type] = eval(DEFAULT_BLOCKS[mime_type.to_sym], @block_binding) + if source = DEFAULT_BLOCKS[mime_type.to_sym] + @responses[mime_type] = eval(source, @block_binding) + else + raise ActionController::RenderError, "Expected a block but none was given for custom mime handler #{mime_type}" + end end end diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index dccc32bb91fbac8ce28c38757af8c217e64b5dbc..f2b8e325467af482f4ec56f62a5d4910963a1680 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -34,7 +34,7 @@ def lookup(string) def register(string, symbol, synonyms = []) Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, synonyms) SET << Mime.send(:const_get, symbol.to_s.upcase) - LOOKUP[string] = EXTENSION_LOOKUP[symbol.to_s] = SET.last + LOOKUP[string] = EXTENSION_LOOKUP[symbol.to_s] = SET.last end def parse(accept_header) diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index d18d4679d41cd7b9f7ac257d24ea95542e2c2e2c..9118d9e5538a5a5880e6454411698683347c5424 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -72,6 +72,18 @@ def custom_constant_handling Mime.send :remove_const, :MOBILE end + + def custom_constant_handling_without_block + Mime::Type.register("text/x-mobile", :mobile) + + respond_to do |type| + type.html { render :text => "HTML" } + type.mobile + end + + Mime.send :remove_const, :MOBILE + end + def handle_any respond_to do |type| @@ -271,6 +283,13 @@ def test_custom_constant assert_equal "Mobile", @response.body end + def custom_constant_handling_without_block + + assert_raised(ActionController::RenderError) do + get :custom_constant_handling, :format => "mobile" + end + end + def test_forced_format get :html_xml_or_rss assert_equal "HTML", @response.body