diff options
Diffstat (limited to 'actionpack')
18 files changed, 159 insertions, 232 deletions
diff --git a/actionpack/examples/benchmark.rb b/actionpack/examples/benchmark.rb index 21d81283a6..78a6649c74 100644 --- a/actionpack/examples/benchmark.rb +++ b/actionpack/examples/benchmark.rb @@ -7,7 +7,7 @@ Person = Struct.new("Person", :name, :address, :age) class BenchmarkController < ActionController::Base def message - render_text "hello world" + render :text => "hello world" end def list diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 353f3f7330..e0474ff5b3 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -15,6 +15,8 @@ module ActionController #:nodoc: end class MissingTemplate < ActionControllerError #:nodoc: end + class RenderError < ActionControllerError #:nodoc: + end class RoutingError < ActionControllerError #:nodoc: attr_reader :failures def initialize(message, failures=[]) @@ -612,7 +614,7 @@ module ActionController #:nodoc: def view_paths self.class.view_paths end - + protected # Renders the content that will be returned to the browser as the response body. # @@ -632,10 +634,6 @@ module ActionController #:nodoc: # # but with a custom layout # render :action => "long_goal", :layout => "spectacular" # - # _Deprecation_ _notice_: This used to have the signatures <tt>render_action("action", status = 200)</tt>, - # <tt>render_without_layout("controller/action", status = 200)</tt>, and - # <tt>render_with_layout("controller/action", status = 200, layout)</tt>. - # # === Rendering partials # # Partial rendering in a controller is most commonly used together with Ajax calls that only update one or a few elements on a page @@ -702,8 +700,6 @@ module ActionController #:nodoc: # # Renders a template relative to the template root and chooses the proper file extension # render :file => "some/template", :use_full_path => true # - # _Deprecation_ _notice_: This used to have the signature <tt>render_file(path, status = 200)</tt> - # # === Rendering text # # Rendering of text is usually used for tests or for rendering prepared content, such as a cache. By default, text @@ -729,8 +725,6 @@ module ActionController #:nodoc: # # Renders "Hello from code!" # render :text => proc { |response, output| output.write("Hello from code!") } # - # _Deprecation_ _notice_: This used to have the signature <tt>render_text("text", status = 200)</tt> - # # === Rendering JSON # # Rendering JSON sets the content type to text/x-json and optionally wraps the JSON in a callback. It is expected @@ -760,8 +754,6 @@ module ActionController #:nodoc: # # Renders "hello david" # render :inline => "<%= 'hello ' + name %>", :locals => { :name => "david" } # - # _Deprecation_ _notice_: This used to have the signature <tt>render_template(template, status = 200, type = :rhtml)</tt> - # # === Rendering inline JavaScriptGenerator page updates # # In addition to rendering JavaScriptGenerator page updates with Ajax in RJS templates (see ActionView::Base for details), @@ -777,25 +769,16 @@ module ActionController #:nodoc: # All renders take the :status and :location options and turn them into headers. They can even be used together: # # render :xml => post.to_xml, :status => :created, :location => post_url(post) - def render(options = nil, deprecated_status = nil, &block) #:doc: + def render(options = nil, &block) #:doc: raise DoubleRenderError, "Can only render or redirect once per action" if performed? if options.nil? - return render_file(default_template_name, deprecated_status, true) + return render_for_file(default_template_name, nil, true) else - # Backwards compatibility - unless options.is_a?(Hash) - if options == :update - options = { :update => true } - else - ActiveSupport::Deprecation.warn( - "You called render('#{options}'), which is a deprecated API call. Instead you use " + - "render :file => #{options}. Calling render with just a string will be removed from Rails 2.0.", - caller - ) - - return render_file(options, deprecated_status, true) - end + if options == :update + options = { :update => true } + elsif !options.is_a?(Hash) + raise RenderError, "You called render with invalid options : #{options}" end end @@ -808,35 +791,45 @@ module ActionController #:nodoc: end if text = options[:text] - render_text(text, options[:status]) + render_for_text(text, options[:status]) else if file = options[:file] - render_file(file, options[:status], options[:use_full_path], options[:locals] || {}) + render_for_file(file, options[:status], options[:use_full_path], options[:locals] || {}) elsif template = options[:template] - render_file(template, options[:status], true) + render_for_file(template, options[:status], true) elsif inline = options[:inline] - render_template(inline, options[:status], options[:type], options[:locals] || {}) + add_variables_to_assigns + render_for_text(@template.render_template(options[:type] || :erb, inline, nil, options[:locals] || {}), options[:status]) elsif action_name = options[:action] - ActiveSupport::Deprecation.silence do - render_action(action_name, options[:status], options[:layout]) - end + template = default_template_name(action_name.to_s) + if options[:layout] && !template_exempt_from_layout?(template) + render_with_a_layout(:file => template, :status => options[:status], :use_full_path => true, :layout => true) + else + render_with_no_layout(:file => template, :status => options[:status], :use_full_path => true) + end elsif xml = options[:xml] - render_xml(xml, options[:status]) + response.content_type = Mime::XML + render_for_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, options[:status]) elsif json = options[:json] - render_json(json, options[:callback], options[:status]) + json = "#{options[:callback]}(#{json})" unless options[:callback].blank? + response.content_type = Mime::JSON + render_for_text(json, options[:status]) elsif partial = options[:partial] partial = default_template_name if partial == true + add_variables_to_assigns if collection = options[:collection] - render_partial_collection(partial, collection, options[:spacer_template], options[:locals], options[:status]) + render_for_text(@template.send(:render_partial_collection, partial, collection, options[:spacer_template], options[:locals]), + options[:status]) else - render_partial(partial, ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals], options[:status]) + render_for_text(@template.send(:render_partial, partial, ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals]), + options[:status]) end elsif options[:update] @@ -844,15 +837,15 @@ module ActionController #:nodoc: @template.send :evaluate_assigns generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block) - render_javascript(generator.to_s) + response.content_type = Mime::JS + render_for_text(generator.to_s) elsif options[:nothing] # Safari doesn't pass the headers of the return if the response is zero length - render_text(" ", options[:status]) + render_for_text(" ", options[:status]) else - render_file(default_template_name, options[:status], true) - + render_for_file(default_template_name, options[:status], true) end end end @@ -860,87 +853,13 @@ module ActionController #:nodoc: # Renders according to the same rules as <tt>render</tt>, but returns the result in a string instead # of sending it as the response body to the browser. def render_to_string(options = nil, &block) #:doc: - ActiveSupport::Deprecation.silence { render(options, &block) } + render(options, &block) ensure erase_render_results forget_variables_added_to_assigns reset_variables_added_to_assigns end - def render_action(action_name, status = nil, with_layout = true) #:nodoc: - template = default_template_name(action_name.to_s) - if with_layout && !template_exempt_from_layout?(template) - render_with_layout(:file => template, :status => status, :use_full_path => true, :layout => true) - else - render_without_layout(:file => template, :status => status, :use_full_path => true) - end - end - - def render_file(template_path, status = nil, use_full_path = false, locals = {}) #:nodoc: - add_variables_to_assigns - assert_existence_of_template_file(template_path) if use_full_path - logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger - render_text(@template.render_file(template_path, use_full_path, locals), status) - end - - def render_template(template, status = nil, type = :erb, local_assigns = {}) #:nodoc: - add_variables_to_assigns - render_text(@template.render_template(type, template, nil, local_assigns), status) - end - - def render_text(text = nil, status = nil, append_response = false) #:nodoc: - @performed_render = true - - response.headers['Status'] = interpret_status(status || DEFAULT_RENDER_STATUS_CODE) - - if append_response - response.body ||= '' - response.body << text.to_s - else - response.body = text.is_a?(Proc) ? text : text.to_s - end - end - - def render_javascript(javascript, status = nil, append_response = true) #:nodoc: - response.content_type = Mime::JS - render_text(javascript, status, append_response) - end - - def render_xml(xml, status = nil) #:nodoc: - response.content_type = Mime::XML - render_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, status) - end - - def render_json(json, callback = nil, status = nil) #:nodoc: - json = "#{callback}(#{json})" unless callback.blank? - - response.content_type = Mime::JSON - render_text(json, status) - end - - def render_nothing(status = nil) #:nodoc: - render_text(' ', status) - end - - def render_partial(partial_path = default_template_name, object = nil, local_assigns = nil, status = nil) #:nodoc: - add_variables_to_assigns - render_text(@template.send(:render_partial, partial_path, object, local_assigns), status) - end - - def render_partial_collection(partial_name, collection, partial_spacer_template = nil, local_assigns = nil, status = nil) #:nodoc: - add_variables_to_assigns - render_text(@template.send(:render_partial_collection, partial_name, collection, partial_spacer_template, local_assigns), status) - end - - def render_with_layout(template_name = default_template_name, status = nil, layout = nil) #:nodoc: - render_with_a_layout(template_name, status, layout) - end - - def render_without_layout(template_name = default_template_name, status = nil) #:nodoc: - render_with_no_layout(template_name, status) - end - - # Return a response that has no content (merely headers). The options # argument is interpreted to be a hash of header names and values. # This allows you to easily return a response that consists only of @@ -1101,6 +1020,27 @@ module ActionController #:nodoc: end private + + def render_for_file(template_path, status = nil, use_full_path = false, locals = {}) #:nodoc: + add_variables_to_assigns + assert_existence_of_template_file(template_path) if use_full_path + logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger + render_for_text(@template.render_file(template_path, use_full_path, locals), status) + end + + def render_for_text(text = nil, status = nil, append_response = false) #:nodoc: + @performed_render = true + + response.headers['Status'] = interpret_status(status || DEFAULT_RENDER_STATUS_CODE) + + if append_response + response.body ||= '' + response.body << text.to_s + else + response.body = text.is_a?(Proc) ? text : text.to_s + end + end + def initialize_template_class(response) raise "You must assign a template class through ActionController.template_class= before processing a request" unless @@template_class diff --git a/actionpack/lib/action_controller/benchmarking.rb b/actionpack/lib/action_controller/benchmarking.rb index 8e0d83c2d6..31fa5d940d 100644 --- a/actionpack/lib/action_controller/benchmarking.rb +++ b/actionpack/lib/action_controller/benchmarking.rb @@ -43,12 +43,12 @@ module ActionController #:nodoc: protected def render_with_benchmark(options = nil, deprecated_status = nil, &block) unless logger - render_without_benchmark(options, deprecated_status, &block) + render_without_benchmark(options, &block) else db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? render_output = nil - @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, deprecated_status, &block) }.real + @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(options, &block) }.real if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? @db_rt_before_render = db_runtime diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 043b4ea761..3434f5f9da 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -232,7 +232,7 @@ module ActionController #:nodoc: if cache = controller.read_fragment(cache_path.path) controller.rendered_action_cache = true set_content_type!(controller, cache_path.extension) - controller.send(:render_text, cache) + controller.send(:render_for_text, cache) false else controller.action_cache_path = cache_path diff --git a/actionpack/lib/action_controller/components.rb b/actionpack/lib/action_controller/components.rb index 93008ce444..dc3032219b 100644 --- a/actionpack/lib/action_controller/components.rb +++ b/actionpack/lib/action_controller/components.rb @@ -78,7 +78,7 @@ module ActionController #:nodoc: # Renders the component specified as the response for the current method def render_component(options) #:doc: component_logging(options) do - render_text(component_response(options, true).body, response.headers["Status"]) + render_for_text(component_response(options, true).body, response.headers["Status"]) end end diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 027ae42aeb..ff4a4057a2 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -233,29 +233,23 @@ module ActionController #:nodoc: end protected - def render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) #:nodoc: + def render_with_a_layout(options = nil, &block) #:nodoc: template_with_options = options.is_a?(Hash) - if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options, deprecated_layout)) + if apply_layout?(template_with_options, options) && (layout = pick_layout(template_with_options, options)) assert_existence_of_template_file(layout) options = options.merge :layout => false if template_with_options logger.info("Rendering template within #{layout}") if logger - if template_with_options - content_for_layout = render_with_no_layout(options, &block) - deprecated_status = options[:status] || deprecated_status - else - content_for_layout = render_with_no_layout(options, deprecated_status, &block) - end - + content_for_layout = render_with_no_layout(options, &block) erase_render_results add_variables_to_assigns @template.instance_variable_set("@content_for_layout", content_for_layout) response.layout = layout - render_text(@template.render_file(layout, true), deprecated_status) + render_for_text(@template.render_file(layout, true)) else - render_with_no_layout(options, deprecated_status, &block) + render_with_no_layout(options, &block) end end @@ -272,10 +266,8 @@ module ActionController #:nodoc: !template_exempt_from_layout?(default_template_name(options[:action] || options[:template])) end - def pick_layout(template_with_options, options, deprecated_layout) - if deprecated_layout - deprecated_layout - elsif template_with_options + def pick_layout(template_with_options, options) + if template_with_options case layout = options[:layout] when FalseClass nil diff --git a/actionpack/lib/action_controller/rescue.rb b/actionpack/lib/action_controller/rescue.rb index 3ab10107bf..8eb6379fcf 100644 --- a/actionpack/lib/action_controller/rescue.rb +++ b/actionpack/lib/action_controller/rescue.rb @@ -125,7 +125,7 @@ module ActionController #:nodoc: @template.instance_variable_set("@contents", @template.render_file(template_path_for_local_rescue(exception), false)) response.content_type = Mime::HTML - render_file(rescues_path("layout"), response_code_for_rescue(exception)) + render_for_file(rescues_path("layout"), response_code_for_rescue(exception)) end private diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index e26ca499d0..8fb4c3a727 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -103,13 +103,11 @@ module ActionView # As you can see, the :locals hash is shared between both the partial and its layout. module Partials private - # Deprecated, use render :partial - def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns = nil) #:nodoc: + def render_partial(partial_path, object_assigns = nil, local_assigns = nil) #:nodoc: case partial_path when String, Symbol, NilClass path, partial_name = partial_pieces(partial_path) - object = extracting_object(partial_name, local_assigns, deprecated_local_assigns) - local_assigns = extract_local_assigns(local_assigns, deprecated_local_assigns) + object = extracting_object(partial_name, object_assigns) local_assigns = local_assigns ? local_assigns.clone : {} add_counter_to_local_assigns!(partial_name, local_assigns) add_object_to_local_assigns!(partial_name, local_assigns, object) @@ -125,18 +123,17 @@ module ActionView if partial_path.any? path = ActionController::RecordIdentifier.partial_path(partial_path.first) collection = partial_path - render_partial_collection(path, collection, nil, local_assigns.value) + render_partial_collection(path, collection, nil, object_assigns.value) else "" end else render_partial( ActionController::RecordIdentifier.partial_path(partial_path), - local_assigns, deprecated_local_assigns) + object_assigns, local_assigns) end end - # Deprecated, use render :partial, :collection def render_partial_collection(partial_name, collection, partial_spacer_template = nil, local_assigns = nil) #:nodoc: collection_of_partials = Array.new counter_name = partial_counter_name(partial_name) @@ -174,20 +171,15 @@ module ActionView partial_name.split('/').last.split('.').first.intern end - def extracting_object(partial_name, local_assigns, deprecated_local_assigns) + def extracting_object(partial_name, object_assigns) variable_name = partial_variable_name(partial_name) - if local_assigns.is_a?(Hash) || local_assigns.nil? + if object_assigns.nil? controller.instance_variable_get("@#{variable_name}") else - # deprecated form where object could be passed in as second parameter - local_assigns + object_assigns end end - def extract_local_assigns(local_assigns, deprecated_local_assigns) - local_assigns.is_a?(Hash) ? local_assigns : deprecated_local_assigns - end - def add_counter_to_local_assigns!(partial_name, local_assigns) counter_name = partial_counter_name(partial_name) local_assigns[counter_name] = 1 unless local_assigns.has_key?(counter_name) diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 1aefbfd677..75d0e17f61 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -7,10 +7,10 @@ class ActionPackAssertionsController < ActionController::Base def nothing() head :ok end # a standard template - def hello_world() render "test/hello_world"; end + def hello_world() render :template => "test/hello_world"; end # a standard template - def hello_xml_world() render "test/hello_xml_world"; end + def hello_xml_world() render :template => "test/hello_xml_world"; end # a redirect to an internal location def redirect_internal() redirect_to "/nothing"; end @@ -38,13 +38,13 @@ class ActionPackAssertionsController < ActionController::Base # putting stuff in the flash def flash_me flash['hello'] = 'my name is inigo montoya...' - render_text "Inconceivable!" + render :text => "Inconceivable!" end # we have a flash, but nothing is in it def flash_me_naked flash.clear - render_text "wow!" + render :text => "wow!" end # assign some template instance variables @@ -54,11 +54,11 @@ class ActionPackAssertionsController < ActionController::Base end def render_based_on_parameters - render_text "Mr. #{params[:name]}" + render :text => "Mr. #{params[:name]}" end def render_url - render_text "<div>#{url_for(:action => 'flash_me', :only_path => true)}</div>" + render :text => "<div>#{url_for(:action => 'flash_me', :only_path => true)}</div>" end def render_text_with_custom_content_type @@ -68,19 +68,19 @@ class ActionPackAssertionsController < ActionController::Base # puts something in the session def session_stuffing session['xmas'] = 'turkey' - render_text "ho ho ho" + render :text => "ho ho ho" end # raises exception on get requests def raise_on_get raise "get" if request.get? - render_text "request method: #{request.env['REQUEST_METHOD']}" + render :text => "request method: #{request.env['REQUEST_METHOD']}" end # raises exception on post requests def raise_on_post raise "post" if request.post? - render_text "request method: #{request.env['REQUEST_METHOD']}" + render :text => "request method: #{request.env['REQUEST_METHOD']}" end def get_valid_record @@ -310,7 +310,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase process :nothing assert !@response.rendered_with_file? - assert_deprecated(/render/) { process :hello_world } + process :hello_world assert @response.rendered_with_file? assert 'hello_world', @response.rendered_file end @@ -461,13 +461,13 @@ class ActionPackHeaderTest < Test::Unit::TestCase end def test_rendering_xml_sets_content_type - assert_deprecated(/render/) { process :hello_xml_world } + process :hello_xml_world assert_equal('application/xml; charset=utf-8', @response.headers['type']) end def test_rendering_xml_respects_content_type @response.headers['type'] = 'application/pdf' - assert_deprecated(/render/) { process :hello_xml_world } + process :hello_xml_world assert_equal('application/pdf; charset=utf-8', @response.headers['type']) end diff --git a/actionpack/test/controller/components_test.rb b/actionpack/test/controller/components_test.rb index c45a59bdbe..c046cf045a 100644 --- a/actionpack/test/controller/components_test.rb +++ b/actionpack/test/controller/components_test.rb @@ -14,15 +14,15 @@ class CallerController < ActionController::Base end def calling_from_template - render_template "Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>" + render :inline => "Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>" end def internal_caller - render_template "Are you there? <%= render_component(:action => 'internal_callee') %>" + render :inline => "Are you there? <%= render_component(:action => 'internal_callee') %>" end def internal_callee - render_text "Yes, ma'am" + render :text => "Yes, ma'am" end def set_flash @@ -38,7 +38,7 @@ class CallerController < ActionController::Base end def calling_redirected_as_string - render_template "<%= render_component(:controller => 'callee', :action => 'redirected') %>" + render :inline => "<%= render_component(:controller => 'callee', :action => 'redirected') %>" end def rescue_action(e) raise end @@ -46,11 +46,11 @@ end class CalleeController < ActionController::Base def being_called - render_text "#{params[:name] || "Lady"} of the House, speaking" + render :text => "#{params[:name] || "Lady"} of the House, speaking" end def blowing_up - render_text "It's game over, man, just game over, man!", "500 Internal Server Error" + render :text => "It's game over, man, just game over, man!", :status => 500 end def set_flash diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb index 44023b0791..e6b6045af9 100644 --- a/actionpack/test/controller/cookie_test.rb +++ b/actionpack/test/controller/cookie_test.rb @@ -33,7 +33,7 @@ class CookieTest < Test::Unit::TestCase def delete_cookie_with_path cookies.delete("user_name", :path => '/beaten') - render_text "hello world" + render :text => "hello world" end def rescue_action(e) diff --git a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb index 7c6afd358f..6d7157e1a5 100644 --- a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb +++ b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb @@ -2,9 +2,6 @@ require File.dirname(__FILE__) + '/../../abstract_unit' class DeprecatedBaseMethodsTest < Test::Unit::TestCase class Target < ActionController::Base - def deprecated_render_parameters - render "fun/games/hello_world" - end def home_url(greeting) "http://example.com/#{greeting}" @@ -25,14 +22,6 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase @controller = Target.new end - def test_deprecated_render_parameters - assert_deprecated("render('fun/games/hello_world')") do - get :deprecated_render_parameters - end - - assert_equal "Living in a nested world", @response.body - end - def test_log_error_silences_deprecation_warnings get :raises_name_error rescue => e diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 8adee4c12f..56aabddd31 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -234,7 +234,7 @@ class FilterTest < Test::Unit::TestCase before_filter(AuditFilter) def show - render_text "hello" + render :text => "hello" end end @@ -271,11 +271,11 @@ class FilterTest < Test::Unit::TestCase before_filter :second, :only => :foo def foo - render_text 'foo' + render :text => 'foo' end def bar - render_text 'bar' + render :text => 'bar' end protected diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb index ce254cbf0d..0ef8ce141b 100644 --- a/actionpack/test/controller/new_render_test.rb +++ b/actionpack/test/controller/new_render_test.rb @@ -152,7 +152,15 @@ class NewRenderTestController < ActionController::Base def partial_with_hash_object render :partial => "hash_object", :object => {:first_name => "Sam"} end - + + def partial_hash_collection + render :partial => "hash_object", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ] + end + + def partial_hash_collection_with_locals + render :partial => "hash_greeting", :collection => [ {:first_name => "Pratik"}, {:first_name => "Amy"} ], :locals => { :greeting => "Hola" } + end + def partial_with_implicit_local_assignment @customer = Customer.new("Marcel") render :partial => "customer" @@ -164,7 +172,7 @@ class NewRenderTestController < ActionController::Base def hello_in_a_string @customers = [ Customer.new("david"), Customer.new("mary") ] - render :text => "How's there? #{render_to_string("test/list")}" + render :text => "How's there? " << render_to_string(:template => "test/list") end def render_to_string_with_assigns @@ -203,7 +211,7 @@ class NewRenderTestController < ActionController::Base end def render_with_explicit_template - render "test/hello_world" + render :template => "test/hello_world" end def double_render @@ -622,7 +630,7 @@ EOS end def test_render_with_explicit_template - assert_deprecated(/render/) { get :render_with_explicit_template } + get :render_with_explicit_template assert_response :success end @@ -683,6 +691,16 @@ EOS get :partial_with_hash_object assert_equal "Sam", @response.body end + + def test_hash_partial_collection + get :partial_hash_collection + assert_equal "PratikAmy", @response.body + end + + def test_partial_hash_collection_with_locals + get :partial_hash_collection_with_locals + assert_equal "Hola: PratikHola: Amy", @response.body + end def test_partial_with_implicit_local_assignment get :partial_with_implicit_local_assignment diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index b6cbe7f924..3b755eb6a6 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -16,32 +16,32 @@ class TestController < ActionController::Base end def render_hello_world - render "test/hello_world" + render :template => "test/hello_world" end def render_hello_world_from_variable @person = "david" - render_text "hello #{@person}" + render :text => "hello #{@person}" end def render_action_hello_world - render_action "hello_world" + render :action => "hello_world" end def render_action_hello_world_with_symbol - render_action :hello_world + render :action => :hello_world end def render_text_hello_world - render_text "hello world" + render :text => "hello world" end def render_json_hello_world - render_json({:hello => 'world'}.to_json) + render :json => {:hello => 'world'}.to_json end def render_json_hello_world_with_callback - render_json({:hello => 'world'}.to_json, 'alert') + render :json => {:hello => 'world'}.to_json, :callback => 'alert' end def render_symbol_json @@ -49,21 +49,20 @@ class TestController < ActionController::Base end def render_custom_code - render_text "hello world", "404 Moved" - end - - def render_text_appendix - render_text "hello world" - render_text ", goodbye!", "404 Not Found", true + render :text => "hello world", :status => 404 end def render_nothing_with_appendix - render_text "appended", nil, true + render :text => "appended" + end + + def render_invalid_args + render("test/hello") end def render_xml_hello @name = "David" - render "test/hello" + render :template => "test/hello" end def heading @@ -75,34 +74,34 @@ class TestController < ActionController::Base end def layout_test - render_action "hello_world" + render :action => "hello_world" end def builder_layout_test - render_action "hello" + render :action => "hello" end def builder_partial_test - render_action "hello_world_container" + render :action => "hello_world_container" end def partials_list @test_unchanged = 'hello' @customers = [ Customer.new("david"), Customer.new("mary") ] - render_action "list" + render :action => "list" end def partial_only - render_partial + render :partial => true end def hello_in_a_string @customers = [ Customer.new("david"), Customer.new("mary") ] - render_text "How's there? #{render_to_string("test/list")}" + render :text => "How's there? " + render_to_string(:template => "test/list") end def accessing_params_in_template - render_template "Hello: <%= params[:name] %>" + render :inline => "Hello: <%= params[:name] %>" end def accessing_local_assigns_in_inline_template @@ -184,7 +183,7 @@ class RenderTest < Test::Unit::TestCase end def test_do_with_render - assert_deprecated_render { get :render_hello_world } + get :render_hello_world assert_template "test/hello_world" end @@ -229,12 +228,7 @@ class RenderTest < Test::Unit::TestCase def test_do_with_render_custom_code get :render_custom_code assert_response 404 - end - - def test_do_with_render_text_appendix - get :render_text_appendix - assert_response 404 - assert_equal 'hello world, goodbye!', @response.body + assert_equal 'hello world', @response.body end def test_do_with_render_nothing_with_appendix @@ -242,7 +236,11 @@ class RenderTest < Test::Unit::TestCase assert_response 200 assert_equal 'appended', @response.body end - + + def test_attempt_to_render_with_invalid_arguments + assert_raises(ActionController::RenderError) { get :render_invalid_args } + end + def test_attempt_to_access_object_method assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone } end @@ -252,7 +250,7 @@ class RenderTest < Test::Unit::TestCase end def test_render_xml - assert_deprecated_render { get :render_xml_hello } + get :render_xml_hello assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body end @@ -416,10 +414,7 @@ class RenderTest < Test::Unit::TestCase end protected - def assert_deprecated_render(&block) - assert_deprecated(/render/, &block) - end - + def etag_for(text) %("#{Digest::MD5.hexdigest(text)}") end diff --git a/actionpack/test/controller/session_management_test.rb b/actionpack/test/controller/session_management_test.rb index 63917565ef..44fb93104c 100644 --- a/actionpack/test/controller/session_management_test.rb +++ b/actionpack/test/controller/session_management_test.rb @@ -5,11 +5,11 @@ class SessionManagementTest < Test::Unit::TestCase session :off def show - render_text "done" + render :text => "done" end def tell - render_text "done" + render :text => "done" end end @@ -20,15 +20,15 @@ class SessionManagementTest < Test::Unit::TestCase :if => Proc.new { |r| r.parameters[:ws] } def show - render_text "done" + render :text => "done" end def tell - render_text "done" + render :text => "done" end def conditional - render_text ">>>#{params[:ws]}<<<" + render :text => ">>>#{params[:ws]}<<<" end end @@ -36,11 +36,11 @@ class SessionManagementTest < Test::Unit::TestCase session :disabled => false, :only => :something def something - render_text "done" + render :text => "done" end def another - render_text "done" + render :text => "done" end end diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb index c84ced5394..67048e76b0 100644 --- a/actionpack/test/controller/view_paths_test.rb +++ b/actionpack/test/controller/view_paths_test.rb @@ -20,7 +20,7 @@ class ViewLoadPathsTest < Test::Unit::TestCase class Test::SubController < ActionController::Base layout 'test/sub' - def hello_world; render 'test/hello_world'; end + def hello_world; render(:template => 'test/hello_world'); end end def setup diff --git a/actionpack/test/fixtures/test/_hash_greeting.erb b/actionpack/test/fixtures/test/_hash_greeting.erb new file mode 100644 index 0000000000..fc54a36f2a --- /dev/null +++ b/actionpack/test/fixtures/test/_hash_greeting.erb @@ -0,0 +1 @@ +<%= greeting %>: <%= hash_greeting[:first_name] %>
\ No newline at end of file |