diff options
author | David Chelimsky <dchelimsky@gmail.com> | 2010-06-23 07:59:56 -0500 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-23 15:07:44 +0200 |
commit | 0e0df4b0c5df7fdd1daa5653c255c4737f5526fc (patch) | |
tree | 76d9f89cdfc19949736f744af0ef7a9dfe9f2720 /actionpack/lib/action_view | |
parent | e8c064bbe0fb5e07c7ceaa45d0cafa3c4ef01ab0 (diff) | |
download | rails-0e0df4b0c5df7fdd1daa5653c255c4737f5526fc.tar.gz rails-0e0df4b0c5df7fdd1daa5653c255c4737f5526fc.tar.bz2 rails-0e0df4b0c5df7fdd1daa5653c255c4737f5526fc.zip |
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>
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/action_view/test_case.rb | 3 |
2 files changed, 7 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index a7ba9f374a..50df1c97b2 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -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 diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 00c7386d23..5abc59507f 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -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" |