Skip to content

Commit ed3cb0e

Browse files
author
Ethan Bresler
committed
adding tests
1 parent 886bb64 commit ed3cb0e

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

spec/lib/annotate/annotate_models_spec.rb

+52-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def mock_column(name, type, options = {})
147147
let(:options) do
148148
{
149149
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
151152
}
152153
end
153154

@@ -174,6 +175,41 @@ def mock_column(name, type, options = {})
174175
is_expected.to eq(['app/models', 'app/one', 'app/two', 'app/three'])
175176
end
176177
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
177213
end
178214

179215
describe '.get_schema_info' do
@@ -2087,6 +2123,21 @@ class Bar::Foo
20872123
expect(klass.name).to eq('Foo')
20882124
expect(klass_2.name).to eq('Bar::Foo')
20892125
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
20902141
end
20912142

20922143
context 'one of the classes is nested in another class' do

0 commit comments

Comments
 (0)