Yusuke Hatanaka

April 17, 2024

TIL: minimum rails reproductive script

I found a great minimum reproductive script when I was looking at rails/rails pull #51523.

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "rails", ARGV.first || "7.1.3"
end

require "action_controller/railtie"
require "minitest/autorun"

class FoosController < ActionController::Base
end

class BugTest < ActionController::TestCase
  def test_routing
    with_routing do |routes|
      routes.draw do
        resources :foos, only: [] do
          get "bar", to: "bar"
        end
      end

      assert_routing "/foos/1/bar", controller: "foos", action: "bar", foo_id: "1"
    end
  end
end

The script not only can test on your own rails version, but also minimum and simple. Great work.

About Yusuke Hatanaka

I'm working as a software engineer in Japan. I like reading, watching basketball game, and fishing. 
Not only the fact oriented but also intuition.