Permalink
Browse files

Memoize the object returned by _view in ActionView::TestCase::Behavior

[#4799 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent ab2877c commit bdcf70cca89df906a3510464ef46a44646fd29a3 @dchelimsky dchelimsky committed with josevalim Jun 8, 2010
Showing with 12 additions and 6 deletions.
  1. +8 −6 actionpack/lib/action_view/test_case.rb
  2. +4 −0 actionpack/test/template/test_case_test.rb
@@ -131,12 +131,14 @@ def make_test_case_available_to_view!
end
def _view
- view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @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.output_buffer = self.output_buffer
- view
+ @_view ||= begin
+ view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @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.output_buffer = self.output_buffer
+ view
+ end
end
EXCLUDE_IVARS = %w{
@@ -37,6 +37,10 @@ class GeneralViewTest < ActionView::TestCase
include SharedTests
test_case = self
+ test "memoizes the _view" do
+ assert_same _view, _view
+ end
+
test "works without testing a helper module" do
assert_equal 'Eloy', render('developers/developer', :developer => stub(:name => 'Eloy'))
end

0 comments on commit bdcf70c

Please sign in to comment.