Created
August 11, 2022 13:39
-
-
Save benoittgt/89adbc6e9b1d0c00aeed3c13ea177885 to your computer and use it in GitHub Desktop.
Why default_url_options is not working?
This file contains hidden or 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" | |
| require "json" | |
| 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", "~> 7.0.0" | |
| 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" | |
| post "/" => "test#update" | |
| end | |
| end | |
| class TestController < ActionController::Base | |
| include Rails.application.routes.url_helpers | |
| def default_url_options | |
| { "default_param" => "tenderlove" } | |
| end | |
| def index | |
| render json: params | |
| end | |
| def update | |
| # Rails.logger.warn(params) | |
| render json: params | |
| end | |
| end | |
| require "minitest/autorun" | |
| require "rack/test" | |
| class BugTest < Minitest::Test | |
| include Rack::Test::Methods | |
| def test_index | |
| get "/?foo=bar" | |
| hash_expected = {"foo"=>"bar", "controller"=>"test", "action"=>"index", "default_param" => "tenderlove"} | |
| assert_equal hash_expected, JSON.parse(last_response.body) | |
| end | |
| def test_update | |
| post("/", { foo: "baz" }) | |
| hash_expect = {"foo"=>"bar", "controller"=>"test", "action"=>"index", "default_param" => "tenderlove"} | |
| assert_equal hash_expect, JSON.parse(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