diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-03-17 16:28:05 -0700 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-03-17 16:29:35 -0700 |
commit | d9375f3f302a5d1856ad57946c7263d4e6a45a2a (patch) | |
tree | 76769a45da7b1315df173976067ff37edcb59b49 /actionpack/lib | |
parent | 7872fa9a4397c450ee22c511966e149d594d153e (diff) | |
download | rails-d9375f3f302a5d1856ad57946c7263d4e6a45a2a.tar.gz rails-d9375f3f302a5d1856ad57946c7263d4e6a45a2a.tar.bz2 rails-d9375f3f302a5d1856ad57946c7263d4e6a45a2a.zip |
Modify assert_template to use notifications. Also, remove ActionController::Base#template since it is no longer needed.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal/compatibility.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 20 | ||||
-rw-r--r-- | actionpack/lib/action_view/base.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/prototype_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/render/rendering.rb | 3 | ||||
-rw-r--r-- | actionpack/lib/action_view/test_case.rb | 4 |
6 files changed, 32 insertions, 15 deletions
diff --git a/actionpack/lib/action_controller/metal/compatibility.rb b/actionpack/lib/action_controller/metal/compatibility.rb index ab8d87b2c4..e6cea483bb 100644 --- a/actionpack/lib/action_controller/metal/compatibility.rb +++ b/actionpack/lib/action_controller/metal/compatibility.rb @@ -40,15 +40,6 @@ module ActionController def initialize_template_class(*) end def assign_shortcuts(*) end - def template - @template ||= view_context - end - - def process_action(*) - template - super - end - def _normalize_options(options) if options[:action] && options[:action].to_s.include?(?/) ActiveSupport::Deprecation.warn "Giving a path to render :action is deprecated. " << diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 330b950d7c..8ab0c32a9e 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -13,6 +13,13 @@ module ActionController def setup_subscriptions @partials = Hash.new(0) @templates = Hash.new(0) + @layouts = Hash.new(0) + + ActiveSupport::Notifications.subscribe("action_view.render_template") do |name, start, finish, id, payload| + path = payload[:layout] + @layouts[path] += 1 + end + ActiveSupport::Notifications.subscribe("action_view.render_template!") do |name, start, finish, id, payload| path = payload[:virtual_path] next unless path @@ -69,6 +76,19 @@ module ActionController "expecting ? to be rendered ? time(s) but rendered ? time(s)", expected_partial, expected_count, actual_count) assert(actual_count == expected_count.to_i, msg) + elsif options.key?(:layout) + msg = build_message(message, + "expecting layout <?> but action rendered <?>", + expected_layout, @layouts.keys) + + case layout = options[:layout] + when String + assert(@layouts.include?(expected_layout), msg) + when Regexp + assert(@layouts.any? {|l| l =~ layout }, msg) + when nil + assert(@layouts.empty?, msg) + end else msg = build_message(message, "expecting partial <?> but action rendered <?>", diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 326b79f9bf..4d9f53cf95 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -196,7 +196,7 @@ module ActionView #:nodoc: end attr_accessor :base_path, :assigns, :template_extension, :lookup_context - attr_internal :captures, :request, :layout, :controller, :template, :config + attr_internal :captures, :request, :controller, :template, :config delegate :find_template, :template_exists?, :formats, :formats=, :locale, :locale=, :view_paths, :view_paths=, :with_fallbacks, :update_details, :to => :lookup_context @@ -206,6 +206,11 @@ module ActionView #:nodoc: delegate :logger, :to => :controller, :allow_nil => true + # TODO: HACK FOR RJS + def view_context + self + end + def self.xss_safe? #:nodoc: true end @@ -254,7 +259,7 @@ module ActionView #:nodoc: @helpers = self.class.helpers || Module.new @_controller = controller - @_config = ActiveSupport::InheritableOptions.new(controller.config) if controller + @_config = ActiveSupport::InheritableOptions.new(controller.config) if controller && controller.respond_to?(:config) @_content_for = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new } @_virtual_path = nil diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 2e5fe5744e..aba2565c67 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -582,7 +582,7 @@ module ActionView # page.hide 'spinner' # end def update_page(&block) - JavaScriptGenerator.new(@template, &block).to_s.html_safe + JavaScriptGenerator.new(view_context, &block).to_s.html_safe end # Works like update_page but wraps the generated JavaScript in a <script> diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index d8dfd5077b..b0fed556c3 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -53,13 +53,12 @@ module ActionView layout = find_layout(layout) if layout ActiveSupport::Notifications.instrument("action_view.render_template", - :identifier => template.identifier, :layout => layout.try(:identifier)) do + :identifier => template.identifier, :layout => layout.try(:virtual_path)) do content = template.render(self, locals) { |*name| _layout_for(*name) } @_content_for[:layout] = content if layout - @_layout = layout.identifier content = _render_layout(layout, locals) end diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 1c69c23bfc..b0ababe344 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -4,6 +4,8 @@ require 'action_view' module ActionView class TestCase < ActiveSupport::TestCase class TestController < ActionController::Base + include ActionDispatch::TestProcess + attr_accessor :request, :response, :params def self.controller_path @@ -44,7 +46,7 @@ module ActionView end def config - @controller.config + @controller.config if @controller.respond_to?(:config) end def render(options = {}, local_assigns = {}, &block) |