@@ -31,8 +31,8 @@ module AnnotateModels
31
31
FABRICATORS_SPEC_DIR = File . join ( "spec" , "fabricators" )
32
32
33
33
TEST_PATTERNS = [
34
- [ UNIT_TEST_DIR , "%MODEL_NAME%_test.rb" ] ,
35
- [ SPEC_MODEL_DIR , "%MODEL_NAME%_spec.rb" ] ,
34
+ File . join ( UNIT_TEST_DIR , "%MODEL_NAME%_test.rb" ) ,
35
+ File . join ( SPEC_MODEL_DIR , "%MODEL_NAME%_spec.rb" ) ,
36
36
]
37
37
38
38
FIXTURE_PATTERNS = [
@@ -301,8 +301,7 @@ def annotate(klass, file, header, options={})
301
301
302
302
unless options [ :exclude_tests ]
303
303
did_annotate = TEST_PATTERNS .
304
- map { |pat | [ pat [ 0 ] , resolve_filename ( pat [ 1 ] , model_name , table_name ) ] } .
305
- map { |pat | find_test_file ( *pat ) } .
304
+ map { |file | resolve_filename ( file , model_name , table_name ) } .
306
305
map { |file | annotate_one_file ( file , info , :position_in_test , options_with_position ( options , :position_in_test ) ) } .
307
306
detect { |result | result } || did_annotate
308
307
end
@@ -441,16 +440,7 @@ def remove_annotations(options={})
441
440
model_file_name = File . join ( model_dir , file )
442
441
deannotated_klass = true if ( remove_annotation_of_file ( model_file_name ) )
443
442
444
- TEST_PATTERNS .
445
- map { |pat | [ pat [ 0 ] , resolve_filename ( pat [ 1 ] , model_name , table_name ) ] } .
446
- map { |pat | find_test_file ( *pat ) } . each do |file |
447
- if ( File . exist? ( file ) )
448
- remove_annotation_of_file ( file )
449
- deannotated_klass = true
450
- end
451
- end
452
-
453
- ( FIXTURE_PATTERNS + FACTORY_PATTERNS ) .
443
+ ( TEST_PATTERNS + FIXTURE_PATTERNS + FACTORY_PATTERNS ) .
454
444
map { |file | resolve_filename ( file , model_name , table_name ) } .
455
445
each do |file |
456
446
if File . exist? ( file )
@@ -468,10 +458,6 @@ def remove_annotations(options={})
468
458
puts "Removed annotations from: #{ deannotated . join ( ', ' ) } "
469
459
end
470
460
471
- def find_test_file ( dir , file_name )
472
- Dir . glob ( File . join ( dir , "**" , file_name ) ) . first || File . join ( dir , file_name )
473
- end
474
-
475
461
def resolve_filename ( filename_template , model_name , table_name )
476
462
return filename_template .
477
463
gsub ( '%MODEL_NAME%' , model_name ) .
0 commit comments