Created
March 9, 2018 13:46
-
-
Save pixeltrix/6b97c14cc3cb810bce927d4a04f5ecdb to your computer and use it in GitHub Desktop.
Example for issue #32083
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
begin | |
require "bundler/inline" | |
rescue LoadError => e | |
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | |
raise e | |
end | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "rails", "5.1.5" | |
end | |
require "rack/test" | |
require "action_controller/railtie" | |
class TestApp < Rails::Application | |
config.root = __dir__ | |
config.session_store :cookie_store, key: "cookie_store_key" | |
secrets.secret_key_base = "secret_key_base" | |
config.logger = Logger.new("/dev/null") | |
Rails.logger = config.logger | |
routes.draw do | |
get "/*id", to: "pages#show", id: /(?!admin).*/ | |
end | |
end | |
class ApplicationController < ActionController::Base | |
include Rails.application.routes.url_helpers | |
end | |
class PagesController < ApplicationController | |
def show | |
render plain: request.path | |
end | |
end | |
require "minitest/autorun" | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
class BugTest < Minitest::Test | |
include Rack::Test::Methods | |
def test_negative_lookup_constraints | |
get "/foo" | |
assert_equal 200, last_response.status | |
assert_equal "/foo", last_response.body | |
get "/foo/admin" | |
assert_equal 200, last_response.status | |
assert_equal "/foo/admin", last_response.body | |
get "/admin" | |
assert_equal 404, last_response.status | |
get "/admin/foo" | |
assert_equal 404, last_response.status | |
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