Commit f9ebcded by jonoterc

use general file resolution for test files as well

the special-purpose file resolution method for test/spec files was failing with namespaced test files (ex. User model attributes would annotate both test/unit/user_test.rb as well as test/unit/foo/user_test.rb, instead of only the former)
parent 2eb9714b
...@@ -31,8 +31,8 @@ module AnnotateModels ...@@ -31,8 +31,8 @@ module AnnotateModels
FABRICATORS_SPEC_DIR = File.join("spec", "fabricators") FABRICATORS_SPEC_DIR = File.join("spec", "fabricators")
TEST_PATTERNS = [ TEST_PATTERNS = [
[UNIT_TEST_DIR, "%MODEL_NAME%_test.rb"], File.join(UNIT_TEST_DIR, "%MODEL_NAME%_test.rb"),
[SPEC_MODEL_DIR, "%MODEL_NAME%_spec.rb"], File.join(SPEC_MODEL_DIR, "%MODEL_NAME%_spec.rb"),
] ]
FIXTURE_PATTERNS = [ FIXTURE_PATTERNS = [
...@@ -301,8 +301,7 @@ module AnnotateModels ...@@ -301,8 +301,7 @@ module AnnotateModels
unless options[:exclude_tests] unless options[:exclude_tests]
did_annotate = TEST_PATTERNS. did_annotate = TEST_PATTERNS.
map { |pat| [pat[0], resolve_filename(pat[1], model_name, table_name)] }. map { |file| resolve_filename(file, model_name, table_name) }.
map { |pat| find_test_file(*pat) }.
map { |file| annotate_one_file(file, info, :position_in_test, options_with_position(options, :position_in_test)) }. map { |file| annotate_one_file(file, info, :position_in_test, options_with_position(options, :position_in_test)) }.
detect { |result| result } || did_annotate detect { |result| result } || did_annotate
end end
...@@ -441,16 +440,7 @@ module AnnotateModels ...@@ -441,16 +440,7 @@ module AnnotateModels
model_file_name = File.join(model_dir, file) model_file_name = File.join(model_dir, file)
deannotated_klass = true if(remove_annotation_of_file(model_file_name)) deannotated_klass = true if(remove_annotation_of_file(model_file_name))
TEST_PATTERNS. (TEST_PATTERNS + FIXTURE_PATTERNS + FACTORY_PATTERNS).
map { |pat| [pat[0], resolve_filename(pat[1], model_name, table_name)]}.
map { |pat| find_test_file(*pat) }.each do |file|
if(File.exist?(file))
remove_annotation_of_file(file)
deannotated_klass = true
end
end
(FIXTURE_PATTERNS + FACTORY_PATTERNS).
map { |file| resolve_filename(file, model_name, table_name) }. map { |file| resolve_filename(file, model_name, table_name) }.
each do |file| each do |file|
if File.exist?(file) if File.exist?(file)
...@@ -468,10 +458,6 @@ module AnnotateModels ...@@ -468,10 +458,6 @@ module AnnotateModels
puts "Removed annotations from: #{deannotated.join(', ')}" puts "Removed annotations from: #{deannotated.join(', ')}"
end end
def find_test_file(dir, file_name)
Dir.glob(File.join(dir, "**", file_name)).first || File.join(dir, file_name)
end
def resolve_filename(filename_template, model_name, table_name) def resolve_filename(filename_template, model_name, table_name)
return filename_template. return filename_template.
gsub('%MODEL_NAME%', model_name). gsub('%MODEL_NAME%', model_name).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment