Skip to content

Instantly share code, notes, and snippets.

@Peeja
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Peeja/de5ce3ea12b264aaf792 to your computer and use it in GitHub Desktop.
Save Peeja/de5ce3ea12b264aaf792 to your computer and use it in GitHub Desktop.
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'rails'
require 'action_controller/railtie'
# This will help us see what's going on. Forgive the global; we can't just put
# the value in the Rack response, because the 404 response gets thrown away
# when it cascades.
class StashPathInfoInGlobal
def initialize(app)
@app = app
end
def call(env)
$last_path_info = env['PATH_INFO']
@app.call(env)
end
end
# This is a URLMap app with a single mapping.
DemoRackApp = Rack::Builder.new do
use StashPathInfoInGlobal
map '/path' do
run -> (env) {
res = Rack::Response.new
res.write "Rendering from DemoRackApp."
res.finish
}
end
end
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.secret_key_base = 'secret_key_base'
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
mount DemoRackApp, at: '/'
mount DemoRackApp, at: '/deeper_mountpoint'
end
end
require 'minitest/autorun'
require 'rack/test'
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_at_root
get '/path'
assert_equal "Rendering from DemoRackApp.", last_response.body
end
def test_at_deeper_mountpoint
get '/deeper_mountpoint/path'
assert_equal "Rendering from DemoRackApp.", last_response.body
end
def test_path_info_at_root
get '/path'
assert_equal "/path", $last_path_info
end
def test_path_info_at_deeper_mountpoint
get '/deeper_mountpoint/path'
assert_equal "/path", $last_path_info
end
private
def app
Rails.application
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment