Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@dchelimsky dchelimsky authored josevalim committed
View
6 actionpack/lib/action_view/base.rb
@@ -204,8 +204,12 @@ def self.process_view_paths(value)
value.dup : ActionView::PathSet.new(Array.wrap(value))
end
+ def assign(new_assigns) # :nodoc:
+ self.assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
+ end
+
def initialize(lookup_context = nil, assigns_for_first_render = {}, controller = nil, formats = nil) #:nodoc:
- self.assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) }
+ assign(assigns_for_first_render)
self.helpers = self.class.helpers || Module.new
if @_controller = controller
View
3  actionpack/lib/action_view/test_case.rb
@@ -99,6 +99,7 @@ def config
end
def render(options = {}, local_assigns = {}, &block)
+ _view.assign(_assigns)
@rendered << output = _view.render(options, local_assigns, &block)
output
end
@@ -147,7 +148,7 @@ def _render_partial(options)
def _view
@_view ||= begin
- view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
+ view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller)
view.singleton_class.send :include, _helpers
view.singleton_class.send :include, @controller._router.url_helpers
view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
View
9 actionpack/test/template/test_case_test.rb
@@ -200,6 +200,15 @@ def render_from_helper
assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
end
+ test "is able to render partials from templates and also use instance variables after _view has been referenced" do
+ @controller.controller_path = "test"
+
+ _view
+
+ @customers = [stub(:name => 'Eloy'), stub(:name => 'Manfred')]
+ assert_match /Hello: EloyHello: Manfred/, render(:file => 'test/list')
+ end
+
end
class AssertionsTest < ActionView::TestCase
Please sign in to comment.
Something went wrong with that request. Please try again.