Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented RouteSet#default_scope, which allows to set the scope for…

… the entire routes object
  • Loading branch information...
commit b8d6dc3c84321c751ab2ca8232e1e3fb332a844c 1 parent b43b686
Piotr Sarnacki drogus authored
6 actionpack/lib/action_dispatch/routing/mapper.rb
View
@@ -274,6 +274,12 @@ def default_url_options=(options)
end
alias_method :default_url_options, :default_url_options=
+ def with_default_scope(scope, &block)
+ scope(scope) do
+ instance_exec(&block)
+ end
+ end
+
private
def app_name(app)
return unless app.respond_to?(:routes)
8 actionpack/lib/action_dispatch/routing/route_set.rb
View
@@ -199,7 +199,7 @@ def #{selector}(*args)
end
end
- attr_accessor :set, :routes, :named_routes
+ attr_accessor :set, :routes, :named_routes, :default_scope
attr_accessor :disable_clear_and_finalize, :resources_path_names
attr_accessor :default_url_options, :request_class, :valid_conditions
@@ -230,7 +230,11 @@ def draw(&block)
if block.arity == 1
mapper.instance_exec(DeprecatedMapper.new(self), &block)
else
- mapper.instance_exec(&block)
+ if default_scope
+ mapper.with_default_scope(default_scope, &block)
+ else
+ mapper.instance_exec(&block)
+ end
end
finalize! unless @disable_clear_and_finalize
29 actionpack/test/dispatch/routing_test.rb
View
@@ -2151,3 +2151,32 @@ def expected_redirect_body(url)
%(<html><body>You are being <a href="#{ERB::Util.h(url)}">redirected</a>.</body></html>)
end
end
+
+
+class TestDefaultScope < ActionController::IntegrationTest
+ module ::Blog
+ class PostsController < ActionController::Base
+ def index
+ render :text => "blog/posts#index"
+ end
+ end
+ end
+
+ DefaultScopeRoutes = ActionDispatch::Routing::RouteSet.new
+ DefaultScopeRoutes.default_scope = {:module => :blog}
+ DefaultScopeRoutes.draw do
+ resources :posts
+ end
+
+ def app
+ DefaultScopeRoutes
+ end
+
+ include DefaultScopeRoutes.url_helpers
+
+ def test_default_scope
+ get '/posts'
+ assert_equal "blog/posts#index", @response.body
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.