From c0a372ba87f556769b98a6d06e8c684c3c3156df Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 28 Apr 2009 23:29:29 -0500 Subject: Deprecate template, session, assigns, and layout accessors on response object. Instead access them through the controller instance. This mainly affects functional test assertions. --- actionpack/lib/action_controller/base/base.rb | 4 +++- actionpack/lib/action_controller/base/mime_responds.rb | 2 +- actionpack/lib/action_controller/caching/actions.rb | 2 +- .../lib/action_controller/testing/assertions/response.rb | 10 +++++----- actionpack/lib/action_controller/testing/process.rb | 13 ++++++++----- 5 files changed, 18 insertions(+), 13 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/base/base.rb b/actionpack/lib/action_controller/base/base.rb index 2063df54b4..14c4339c94 100644 --- a/actionpack/lib/action_controller/base/base.rb +++ b/actionpack/lib/action_controller/base/base.rb @@ -367,6 +367,8 @@ module ActionController #:nodoc: # Returns the name of the action this controller is processing. attr_accessor :action_name + attr_reader :template + class << self def call(env) # HACK: For global rescue to have access to the original request and response @@ -816,7 +818,7 @@ module ActionController #:nodoc: def initialize_template_class(response) @template = response.template = ActionView::Base.new(self.class.view_paths, {}, self, formats) - response.template.helpers.send :include, self.class.master_helper_module + @template.helpers.send :include, self.class.master_helper_module response.redirected_to = nil @performed_render = @performed_redirect = false end diff --git a/actionpack/lib/action_controller/base/mime_responds.rb b/actionpack/lib/action_controller/base/mime_responds.rb index bac225ab2a..1003e61a0b 100644 --- a/actionpack/lib/action_controller/base/mime_responds.rb +++ b/actionpack/lib/action_controller/base/mime_responds.rb @@ -127,7 +127,7 @@ module ActionController #:nodoc: @order << mime_type @responses[mime_type] ||= Proc.new do - @response.template.formats = [mime_type.to_sym] + @controller.template.formats = [mime_type.to_sym] @response.content_type = mime_type.to_s block_given? ? block.call : @controller.send(:render, :action => @controller.action_name) end diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index b99feddf77..d95a346862 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -121,7 +121,7 @@ module ActionController #:nodoc: end def content_for_layout(controller) - controller.response.layout && controller.response.template.instance_variable_get('@cached_content_for_layout') + controller.template.layout && controller.template.instance_variable_get('@cached_content_for_layout') end end diff --git a/actionpack/lib/action_controller/testing/assertions/response.rb b/actionpack/lib/action_controller/testing/assertions/response.rb index a4a3dcdec8..684fe1ffe0 100644 --- a/actionpack/lib/action_controller/testing/assertions/response.rb +++ b/actionpack/lib/action_controller/testing/assertions/response.rb @@ -33,7 +33,7 @@ module ActionController assert_block("") { true } # to count the assertion else if @controller && @response.error? - exception = @controller.response.template.instance_variable_get(:@exception) + exception = @controller.template.instance_variable_get(:@exception) exception_message = exception && exception.message assert_block(build_message(message, "Expected response to be a , but was \n", type, @response.response_code, exception_message.to_s)) { false } else @@ -98,20 +98,20 @@ module ActionController clean_backtrace do case options when NilClass, String - rendered = (@controller.response.rendered[:template] || []).map { |t| t.identifier } + rendered = (@controller.template.rendered[:template] || []).map { |t| t.identifier } msg = build_message(message, "expecting but rendering with ", options, rendered.join(', ')) assert_block(msg) do if options.nil? - @controller.response.rendered[:template].blank? + @controller.template.rendered[:template].blank? else rendered.any? { |t| t.match(options) } end end when Hash if expected_partial = options[:partial] - partials = @controller.response.rendered[:partials] + partials = @controller.template.rendered[:partials] if expected_count = options[:count] found = partials.detect { |p, _| p.identifier.match(expected_partial) } actual_count = found.nil? ? 0 : found.second @@ -126,7 +126,7 @@ module ActionController assert(partials.keys.any? { |p| p.identifier.match(expected_partial) }, msg) end else - assert @controller.response.rendered[:partials].empty?, + assert @controller.template.rendered[:partials].empty?, "Expected no partials to be rendered" end end diff --git a/actionpack/lib/action_controller/testing/process.rb b/actionpack/lib/action_controller/testing/process.rb index d073d06b19..16a8f66bc4 100644 --- a/actionpack/lib/action_controller/testing/process.rb +++ b/actionpack/lib/action_controller/testing/process.rb @@ -160,7 +160,8 @@ module ActionController #:nodoc: # Returns the template of the file which was used to # render this response (or nil) def rendered - template.instance_variable_get(:@_rendered) + ActiveSupport::Deprecation.warn("response.rendered has been deprecated. Use tempate.rendered instead", caller) + @template.instance_variable_get(:@_rendered) end # A shortcut to the flash. Returns an empty hash if no session flash exists. @@ -190,11 +191,13 @@ module ActionController #:nodoc: # A shortcut to the template.assigns def template_objects - template.assigns || {} + ActiveSupport::Deprecation.warn("response.template_objects has been deprecated. Use tempate.assigns instead", caller) + @template.assigns || {} end # Does the specified template object exist? def has_template_object?(name=nil) + ActiveSupport::Deprecation.warn("response.has_template_object? has been deprecated. Use tempate.assigns[name].nil? instead", caller) !template_objects[name].nil? end @@ -317,9 +320,9 @@ module ActionController #:nodoc: def assigns(key = nil) if key.nil? - @response.template.assigns + @controller.template.assigns else - @response.template.assigns[key.to_s] + @controller.template.assigns[key.to_s] end end @@ -431,7 +434,7 @@ module ActionController #:nodoc: (instance_variable_names - self.class.protected_instance_variables).each do |var| name, value = var[1..-1], instance_variable_get(var) @assigns[name] = value - response.template.assigns[name] = value if response + @template.assigns[name] = value if response end end end -- cgit v1.2.3