diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-10-11 05:40:53 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-10-11 05:40:53 -0700 |
commit | 888a7a5bdc10bf5e2aceaad1cd40979a2388e4c0 (patch) | |
tree | 45e598b462d05a71b6a0e85c25a4608946462a58 /actionpack/lib/action_view | |
parent | eec8924277a481b8d703913b688bc65ffcbad707 (diff) | |
parent | d6524d78687b39c72e0814e61b80e3e6b6d9997e (diff) | |
download | rails-888a7a5bdc10bf5e2aceaad1cd40979a2388e4c0.tar.gz rails-888a7a5bdc10bf5e2aceaad1cd40979a2388e4c0.tar.bz2 rails-888a7a5bdc10bf5e2aceaad1cd40979a2388e4c0.zip |
Merge pull request #7886 from senny/3675_assert_template_twice_against_same_partial
assert_template works when the same partial was rendered multiple times
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/test_case.rb | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 5434b3421e..a548b44780 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -119,8 +119,29 @@ module ActionView output end - def locals - @locals ||= {} + def rendered_views + @_rendered_views ||= RenderedViewsCollection.new + end + + class RenderedViewsCollection + def initialize + @rendered_views ||= {} + end + + def add(view, locals) + @rendered_views[view] ||= [] + @rendered_views[view] << locals + end + + def locals_for(view) + @rendered_views[view] + end + + def view_rendered?(view, expected_locals) + locals_for(view).any? do |actual_locals| + expected_locals.all? {|key, value| value == actual_locals[key] } + end + end end included do @@ -156,18 +177,18 @@ module ActionView end module Locals - attr_accessor :locals + attr_accessor :rendered_views def render(options = {}, local_assigns = {}) case options when Hash if block_given? - locals[options[:layout]] = options[:locals] + rendered_views.add options[:layout], options[:locals] elsif options.key?(:partial) - locals[options[:partial]] = options[:locals] + rendered_views.add options[:partial], options[:locals] end else - locals[options] = local_assigns + rendered_views.add options, local_assigns end super @@ -180,7 +201,7 @@ module ActionView view = @controller.view_context view.singleton_class.send :include, _helpers view.extend(Locals) - view.locals = self.locals + view.rendered_views = self.rendered_views view.output_buffer = self.output_buffer view end @@ -197,7 +218,7 @@ module ActionView :@_routes, :@controller, :@_layouts, - :@locals, + :@_rendered_views, :@method_name, :@output_buffer, :@_partials, |