diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-07-16 15:41:47 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-07-16 15:41:47 -0700 |
commit | 4a7b95985f54ef1847f50eff294f7361d900539f (patch) | |
tree | 6c615a4b34e1f8e0a474b5a6e3112353b756297a | |
parent | d66536d7d478c47d3b47f4a9aee892e2881c7d64 (diff) | |
download | rails-4a7b95985f54ef1847f50eff294f7361d900539f.tar.gz rails-4a7b95985f54ef1847f50eff294f7361d900539f.tar.bz2 rails-4a7b95985f54ef1847f50eff294f7361d900539f.zip |
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.
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 11 | ||||
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 3 | ||||
-rw-r--r-- | actionpack/test/dispatch/mount_test.rb | 14 | ||||
-rw-r--r-- | actionpack/test/dispatch/prefix_generation_test.rb | 3 |
4 files changed, 17 insertions, 14 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 1fe5cce6a8..c16b04520e 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -605,18 +605,13 @@ module ActionDispatch 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 diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 214eab2f0d..78cce3aa64 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -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 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest @routes ||= ActionDispatch::Routing::RouteSet.new end - class MountedApp + class MountedApp < Rails::Engine def self.routes @routes ||= ActionDispatch::Routing::RouteSet.new end diff --git a/actionpack/test/dispatch/mount_test.rb b/actionpack/test/dispatch/mount_test.rb index ff4b644c16..d5a4d8ee11 100644 --- a/actionpack/test/dispatch/mount_test.rb +++ b/actionpack/test/dispatch/mount_test.rb @@ -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 @@ class TestRoutingMount < ActionDispatch::IntegrationTest 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 diff --git a/actionpack/test/dispatch/prefix_generation_test.rb b/actionpack/test/dispatch/prefix_generation_test.rb index cd31e8e326..c6e4eefa7a 100644 --- a/actionpack/test/dispatch/prefix_generation_test.rb +++ b/actionpack/test/dispatch/prefix_generation_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'rack/test' +require 'rails/engine' module TestGenerationPrefix class Post @@ -23,7 +24,7 @@ module TestGenerationPrefix class WithMountedEngine < ActionDispatch::IntegrationTest include Rack::Test::Methods - class BlogEngine + class BlogEngine < Rails::Engine def self.routes @routes ||= begin routes = ActionDispatch::Routing::RouteSet.new |