Merge pull request #35175 from drn/create-session

Support testing of non-ActionDispatch-routed apps.
This commit is contained in:
Guillermo Iguaran 2019-02-12 10:59:39 -05:00 committed by GitHub
commit 2edeb438e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

@ -335,7 +335,7 @@ def create_session(app)
klass = APP_SESSIONS[app] ||= Class.new(Integration::Session) {
# If the app is a Rails app, make url_helpers available on the session.
# This makes app.url_for and app.foo_path available in the console.
if app.respond_to?(:routes)
if app.respond_to?(:routes) && app.routes.is_a?(ActionDispatch::Routing::RouteSet)
include app.routes.url_helpers
include app.routes.mounted_helpers
end

@ -0,0 +1,27 @@
# frozen_string_literal: true
require "abstract_unit"
module ActionDispatch
module Routing
class NonDispatchRoutedAppTest < ActionDispatch::IntegrationTest
# For example, Grape::API
class SimpleApp
def self.call(env)
[ 200, { "Content-Type" => "text/plain" }, [] ]
end
def self.routes
[]
end
end
setup { @app = SimpleApp }
test "does not except" do
get "/foo"
assert_response :success
end
end
end
end