Skip to content
Browse files

Allow view in AV::TestCase to access it's controller helpers methods

  • Loading branch information...
1 parent f870003 commit 6062d434f174c84a18a121b025dcf4f11d6689f1 @spastorino spastorino committed
Showing with 22 additions and 0 deletions.
  1. +1 −0 actionpack/lib/action_view/test_case.rb
  2. +21 −0 actionpack/test/template/test_case_test.rb
View
1 actionpack/lib/action_view/test_case.rb
@@ -157,6 +157,7 @@ def _render_partial(options)
def view
@view ||= begin
view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller)
+ view.singleton_class.send :include, @controller._helpers
view.singleton_class.send :include, _helpers
view.singleton_class.send :include, @controller._routes.url_helpers
view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
View
21 actionpack/test/template/test_case_test.rb
@@ -116,6 +116,27 @@ def render_from_helper
end
end
+ class ControllerHelperMethod < ActionView::TestCase
+ module SomeHelper
+ def some_method
+ render :partial => 'test/from_helper'
+ end
+ end
+
+ helper SomeHelper
+
+ test "can call a helper method defined on the current controller from a helper" do
+ @controller.singleton_class.class_eval <<-EOF, __FILE__, __LINE__ + 1
+ def render_from_helper
+ 'controller_helper_method'
+ end
+ EOF
+ @controller.class.helper_method :render_from_helper
+
+ assert_equal 'controller_helper_method', some_method
+ end
+ end
+
class AssignsTest < ActionView::TestCase
setup do
ActiveSupport::Deprecation.stubs(:warn)

0 comments on commit 6062d43

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