@@ -146,7 +146,8 @@ def mock_column(name, type, options = {})
146146 let ( :options ) do
147147 {
148148 root_dir : '/root' ,
149- model_dir : 'app/models,app/one, app/two ,,app/three'
149+ model_dir : 'app/models,app/one, app/two ,,app/three' ,
150+ skip_subdirectory_model_load : false
150151 }
151152 end
152153
@@ -173,6 +174,41 @@ def mock_column(name, type, options = {})
173174 is_expected . to eq ( [ 'app/models' , 'app/one' , 'app/two' , 'app/three' ] )
174175 end
175176 end
177+
178+ describe '@skip_subdirectory_model_load' do
179+ subject do
180+ AnnotateModels . instance_variable_get ( :@skip_subdirectory_model_load )
181+ end
182+
183+ context 'option is set to true' do
184+ let ( :options ) do
185+ {
186+ root_dir : '/root' ,
187+ model_dir : 'app/models,app/one, app/two ,,app/three' ,
188+ skip_subdirectory_model_load : true
189+ }
190+ end
191+
192+ it 'sets skip_subdirectory_model_load to true' do
193+ is_expected . to eq ( true )
194+ end
195+ end
196+
197+ context 'option is set to false' do
198+ let ( :options ) do
199+ {
200+ root_dir : '/root' ,
201+ model_dir : 'app/models,app/one, app/two ,,app/three' ,
202+ skip_subdirectory_model_load : false
203+ }
204+ end
205+
206+ it 'sets skip_subdirectory_model_load to false' do
207+ is_expected . to eq ( false )
208+ end
209+
210+ end
211+ end
176212 end
177213
178214 describe '.get_schema_info' do
@@ -2125,6 +2161,21 @@ class Bar::Foo
21252161 expect ( klass . name ) . to eq ( 'Foo' )
21262162 expect ( klass_2 . name ) . to eq ( 'Bar::Foo' )
21272163 end
2164+
2165+ it 'attempts to load the model path without expanding if skip_subdirectory_model_load is false' do
2166+ allow ( AnnotateModels ) . to receive ( :skip_subdirectory_model_load ) . and_return ( false )
2167+ full_path = File . join ( AnnotateModels . model_dir [ 0 ] , filename_2 )
2168+ expect ( File ) . to_not receive ( :expand_path ) . with ( full_path )
2169+ AnnotateModels . get_model_class ( full_path )
2170+ end
2171+
2172+ it 'does not attempt to load the model path without expanding if skip_subdirectory_model_load is true' do
2173+ $LOAD_PATH. unshift ( AnnotateModels . model_dir [ 0 ] )
2174+ allow ( AnnotateModels ) . to receive ( :skip_subdirectory_model_load ) . and_return ( true )
2175+ full_path = File . join ( AnnotateModels . model_dir [ 0 ] , filename_2 )
2176+ expect ( File ) . to receive ( :expand_path ) . with ( full_path ) . and_call_original
2177+ AnnotateModels . get_model_class ( full_path )
2178+ end
21282179 end
21292180
21302181 context 'one of the classes is nested in another class' do
0 commit comments