2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "isolation/abstract_unit"
|
2010-02-25 19:48:36 -05:00
|
|
|
|
|
|
|
module ApplicationTests
|
2012-01-05 20:30:17 -05:00
|
|
|
class UrlGenerationTest < ActiveSupport::TestCase
|
2010-02-25 19:48:36 -05:00
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
def app
|
|
|
|
Rails.application
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it works" do
|
|
|
|
require "rails"
|
|
|
|
require "action_controller/railtie"
|
2013-07-30 05:28:31 -04:00
|
|
|
require "action_view/railtie"
|
2010-02-25 19:48:36 -05:00
|
|
|
|
|
|
|
class MyApp < Rails::Application
|
2012-10-14 06:03:39 -04:00
|
|
|
config.session_store :cookie_store, key: "_myapp_session"
|
2010-06-29 15:18:17 -04:00
|
|
|
config.active_support.deprecation = :log
|
2012-10-18 13:33:40 -04:00
|
|
|
config.eager_load = false
|
2019-02-05 09:50:06 -05:00
|
|
|
config.hosts << proc { true }
|
2019-03-13 16:41:29 -04:00
|
|
|
config.secret_key_base = "b3c631c314c0bbca50c1b2843150fe33"
|
2010-02-25 19:48:36 -05:00
|
|
|
end
|
|
|
|
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.initialize!
|
2010-02-25 19:48:36 -05:00
|
|
|
|
|
|
|
class ::ApplicationController < ActionController::Base
|
|
|
|
end
|
|
|
|
|
|
|
|
class ::OmgController < ::ApplicationController
|
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: omg_path
|
2010-02-25 19:48:36 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
MyApp.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
get "/" => "omg#index", as: :omg
|
2010-02-25 19:48:36 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "rack/test"
|
2010-02-25 19:48:36 -05:00
|
|
|
extend Rack::Test::Methods
|
|
|
|
|
|
|
|
get "/"
|
|
|
|
assert_equal "/", last_response.body
|
|
|
|
end
|
2015-03-05 16:11:53 -05:00
|
|
|
|
|
|
|
def test_routes_know_the_relative_root
|
|
|
|
require "rails"
|
|
|
|
require "action_controller/railtie"
|
|
|
|
require "action_view/railtie"
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
relative_url = "/hello"
|
2015-03-05 16:11:53 -05:00
|
|
|
ENV["RAILS_RELATIVE_URL_ROOT"] = relative_url
|
|
|
|
app = Class.new(Rails::Application)
|
|
|
|
assert_equal relative_url, app.routes.relative_url_root
|
|
|
|
ENV["RAILS_RELATIVE_URL_ROOT"] = nil
|
|
|
|
end
|
2010-02-25 19:48:36 -05:00
|
|
|
end
|
|
|
|
end
|