@@ -147,7 +147,8 @@ def mock_column(name, type, options = {})
147
147
let ( :options ) do
148
148
{
149
149
root_dir : '/root' ,
150
- model_dir : 'app/models,app/one, app/two ,,app/three'
150
+ model_dir : 'app/models,app/one, app/two ,,app/three' ,
151
+ skip_subdirectory_model_load : false
151
152
}
152
153
end
153
154
@@ -174,6 +175,41 @@ def mock_column(name, type, options = {})
174
175
is_expected . to eq ( [ 'app/models' , 'app/one' , 'app/two' , 'app/three' ] )
175
176
end
176
177
end
178
+
179
+ describe '@skip_subdirectory_model_load' do
180
+ subject do
181
+ AnnotateModels . instance_variable_get ( :@skip_subdirectory_model_load )
182
+ end
183
+
184
+ context 'option is set to true' do
185
+ let ( :options ) do
186
+ {
187
+ root_dir : '/root' ,
188
+ model_dir : 'app/models,app/one, app/two ,,app/three' ,
189
+ skip_subdirectory_model_load : true
190
+ }
191
+ end
192
+
193
+ it 'sets skip_subdirectory_model_load to true' do
194
+ is_expected . to eq ( true )
195
+ end
196
+ end
197
+
198
+ context 'option is set to false' do
199
+ let ( :options ) do
200
+ {
201
+ root_dir : '/root' ,
202
+ model_dir : 'app/models,app/one, app/two ,,app/three' ,
203
+ skip_subdirectory_model_load : false
204
+ }
205
+ end
206
+
207
+ it 'sets skip_subdirectory_model_load to false' do
208
+ is_expected . to eq ( false )
209
+ end
210
+
211
+ end
212
+ end
177
213
end
178
214
179
215
describe '.get_schema_info' do
@@ -2087,6 +2123,21 @@ class Bar::Foo
2087
2123
expect ( klass . name ) . to eq ( 'Foo' )
2088
2124
expect ( klass_2 . name ) . to eq ( 'Bar::Foo' )
2089
2125
end
2126
+
2127
+ it 'attempts to load the model path without expanding if skip_subdirectory_model_load is false' do
2128
+ allow ( AnnotateModels ) . to receive ( :skip_subdirectory_model_load ) . and_return ( false )
2129
+ full_path = File . join ( AnnotateModels . model_dir [ 0 ] , filename_2 )
2130
+ expect ( File ) . to_not receive ( :expand_path ) . with ( full_path )
2131
+ AnnotateModels . get_model_class ( full_path )
2132
+ end
2133
+
2134
+ it 'does not attempt to load the model path without expanding if skip_subdirectory_model_load is true' do
2135
+ $LOAD_PATH. unshift ( AnnotateModels . model_dir [ 0 ] )
2136
+ allow ( AnnotateModels ) . to receive ( :skip_subdirectory_model_load ) . and_return ( true )
2137
+ full_path = File . join ( AnnotateModels . model_dir [ 0 ] , filename_2 )
2138
+ expect ( File ) . to receive ( :expand_path ) . with ( full_path ) . and_call_original
2139
+ AnnotateModels . get_model_class ( full_path )
2140
+ end
2090
2141
end
2091
2142
2092
2143
context 'one of the classes is nested in another class' do
0 commit comments