aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb1
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/routing.rb18
-rw-r--r--actionpack/lib/action_view/base.rb4
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb7
-rw-r--r--actionpack/lib/action_view/test_case.rb3
5 files changed, 29 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 048764263e..5537bbbbe8 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -222,7 +222,6 @@ module ActionDispatch
return if @finalized
@finalized = true
@set.add_route(NotFound)
- install_helpers
@set.freeze
end
diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb
index 1d7e8090e4..eb28cd5107 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb
@@ -145,11 +145,25 @@ module ActionDispatch
old_routes, @router = @router, ActionDispatch::Routing::RouteSet.new
old_controller, @controller = @controller, @controller.clone if @controller
_router = @router
- @controller.singleton_class.send(:send, :include, @router.url_helpers) if @controller
+
+ # Unfortunately, there is currently an abstraction leak between AC::Base
+ # and AV::Base which requires having the URL helpers in both AC and AV.
+ # To do this safely at runtime for tests, we need to bump up the helper serial
+ # to that the old AV subclass isn't cached.
+ #
+ # TODO: Make this unnecessary
+ if @controller
+ @controller.singleton_class.send(:include, @router.url_helpers)
+ @controller.class._helper_serial += 1
+ @controller.view_context.singleton_class.send(:include, @router.url_helpers)
+ end
yield @router
ensure
@router = old_routes
- @controller = old_controller if @controller
+ if @controller
+ @controller = old_controller
+ @controller.class._helper_serial += 1 if @controller
+ end
end
# ROUTES TODO: These assertions should really work in an integration context
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 3920d8593f..daabe6d196 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -235,6 +235,10 @@ module ActionView #:nodoc:
include controller._helpers
self.helpers = controller._helpers
end
+
+ if controller.respond_to?(:_router)
+ include controller._router.url_helpers
+ end
end
else
klass = self
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index 94f1cecade..f877378ebe 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -9,6 +9,9 @@ module ActionView
# This allows you to use the same format for links in views
# and controllers.
module UrlHelper
+ extend ActiveSupport::Concern
+
+ include ActionDispatch::Routing::UrlFor
include JavaScriptHelper
# Need to map default url options to controller one.
@@ -16,6 +19,10 @@ module ActionView
controller.send(:default_url_options, *args)
end
+ def url_options
+ controller.url_options
+ end
+
# Returns the URL for the set of +options+ provided. This takes the
# same options as +url_for+ in Action Controller (see the
# documentation for <tt>ActionController::Base#url_for</tt>). Note that by default
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb
index 1578ac9479..7e609eb640 100644
--- a/actionpack/lib/action_view/test_case.rb
+++ b/actionpack/lib/action_view/test_case.rb
@@ -124,7 +124,8 @@ module ActionView
def _view
view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
- view.class.send :include, _helpers
+ view.singleton_class.send :include, _helpers
+ view.singleton_class.send :include, @controller._router.url_helpers
view.output_buffer = self.output_buffer
view
end