Run it with:
curl -fsSL https://gist.github.com/shime/6129865/raw/try_it.sh | bash -e
Run it with:
curl -fsSL https://gist.github.com/shime/6129865/raw/try_it.sh | bash -e
| cd /tmp | |
| rails new buggy_redirects | |
| cd buggy_redirects | |
| cat > /tmp/buggy_redirects/config/routes.rb <<EOF | |
| BuggyRedirects::Application.routes.draw do | |
| namespace :api, defaults: {format: :json} do | |
| namespace :v1 do | |
| resources :users | |
| end | |
| namespace :v2 do | |
| resources :users | |
| end | |
| match 'v:api/*path', :to => redirect("/api/v2/%{path}") | |
| match '*path', :to => redirect("/api/v2/%{path}") | |
| end | |
| end | |
| EOF | |
| cat > /tmp/buggy_redirects/test_request.rb <<EOF | |
| require_relative "./config/environment" | |
| app = ActionDispatch::Integration::Session.new(Rails.application) | |
| puts "GET /api/users\n" | |
| app.get "/api/users", :format => :json | |
| if app.response.body == '<html><body>You are being <a href="http://www.example.com/api/v2/users">redirected</a>.</body></html>' | |
| puts | |
| puts "Yup, I'm definitely getting the HTML redirect:" | |
| end | |
| puts | |
| puts "status: #{app.response.status}" | |
| puts "body: #{app.response.body}" | |
| puts | |
| EOF | |
| ruby /tmp/buggy_redirects/test_request.rb | |
| echo "the app is located in /tmp/buggy_redirects" |