Skip to content
This repository
Browse code

In ActionView::TestCase::Behavior, assign variables right before

rendering the view.

- Previously, _assigns were locked down the first time _view was
  referenced.

[#4931 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 0e0df4b0c5df7fdd1daa5653c255c4737f5526fc 1 parent e8c064b
David Chelimsky authored June 23, 2010 josevalim committed June 23, 2010
6  actionpack/lib/action_view/base.rb
@@ -204,8 +204,12 @@ def self.process_view_paths(value)
204 204
         value.dup : ActionView::PathSet.new(Array.wrap(value))
205 205
     end
206 206
 
  207
+    def assign(new_assigns) # :nodoc:
  208
+      self.assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
  209
+    end
  210
+
207 211
     def initialize(lookup_context = nil, assigns_for_first_render = {}, controller = nil, formats = nil) #:nodoc:
208  
-      self.assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) }
  212
+      assign(assigns_for_first_render)
209 213
       self.helpers = self.class.helpers || Module.new
210 214
 
211 215
       if @_controller = controller
3  actionpack/lib/action_view/test_case.rb
@@ -99,6 +99,7 @@ def config
99 99
       end
100 100
 
101 101
       def render(options = {}, local_assigns = {}, &block)
  102
+        _view.assign(_assigns)
102 103
         @rendered << output = _view.render(options, local_assigns, &block)
103 104
         output
104 105
       end
@@ -147,7 +148,7 @@ def _render_partial(options)
147 148
 
148 149
       def _view
149 150
         @_view ||= begin
150  
-                     view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
  151
+                     view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller)
151 152
                      view.singleton_class.send :include, _helpers
152 153
                      view.singleton_class.send :include, @controller._router.url_helpers
153 154
                      view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
9  actionpack/test/template/test_case_test.rb
@@ -200,6 +200,15 @@ def render_from_helper
200 200
       assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
201 201
     end
202 202
 
  203
+    test "is able to render partials from templates and also use instance variables after _view has been referenced" do
  204
+      @controller.controller_path = "test"
  205
+
  206
+      _view
  207
+
  208
+      @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
  209
+      assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
  210
+    end
  211
+
203 212
   end
204 213
 
205 214
   class AssertionsTest < ActionView::TestCase

0 notes on commit 0e0df4b

Please sign in to comment.
Something went wrong with that request. Please try again.