Skip to content

Instantly share code, notes, and snippets.

@mtomov
Created July 19, 2022 16:41
Show Gist options
  • Save mtomov/5f61c0106be34ffb306f503ffe989541 to your computer and use it in GitHub Desktop.
Save mtomov/5f61c0106be34ffb306f503ffe989541 to your computer and use it in GitHub Desktop.
Inline Rails Application example
# from https://github.com/rails/rails/issues/42835#issuecomment-884768835
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", "6.1.3.2"
end
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
config.hosts << "example.org"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
get "/" => "test#index"
end
end
class CustomObject
def to_json(_options = nil)
'"#to_json"'
end
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
def index
render json: CustomObject.new
end
end
require "minitest/autorun"
require "rack/test"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
get "/"
assert last_response.ok?
assert_equal '"#to_json"', 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