Skip to content

Instantly share code, notes, and snippets.

@adrianthedev
Last active May 25, 2024 10:56
Show Gist options
  • Save adrianthedev/ab57557950a05804532377b69185d866 to your computer and use it in GitHub Desktop.
Save adrianthedev/ab57557950a05804532377b69185d866 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true, quiet: true) do
source "https://rubygems.org"
gem "rails", path: "."
end
require "action_controller"
# patching this so Rails wouldn't crash that it can't find the root.
# Another resolve for this it to have an `avo.rb` file in the lib directory.
module Rails
class Engine
def self.find_root(path)
Pathname.new('/')
end
end
end
# This is the first engine that is loaded.
# This is where the second engine will be mounted and to which the URL be generated in.
module Avo
end
module Avo
class Engine < ::Rails::Engine
isolate_namespace Avo
end
end
# This is the second engine.
module Avo::Pro
class Engine < ::Rails::Engine
isolate_namespace Avo::Pro
end
end
# Basic Rails application setup.
class TestApp < Rails::Application
config.root = __dir__
config.hosts << "example.org"
config.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
mount Avo::Engine, at: "/avo"
end
end
module Avo
class ApplicationController < ActionController::Base
end
end
module Avo
module Pro
class ApplicationController < ActionController::Base
end
end
end
# Avo's routes
Avo::Engine.routes.draw do
root to: redirect("/test")
# The test route is used to test the URL generation.
get "/test" => "test#test"
# The second engine is mounted here.
mount Avo::Pro::Engine, at: "/pro" if defined?(Avo::Pro::Engine)
end
Avo::Pro::Engine.routes.draw do
# We'll use one simple route to test the URL generation.
get :deep, as: :deep, to: "deep#index"
end
class Avo::TestController < Avo::ApplicationController
include Rails.application.routes.url_helpers
def test
# This is the URL that should be generated as /avo/pro/deep
# It works ok in rails 7.0 but breaks in rails 7.1
render inline: "<%= avo_pro.deep_path %>"
end
end
require "minitest/autorun"
require "rack/test"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
get "/avo/test"
assert_equal last_response.body, "/avo/pro/deep"
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