Fix loading plugin and engine route sets

This commit is contained in:
Joshua Peek
2009-12-14 16:51:13 -06:00
parent 70c3e825fc
commit ec99eca013
2 changed files with 58 additions and 5 deletions

View File

@@ -212,11 +212,14 @@ module ActionDispatch
self.routes = []
self.named_routes = NamedRouteCollection.new
@clear_before_draw = true
@finalize_set_on_draw = true
clear!
end
def draw(&block)
clear!
clear! if @clear_before_draw
mapper = Mapper.new(self)
if block.arity == 1
@@ -225,9 +228,13 @@ module ActionDispatch
mapper.instance_exec(&block)
end
@set.add_route(NotFound)
install_helpers
@set.freeze
if @finalize_set_on_draw
@set.add_route(NotFound)
install_helpers
@set.freeze
end
nil
end
def clear!
@@ -283,7 +290,15 @@ module ActionDispatch
def load_routes!
if configuration_files.any?
configuration_files.each { |config| load(config) }
@finalize_set_on_draw = false
configuration_files.each_with_index do |config, index|
@finalize_set_on_draw = true if index == (configuration_files.length - 1)
load(config)
@clear_before_draw = false if index == 0
end
@clear_before_draw = true
@finalize_set_on_draw = true
@routes_last_modified = routes_changed_at
else
draw do |map|

View File

@@ -81,5 +81,43 @@ module ApplicationTests
get '/admin/foo'
assert_equal 'admin::foo', last_response.body
end
test "merges with plugin routes" do
controller 'foo', <<-RUBY
class FooController < ActionController::Base
def index
render :text => "foo"
end
end
RUBY
app_file 'config/routes.rb', <<-RUBY
ActionController::Routing::Routes.draw do |map|
match 'foo', :to => 'foo#index'
end
RUBY
plugin 'bar', 'require File.dirname(__FILE__) + "/app/controllers/bar"' do |plugin|
plugin.write 'app/controllers/bar.rb', <<-RUBY
class BarController < ActionController::Base
def index
render :text => "bar"
end
end
RUBY
plugin.write 'config/routes.rb', <<-RUBY
ActionController::Routing::Routes.draw do |map|
match 'bar', :to => 'bar#index'
end
RUBY
end
get '/foo'
assert_equal 'foo', last_response.body
get '/bar'
assert_equal 'bar', last_response.body
end
end
end