Skip to content
Browse files

Engine sets routes as default rack endpoint if no endpoint was given

  • Loading branch information...
1 parent b5975a4 commit c989d1a87d4ed0d3f4fe425ce2207eec5a8d3154 @drogus drogus committed Jun 24, 2010
Showing with 30 additions and 7 deletions.
  1. +0 −4 railties/lib/rails/application.rb
  2. +5 −2 railties/lib/rails/engine.rb
  3. +25 −1 railties/test/railties/engine_test.rb
View
4 railties/lib/rails/application.rb
@@ -103,10 +103,6 @@ def eager_load! #:nodoc:
super
end
- def routes
- @routes ||= ActionDispatch::Routing::RouteSet.new
- end
-
def railties
@railties ||= Railties.new(config)
end
View
7 railties/lib/rails/engine.rb
@@ -152,18 +152,21 @@ def railties
end
def app
- raise "You can't use Engine as rack application without providing valid rack endpoint" unless endpoint
@app ||= config.middleware.build(endpoint)
end
def endpoint
- self.class.endpoint
+ self.class.endpoint || routes
end
def call(env)
app.call(env)
end
+ def routes
+ @routes ||= ActionDispatch::Routing::RouteSet.new
+ end
+
def initializers
initializers = []
railties.all { |r| initializers += r.initializers }
View
26 railties/test/railties/engine_test.rb
@@ -86,11 +86,35 @@ class Engine < ::Rails::Engine
assert_equal "HELLO WORLD", response[2]
end
+ test "it provides routes as default endpoint" do
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ class Bukkits
+ class Engine < ::Rails::Engine
+ end
+ end
+ RUBY
+
+ boot_rails
+
+ Bukkits::Engine.routes.draw do |map|
+ match "/foo" => lambda { |env| [200, {'Content-Type' => 'text/html'}, 'foo'] }
+ end
+
+ Rails::Application.routes.draw do |map|
+ mount(Bukkits::Engine => "/bukkits")
+ end
+
+ env = Rack::MockRequest.env_for("/bukkits/foo")
+ response = Rails::Application.call(env)
+
+ assert_equal "foo", response[2]
+ end
+
test "engine can load its own plugins" do
@plugin.write "lib/bukkits.rb", <<-RUBY
class Bukkits
class Engine < ::Rails::Engine
- config.paths.vendor.plugins = "#{File.join(@plugin.path, "lib/bukkits/plugins")}"
+ paths.vendor.plugins = "#{File.join(@plugin.path, "lib/bukkits/plugins")}"
end
end
RUBY

0 comments on commit c989d1a

Please sign in to comment.
Something went wrong with that request. Please try again.