aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-24 11:06:06 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-24 11:06:06 +0100
commite0bdc4f446686a498c3117e27ed8561f5c6d34f1 (patch)
tree3b702991c7abdcdf5827b02b70fdfd59f1573e97 /railties
parent5cd9aad4fdf55c591fe8e12657008e83315251d7 (diff)
downloadrails-e0bdc4f446686a498c3117e27ed8561f5c6d34f1.tar.gz
rails-e0bdc4f446686a498c3117e27ed8561f5c6d34f1.tar.bz2
rails-e0bdc4f446686a498c3117e27ed8561f5c6d34f1.zip
Ensure namespaced controllers in engines work.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/engine.rb10
-rw-r--r--railties/lib/rails/tasks/routes.rake1
-rw-r--r--railties/test/plugins/vendored_test.rb32
3 files changed, 42 insertions, 1 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index cc878ac8f2..6f724963b2 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -73,6 +73,16 @@ module Rails
end
end
+ initializer :add_routing_namespaces do |app|
+ config.paths.app.controllers.to_a.each do |load_path|
+ load_path = File.expand_path(load_path)
+ Dir["#{load_path}/*/*_controller.rb"].collect do |path|
+ namespace = File.dirname(path).sub(/#{load_path}\/?/, '')
+ app.routes.controller_namespaces << namespace unless namespace.empty?
+ end
+ end
+ end
+
initializer :add_locales do
config.i18n.load_path.unshift(*config.paths.config.locales.to_a)
end
diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake
index 2395d73b2f..e8da72db4d 100644
--- a/railties/lib/rails/tasks/routes.rake
+++ b/railties/lib/rails/tasks/routes.rake
@@ -1,5 +1,6 @@
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
+ Rails::Application.reload_routes!
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
routes = all_routes.collect do |route|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/plugins/vendored_test.rb
index 6207cd13c1..1fc8766def 100644
--- a/railties/test/plugins/vendored_test.rb
+++ b/railties/test/plugins/vendored_test.rb
@@ -17,6 +17,10 @@ module PluginsTest
require "#{app_path}/config/environment"
end
+ def app
+ @app ||= Rails.application
+ end
+
test "it loads the plugin's init.rb file" do
boot_rails
assert_equal "loaded", BUKKITS
@@ -202,7 +206,6 @@ en:
YAML
boot_rails
- require "#{app_path}/config/environment"
assert_equal %W(
#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml
@@ -217,6 +220,33 @@ YAML
assert_equal "2", I18n.t(:foo)
assert_equal "1", I18n.t(:bar)
end
+
+ test "namespaced controllers with namespaced routes" do
+ @plugin.write "config/routes.rb", <<-RUBY
+ ActionController::Routing::Routes.draw do
+ namespace :admin do
+ match "index", :to => "admin/foo#index"
+ end
+ end
+ RUBY
+
+ @plugin.write "app/controllers/admin/foo_controller.rb", <<-RUBY
+ class Admin::FooController < ApplicationController
+ def index
+ render :text => "Rendered from namespace"
+ end
+ end
+ RUBY
+
+ boot_rails
+
+ require 'rack/test'
+ extend Rack::Test::Methods
+
+ get "/admin/index"
+ assert_equal 200, last_response.status
+ assert_equal "Rendered from namespace", last_response.body
+ end
end
class VendoredOrderingTest < Test::Unit::TestCase