From 194866854f9c38d3ff45f283a2eae835077a7152 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 22 Aug 2021 01:13:00 +0200 Subject: [PATCH] Restore autoloading test for STI This commit restores the test deleted in https://github.com/rails/rails/commit/fc7c02946783e9417e48c32c9cc28e0181ba623f Active Record should not test things about autoloading, this would belong to the railties test suite probably. However, there, it feels a bit too distant from here. Imperfect, but on a second thought I believe this trade-off is better. --- activerecord/test/cases/inheritance_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index 69e59db52a..06659dc296 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "active_support/inflector" +require "zeitwerk" require "cases/helper" require "models/author" require "models/company" @@ -373,6 +374,19 @@ class InheritanceTest < ActiveRecord::TestCase end end + def test_new_with_autoload_paths + path = File.expand_path("../models/autoloadable", __dir__) + Zeitwerk.with_loader do |loader| + loader.push_dir(path) + loader.setup + + firm = Company.new(type: "ExtraFirm") + assert_equal ExtraFirm, firm.class + ensure + loader.unload + end + end + def test_inheritance_condition assert_equal 12, Company.count assert_equal 3, Firm.count