Skip to content

Instantly share code, notes, and snippets.

@dsazup
Last active July 1, 2020 14:38
Show Gist options
  • Save dsazup/c7d425854fa6bb81f2d7d8572da7ee4c to your computer and use it in GitHub Desktop.
Save dsazup/c7d425854fa6bb81f2d7d8572da7ee4c to your computer and use it in GitHub Desktop.
rails optional parameter bug
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "rails", "6.0.3"
end
require "rack/test"
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
config.hosts << "example.org"
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
scope "/(:team)" do
resources :users
end
end
end
class UsersController < ActionController::Base
include Rails.application.routes.url_helpers
def index
render plain: users_path
end
end
require "minitest/autorun"
class BugTest < Minitest::Test
include Rack::Test::Methods
include Rails.application.routes.url_helpers
def test_optional_scope
get "/users"
assert_equal "/users", last_response.body
# the bellow is failing. It should return "/5/users", but is returnins "/users" instead
get "/5/users"
assert_equal "/5/users", last_response.body
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