allow reloading of models

This commit is contained in:
Dylan Knutson
2025-07-18 16:40:18 +00:00
parent 5cf9cfbc81
commit 26ad0e3ea3
2 changed files with 23 additions and 0 deletions

View File

@@ -83,6 +83,11 @@ module HasAuxTable
aux_class_name = aux_table_name.to_s.camelize
aux_association_name = aux_table_name.to_s.singularize.to_sym
# Ensure the class name doesn't conflict with existing constants
if Object.const_defined?(aux_class_name)
Object.send(:remove_const, aux_class_name)
end
# Get the current class for the association
main_class = T.cast(self, T.class_of(ActiveRecord::Base))
main_association_name = foreign_key.to_s.delete_suffix("_id").to_sym

View File

@@ -722,4 +722,22 @@ RSpec.describe HasAuxTable do
expect(fork1.num_tongs).to eq(3)
end
end
it "can redefine constants" do
class TestModel < ActiveRecord::Base
include HasAuxTable
end
class TestModelSpecific < TestModel
aux_table :specific
end
Object.send(:remove_const, :TestModelSpecific)
expect {
class TestModelSpecific < TestModel
aux_table :specific
end
}.not_to raise_error
end
end