File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed
Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 22
33## Unreleased (main)
44
5+ - Don't swallow errors caused by errors in the model class when detecting models
6+
57## v1.0.0 (2025-04-08)
68
79- Fix detection of relationships when there are multiple associations between users and companies
Original file line number Diff line number Diff line change @@ -41,13 +41,9 @@ def self.current_company
4141
4242 def self . detect_model ( *names )
4343 names . each do |name |
44- begin
45- model = name . constantize
44+ model = Object . const_get ( name ) if Object . const_defined? ( name )
4645
47- return model if model . is_a? ( Class )
48- rescue NameError
49- false
50- end
46+ return model if model . is_a? ( Class )
5147 end
5248
5349 nil
Original file line number Diff line number Diff line change 124124 end
125125 end
126126 end
127+
128+ describe '.detect_model' do
129+ it 'should raise an error when the model name is invalid' do
130+ expect { described_class . detect_model ( 'invalid' ) } . to raise_error ( NameError )
131+ end
132+
133+ it 'should not raise an error when the model is not found' do
134+ expect { described_class . detect_model ( 'NonExistentModel' ) } . not_to raise_error
135+ end
136+
137+ it 'should return the model class when it exists' do
138+ expect ( described_class . detect_model ( 'User' ) ) . to eq ( User )
139+ end
140+
141+ it 'should return the first model that exists when given a list of model names' do
142+ expect ( described_class . detect_model ( 'NonExistentModel' , 'User' ) ) . to eq ( User )
143+ end
144+ end
127145end
You can’t perform that action at this time.
0 commit comments