Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix overwriting of namespaced model test annotations with non-namespaced model annotations #166

Merged
merged 2 commits into from
Feb 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -301,8 +301,7 @@ def annotate(klass, file, header, options={})

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
Expand Down Expand Up @@ -441,16 +440,7 @@ def remove_annotations(options={})
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)
Expand All @@ -468,10 +458,6 @@ def remove_annotations(options={})
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).
Expand Down
6 changes: 3 additions & 3 deletions spec/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
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={})
Expand All @@ -27,7 +27,7 @@ def mock_column(name, type, options={})
stubs.merge!(options)
stubs.merge!(:name => name, :type => type)

mock("Column", stubs)
double("Column", stubs)
end

it { AnnotateModels.quote(nil).should eql("NULL") }
Expand Down
2 changes: 1 addition & 1 deletion spec/annotate/annotate_routes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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
Expand Down