allow reloading of models
This commit is contained in:
@@ -83,6 +83,11 @@ module HasAuxTable
|
|||||||
aux_class_name = aux_table_name.to_s.camelize
|
aux_class_name = aux_table_name.to_s.camelize
|
||||||
aux_association_name = aux_table_name.to_s.singularize.to_sym
|
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
|
# Get the current class for the association
|
||||||
main_class = T.cast(self, T.class_of(ActiveRecord::Base))
|
main_class = T.cast(self, T.class_of(ActiveRecord::Base))
|
||||||
main_association_name = foreign_key.to_s.delete_suffix("_id").to_sym
|
main_association_name = foreign_key.to_s.delete_suffix("_id").to_sym
|
||||||
|
|||||||
@@ -722,4 +722,22 @@ RSpec.describe HasAuxTable do
|
|||||||
expect(fork1.num_tongs).to eq(3)
|
expect(fork1.num_tongs).to eq(3)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user