2017-07-23 15:36:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-10-04 09:13:21 +00:00
|
|
|
require "active_support/testing/strict_warnings"
|
|
|
|
|
2017-05-15 14:17:28 +00:00
|
|
|
$:.unshift File.expand_path("lib", __dir__)
|
2013-04-16 22:06:11 +00:00
|
|
|
|
2017-05-15 14:17:28 +00:00
|
|
|
ENV["TMPDIR"] = File.expand_path("tmp", __dir__)
|
2013-04-16 22:06:11 +00:00
|
|
|
|
2016-08-06 16:50:17 +00:00
|
|
|
require "active_support/core_ext/kernel/reporting"
|
2013-04-16 22:06:11 +00:00
|
|
|
|
|
|
|
# These are the normal settings that will be set up by Railties
|
|
|
|
# TODO: Have these tests support other combinations of these values
|
|
|
|
silence_warnings do
|
2017-01-11 08:48:00 +00:00
|
|
|
Encoding.default_internal = Encoding::UTF_8
|
|
|
|
Encoding.default_external = Encoding::UTF_8
|
2013-04-16 22:06:11 +00:00
|
|
|
end
|
|
|
|
|
2016-08-06 16:50:17 +00:00
|
|
|
require "active_support/testing/autorun"
|
2019-08-02 04:24:21 +00:00
|
|
|
require "active_support/testing/method_call_assertions"
|
2016-08-06 16:50:17 +00:00
|
|
|
require "action_controller"
|
|
|
|
require "action_view"
|
|
|
|
require "action_view/testing/resolvers"
|
|
|
|
require "active_support/dependencies"
|
|
|
|
require "active_model"
|
2013-04-16 22:06:11 +00:00
|
|
|
|
2020-05-02 20:18:19 +00:00
|
|
|
module ActionViewTestSuiteUtils
|
|
|
|
def self.require_helpers(helpers_dirs)
|
|
|
|
Array(helpers_dirs).each do |helpers_dir|
|
|
|
|
Dir.glob("#{helpers_dir}/**/*_helper.rb") do |helper_file|
|
|
|
|
require helper_file
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ActionViewTestSuiteUtils.require_helpers("#{__dir__}/fixtures/helpers")
|
|
|
|
ActionViewTestSuiteUtils.require_helpers("#{__dir__}/fixtures/alternate_helpers")
|
|
|
|
|
2013-04-16 22:06:11 +00:00
|
|
|
Thread.abort_on_exception = true
|
|
|
|
|
|
|
|
# Show backtraces for deprecated behavior for quicker cleanup.
|
2022-10-30 20:45:17 +00:00
|
|
|
ActionView.deprecator.debug = true
|
2013-04-16 22:06:11 +00:00
|
|
|
|
2013-12-16 18:04:07 +00:00
|
|
|
# Disable available locale checks to avoid warnings running the test suite.
|
|
|
|
I18n.enforce_available_locales = false
|
|
|
|
|
2014-10-27 16:28:53 +00:00
|
|
|
ORIGINAL_LOCALES = I18n.available_locales.map(&:to_s).sort
|
2013-04-16 22:06:11 +00:00
|
|
|
|
2017-05-15 14:17:28 +00:00
|
|
|
FIXTURE_LOAD_PATH = File.expand_path("fixtures", __dir__)
|
2013-04-16 22:06:11 +00:00
|
|
|
|
|
|
|
module RenderERBUtils
|
|
|
|
def view
|
|
|
|
@view ||= begin
|
|
|
|
path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH)
|
|
|
|
view_paths = ActionView::PathSet.new([path])
|
2019-01-23 22:19:50 +00:00
|
|
|
view = ActionView::Base.with_empty_template_cache
|
|
|
|
view.with_view_paths(view_paths)
|
2013-04-16 22:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_erb(string)
|
2020-12-30 12:24:58 +00:00
|
|
|
@virtual_path = nil
|
|
|
|
|
2013-04-16 22:06:11 +00:00
|
|
|
template = ActionView::Template.new(
|
|
|
|
string.strip,
|
|
|
|
"test template",
|
2019-02-02 00:10:02 +00:00
|
|
|
ActionView::Template.handler_for_extension(:erb),
|
2019-02-25 23:14:53 +00:00
|
|
|
format: :html, locals: [])
|
2013-04-16 22:06:11 +00:00
|
|
|
|
2019-01-23 22:19:50 +00:00
|
|
|
view = ActionView::Base.with_empty_template_cache
|
|
|
|
template.render(view.empty, {}).strip
|
2013-04-16 22:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class BasicController
|
2020-07-28 09:57:36 +00:00
|
|
|
attr_accessor :request, :response
|
2013-04-16 22:06:11 +00:00
|
|
|
|
|
|
|
def config
|
|
|
|
@config ||= ActiveSupport::InheritableOptions.new(ActionController::Base.config).tap do |config|
|
|
|
|
# VIEW TODO: View tests should not require a controller
|
2017-05-15 14:17:28 +00:00
|
|
|
public_dir = File.expand_path("fixtures/public", __dir__)
|
2013-04-16 22:06:11 +00:00
|
|
|
config.assets_dir = public_dir
|
|
|
|
config.javascripts_dir = "#{public_dir}/javascripts"
|
|
|
|
config.stylesheets_dir = "#{public_dir}/stylesheets"
|
2016-08-06 17:44:11 +00:00
|
|
|
config.assets = ActiveSupport::InheritableOptions.new(prefix: "assets")
|
2013-04-16 22:06:11 +00:00
|
|
|
config
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
|
2024-01-12 14:33:34 +00:00
|
|
|
self.app = ActionDispatch::MiddlewareStack.new do |middleware|
|
|
|
|
middleware.use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")
|
|
|
|
middleware.use ActionDispatch::DebugExceptions
|
|
|
|
middleware.use ActionDispatch::Callbacks
|
|
|
|
middleware.use ActionDispatch::Cookies
|
|
|
|
middleware.use ActionDispatch::Flash
|
|
|
|
middleware.use Rack::Head
|
2013-04-16 22:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-01 04:12:37 +00:00
|
|
|
ActionView::RoutingUrlFor.include(ActionDispatch::Routing::UrlFor)
|
2013-07-16 13:25:25 +00:00
|
|
|
|
2013-04-16 22:06:11 +00:00
|
|
|
module ActionController
|
|
|
|
class Base
|
|
|
|
self.view_paths = FIXTURE_LOAD_PATH
|
|
|
|
|
|
|
|
def self.test_routes(&block)
|
|
|
|
routes = ActionDispatch::Routing::RouteSet.new
|
|
|
|
routes.draw(&block)
|
|
|
|
include routes.url_helpers
|
2018-09-24 21:49:26 +00:00
|
|
|
routes
|
2013-04-16 22:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestCase
|
|
|
|
include ActionDispatch::TestProcess
|
|
|
|
|
2018-09-24 21:49:26 +00:00
|
|
|
def self.with_routes(&block)
|
2024-01-12 14:33:34 +00:00
|
|
|
setup do
|
|
|
|
@routes = ActionDispatch::Routing::RouteSet.new
|
|
|
|
@routes.draw(&block)
|
2018-09-24 21:49:26 +00:00
|
|
|
|
2024-01-12 14:33:34 +00:00
|
|
|
@controller.singleton_class.include @routes.url_helpers if @controller
|
|
|
|
end
|
2018-09-24 21:49:26 +00:00
|
|
|
end
|
2013-04-16 22:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module ActionDispatch
|
|
|
|
class DebugExceptions
|
|
|
|
private
|
2016-08-06 17:55:02 +00:00
|
|
|
remove_method :stderr_logger
|
2016-09-14 08:57:52 +00:00
|
|
|
# Silence logger
|
2016-08-06 17:55:02 +00:00
|
|
|
def stderr_logger
|
|
|
|
nil
|
|
|
|
end
|
2013-04-16 22:06:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-22 04:03:53 +00:00
|
|
|
class ActiveSupport::TestCase
|
2021-01-25 19:50:41 +00:00
|
|
|
if Process.respond_to?(:fork) && !Gem.win_platform?
|
|
|
|
parallelize
|
|
|
|
else
|
|
|
|
parallelize(with: :threads)
|
|
|
|
end
|
2019-08-02 04:24:11 +00:00
|
|
|
|
2019-08-02 04:24:21 +00:00
|
|
|
include ActiveSupport::Testing::MethodCallAssertions
|
2015-08-22 04:03:53 +00:00
|
|
|
end
|
2019-03-24 17:59:28 +00:00
|
|
|
|
|
|
|
require_relative "../../tools/test_common"
|