Skip to content

Commit f094da6

Browse files
committed
Merge pull request #93 from jmcnevin/master
Adjust expected location of Factory Girl factories.
2 parents 98d0063 + d470621 commit f094da6

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

lib/annotate/annotate_models.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class << self
3939
def model_dir
4040
@model_dir || "app/models"
4141
end
42-
42+
4343
def model_dir=(dir)
4444
@model_dir = dir
4545
end
@@ -92,7 +92,7 @@ def get_schema_info(klass, header, options = {})
9292
col_type << "(#{col.limit})" unless NO_LIMIT_COL_TYPES.include?(col_type)
9393
end
9494
end
95-
95+
9696
# Check out if we got a geometric column
9797
# and print the type and SRID
9898
if col.respond_to?(:geometry_type)
@@ -180,7 +180,7 @@ def annotate_one_file(file_name, info_block, options={})
180180
if old_columns == new_columns && !options[:force]
181181
false
182182
else
183-
183+
184184
# todo: figure out if we need to extract any logic from this merge chunk
185185
# <<<<<<< HEAD
186186
# # Replace the old schema info with the new schema info
@@ -197,7 +197,7 @@ def annotate_one_file(file_name, info_block, options={})
197197
# Strip the old schema info, and insert new schema info.
198198
old_content.sub!(encoding, '')
199199
old_content.sub!(PATTERN, '')
200-
200+
201201
new_content = (options[:position] || 'before').to_s == 'after' ?
202202
(encoding_header + (old_content.rstrip + "\n\n" + info_block)) :
203203
(encoding_header + info_block + old_content)
@@ -207,7 +207,7 @@ def annotate_one_file(file_name, info_block, options={})
207207
end
208208
end
209209
end
210-
210+
211211
def remove_annotation_of_file(file_name)
212212
if File.exist?(file_name)
213213
content = File.read(file_name)
@@ -252,8 +252,10 @@ def annotate(klass, file, header, options={})
252252
File.join(EXEMPLARS_SPEC_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
253253
File.join(BLUEPRINTS_TEST_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
254254
File.join(BLUEPRINTS_SPEC_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
255-
File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories
256-
File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories
255+
File.join(FACTORY_GIRL_TEST_DIR, "#{klass.table_name}.rb"), # Factory Girl Factories (new style)
256+
File.join(FACTORY_GIRL_SPEC_DIR, "#{klass.table_name}.rb"), # Factory Girl Factories (new style)
257+
File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories (old style)
258+
File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories (old style)
257259
File.join(FABRICATORS_TEST_DIR, "#{model_name}_fabricator.rb"), # Fabrication Fabricators
258260
File.join(FABRICATORS_SPEC_DIR, "#{model_name}_fabricator.rb"), # Fabrication Fabricators
259261
].each do |file|
@@ -302,7 +304,7 @@ def get_model_files(options)
302304
end
303305
models
304306
end
305-
307+
306308
# Retrieve the classes belonging to the model names we're asked to process
307309
# Check for namespaced models in subdirectories as well as models
308310
# in subdirectories without namespacing.
@@ -320,7 +322,7 @@ def get_loaded_model(model_path)
320322
select do |c|
321323
Class === c and # note: we use === to avoid a bug in activesupport 2.3.14 OptionMerger vs. is_a?
322324
c.ancestors.respond_to?(:include?) and # to fix FactoryGirl bug, see https://github.com/ctran/annotate_models/pull/82
323-
c.ancestors.include?(ActiveRecord::Base)
325+
c.ancestors.include?(ActiveRecord::Base)
324326
end.
325327
detect { |c| ActiveSupport::Inflector.underscore(c) == model_path }
326328
end
@@ -342,9 +344,9 @@ def do_annotations(options={})
342344
version = ActiveRecord::Migrator.current_version rescue 0
343345
if version > 0
344346
header << "\n# Schema version: #{version}"
345-
end
347+
end
346348
end
347-
349+
348350
self.model_dir = options[:model_dir] if options[:model_dir]
349351

350352
annotated = []
@@ -394,8 +396,10 @@ def remove_annotations(options={})
394396
File.join(EXEMPLARS_SPEC_DIR, "#{model_name}_exemplar.rb"), # Object Daddy
395397
File.join(BLUEPRINTS_TEST_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
396398
File.join(BLUEPRINTS_SPEC_DIR, "#{model_name}_blueprint.rb"), # Machinist Blueprints
397-
File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories
398-
File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories
399+
File.join(FACTORY_GIRL_TEST_DIR, "#{klass.table_name}.rb"), # Factory Girl Factories (new style)
400+
File.join(FACTORY_GIRL_SPEC_DIR, "#{klass.table_name}.rb"), # Factory Girl Factories (new style)
401+
File.join(FACTORY_GIRL_TEST_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories (old style)
402+
File.join(FACTORY_GIRL_SPEC_DIR, "#{model_name}_factory.rb"), # Factory Girl Factories (old style)
399403
File.join(FABRICATORS_TEST_DIR, "#{model_name}_fabricator.rb"), # Fabrication Fabricators
400404
File.join(FABRICATORS_SPEC_DIR, "#{model_name}_fabricator.rb"), # Fabrication Fabricators
401405
].each do |file|
@@ -405,7 +409,7 @@ def remove_annotations(options={})
405409
end
406410
rescue Exception => e
407411
puts "Unable to deannotate #{file}: #{e.message}"
408-
puts "\t" + e.backtrace.join("\n\t") if options[:trace]
412+
puts "\t" + e.backtrace.join("\n\t") if options[:trace]
409413
end
410414
end
411415
puts "Removed annotation from: #{deannotated.join(', ')}"

0 commit comments

Comments
 (0)