Commit 7cbdba6a by Cuong Tran

Merge pull request #166 from jonoterc/namespacefix

fix overwriting of namespaced model test annotations with non-namespaced model annotations
parents 4e4a5a42 8aa6948e
......@@ -31,8 +31,8 @@ module AnnotateModels
FABRICATORS_SPEC_DIR = File.join("spec", "fabricators")
TEST_PATTERNS = [
[UNIT_TEST_DIR, "%MODEL_NAME%_test.rb"],
[SPEC_MODEL_DIR, "%MODEL_NAME%_spec.rb"],
File.join(UNIT_TEST_DIR, "%MODEL_NAME%_test.rb"),
File.join(SPEC_MODEL_DIR, "%MODEL_NAME%_spec.rb"),
]
FIXTURE_PATTERNS = [
......@@ -301,8 +301,7 @@ module AnnotateModels
unless options[:exclude_tests]
did_annotate = TEST_PATTERNS.
map { |pat| [pat[0], resolve_filename(pat[1], model_name, table_name)] }.
map { |pat| find_test_file(*pat) }.
map { |file| resolve_filename(file, model_name, table_name) }.
map { |file| annotate_one_file(file, info, :position_in_test, options_with_position(options, :position_in_test)) }.
detect { |result| result } || did_annotate
end
......@@ -441,16 +440,7 @@ module AnnotateModels
model_file_name = File.join(model_dir, file)
deannotated_klass = true if(remove_annotation_of_file(model_file_name))
TEST_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).
(TEST_PATTERNS + FIXTURE_PATTERNS + FACTORY_PATTERNS).
map { |file| resolve_filename(file, model_name, table_name) }.
each do |file|
if File.exist?(file)
......@@ -468,10 +458,6 @@ module AnnotateModels
puts "Removed annotations from: #{deannotated.join(', ')}"
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)
return filename_template.
gsub('%MODEL_NAME%', model_name).
......
......@@ -6,14 +6,14 @@ require 'annotate/active_record_patch'
describe AnnotateModels do
def mock_class(table_name, primary_key, columns)
options = {
:connection => mock("Conn", :indexes => []),
:connection => double("Conn", :indexes => []),
:table_name => table_name,
:primary_key => primary_key,
:column_names => columns.map { |col| col.name.to_s },
:columns => columns
}
mock("An ActiveRecord class", options)
double("An ActiveRecord class", options)
end
def mock_column(name, type, options={})
......@@ -27,7 +27,7 @@ describe AnnotateModels do
stubs.merge!(options)
stubs.merge!(:name => name, :type => type)
mock("Column", stubs)
double("Column", stubs)
end
it { AnnotateModels.quote(nil).should eql("NULL") }
......
......@@ -4,7 +4,7 @@ require 'annotate/annotate_routes'
describe AnnotateRoutes do
def mock_file(stubs={})
@mock_file ||= mock(File, stubs)
@mock_file ||= double(File, stubs)
end
it "should check if routes.rb exists" do
......
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