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>
This commit is contained in:
parent
e8c064bbe0
commit
0e0df4b0c5
|
@ -204,8 +204,12 @@ module ActionView #:nodoc:
|
|||
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
|
||||
|
|
|
@ -99,6 +99,7 @@ module ActionView
|
|||
end
|
||||
|
||||
def render(options = {}, local_assigns = {}, &block)
|
||||
_view.assign(_assigns)
|
||||
@rendered << output = _view.render(options, local_assigns, &block)
|
||||
output
|
||||
end
|
||||
|
@ -147,7 +148,7 @@ module ActionView
|
|||
|
||||
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"
|
||||
|
|
|
@ -200,6 +200,15 @@ module ActionView
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue