Created
June 14, 2024 15:25
-
-
Save adrianthedev/743fc1834d68bc4b128dbb7c5e3b9913 to your computer and use it in GitHub Desktop.
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 | |
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 | |
# Basic Rails application setup. | |
class TestApp < Rails::Application | |
config.root = __dir__ | |
config.hosts << "example.org" | |
config.hosts << "foobar.example.org" | |
config.secret_key_base = "secret_key_base" | |
config.logger = Logger.new($stdout) | |
Rails.logger = config.logger | |
routes.draw do | |
constraints subdomain: "foobar" do | |
mount Avo::Engine, at: "/avo" | |
end | |
get "p/:id", to: "pages#show", as: :page | |
end | |
end | |
class Page | |
def id | |
1 | |
end | |
end | |
class PagesController < ActionController::Base | |
end | |
module Avo | |
class ApplicationController < ActionController::Base | |
include Rails.application.routes.url_helpers | |
end | |
end | |
# Avo's routes | |
Avo::Engine.routes.draw do | |
root to: redirect("/test") | |
get "/test" => "test#test" | |
end | |
class Avo::TestController < Avo::ApplicationController | |
def test | |
render inline: "<%= main_app.page_path 1 %>" | |
end | |
end | |
require "minitest/autorun" | |
require "rack/test" | |
class BugTest < Minitest::Test | |
include Rack::Test::Methods | |
def test_returns_success | |
get 'http://foobar.example.org/avo/test' | |
assert_equal last_response.body, "/test" | |
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