aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2010-10-26 14:27:18 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2010-10-26 14:27:18 +0100
commit4ba24ba043a00e61e97369e6664d5c0fcdbc0fe8 (patch)
tree1ed823580f576b96d747febd507442d053c55f40 /actionpack
parentc40074c1c7253f89ca9daf69b1a61068a478f144 (diff)
downloadrails-4ba24ba043a00e61e97369e6664d5c0fcdbc0fe8.tar.gz
rails-4ba24ba043a00e61e97369e6664d5c0fcdbc0fe8.tar.bz2
rails-4ba24ba043a00e61e97369e6664d5c0fcdbc0fe8.zip
Allow generated url helpers to be overriden [#5243 state:resolved]
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb10
-rw-r--r--actionpack/test/template/url_helper_test.rb18
2 files changed, 23 insertions, 5 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index 1c63fb2d14..475785a4b4 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -46,14 +46,14 @@ module AbstractController
@view_context_class ||= begin
controller = self
Class.new(ActionView::Base) do
+ if controller.respond_to?(:_routes) && controller._routes
+ include controller._routes.url_helpers
+ include controller._routes.mounted_helpers
+ end
+
if controller.respond_to?(:_helpers)
include controller._helpers
- if controller.respond_to?(:_routes) && controller._routes
- include controller._routes.url_helpers
- include controller._routes.mounted_helpers
- end
-
# TODO: Fix RJS to not require this
self.helpers = controller._helpers
end
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index a6fdf806a4..bc2548e06c 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -433,6 +433,10 @@ class UrlHelperControllerTest < ActionController::TestCase
match 'url_helper_controller_test/url_helper/normalize_recall_params',
:to => UrlHelperController.action(:normalize_recall),
:as => :normalize_recall_params
+
+ match '/url_helper_controller_test/url_helper/override_url_helper/default',
+ :to => 'url_helper_controller_test/url_helper#override_url_helper',
+ :as => :override_url_helper
end
def show
@@ -468,6 +472,15 @@ class UrlHelperControllerTest < ActionController::TestCase
end
def rescue_action(e) raise e end
+
+ def override_url_helper
+ render :inline => '<%= override_url_helper_path %>'
+ end
+
+ def override_url_helper_path
+ '/url_helper_controller_test/url_helper/override_url_helper/override'
+ end
+ helper_method :override_url_helper_path
end
tests UrlHelperController
@@ -527,6 +540,11 @@ class UrlHelperControllerTest < ActionController::TestCase
get :show, :name => '123'
assert_equal 'ok', @response.body
end
+
+ def test_url_helper_can_be_overriden
+ get :override_url_helper
+ assert_equal '/url_helper_controller_test/url_helper/override_url_helper/override', @response.body
+ end
end
class TasksController < ActionController::Base