Permalink
Browse files

Rails-ish apps should descend from Rails::Railtie

Use an is_a check to ensure it's a Railsish app so we can avoid
respond_to calls everywhere.
  • Loading branch information...
tenderlove committed Jul 16, 2014
1 parent d66536d commit 4a7b95985f54ef1847f50eff294f7361d900539f
@@ -605,18 +605,13 @@ def has_named_route?(name)
private
def app_name(app)
- return unless app.respond_to?(:routes)
+ return unless app.is_a?(Class) && app < Rails::Railtie
- if app.respond_to?(:railtie_name)
- app.railtie_name
- else
- class_name = app.name
- ActiveSupport::Inflector.underscore(class_name).tr("/", "_")
- end
+ app.railtie_name
end
def define_generate_prefix(app, name)
- return unless app.respond_to?(:routes)
+ return unless app.is_a?(Class) && app < Rails::Railtie
_route = @set.named_routes.routes[name.to_sym]
_routes = @set
@@ -1,6 +1,7 @@
require 'abstract_unit'
require 'controller/fake_controllers'
require 'action_view/vendor/html-scanner'
+require 'rails/engine'
class SessionTest < ActiveSupport::TestCase
StubApp = lambda { |env|
@@ -595,7 +596,7 @@ def self.routes
@routes ||= ActionDispatch::Routing::RouteSet.new
end
- class MountedApp
+ class MountedApp < Rails::Engine
def self.routes
@routes ||= ActionDispatch::Routing::RouteSet.new
end
@@ -1,12 +1,18 @@
require 'abstract_unit'
+require 'rails/engine'
class TestRoutingMount < ActionDispatch::IntegrationTest
Router = ActionDispatch::Routing::RouteSet.new
- class FakeEngine
+ class AppWithRoutes < Rails::Engine
def self.routes
@routes ||= ActionDispatch::Routing::RouteSet.new
end
+ end
+
+ # Test for mounting apps that respond to routes, but aren't Rails-like apps.
+ class SinatraLikeApp
+ def self.routes; Object.new; end
def self.call(env)
[200, {"Content-Type" => "text/html"}, ["OK"]]
@@ -21,15 +27,15 @@ def self.call(env)
mount SprocketsApp, :at => "/sprockets"
mount SprocketsApp => "/shorthand"
- mount FakeEngine, :at => "/fakeengine", :as => :fake
- mount FakeEngine, :at => "/getfake", :via => :get
+ mount SinatraLikeApp, :at => "/fakeengine", :as => :fake
+ mount SinatraLikeApp, :at => "/getfake", :via => :get
scope "/its_a" do
mount SprocketsApp, :at => "/sprocket"
end
resources :users do
- mount FakeEngine, :at => "/fakeengine", :as => :fake_mounted_at_resource
+ mount AppWithRoutes, :at => "/fakeengine", :as => :fake_mounted_at_resource
end
mount SprocketsApp, :at => "/", :via => :get
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'rack/test'
+require 'rails/engine'
module TestGenerationPrefix
class Post
@@ -23,7 +24,7 @@ def persisted?; true; end
class WithMountedEngine < ActionDispatch::IntegrationTest
include Rack::Test::Methods
- class BlogEngine
+ class BlogEngine < Rails::Engine
def self.routes
@routes ||= begin
routes = ActionDispatch::Routing::RouteSet.new

0 comments on commit 4a7b959

Please sign in to comment.