Skip to content

Commit

Permalink
Added auto fixture dir finding, unit-test annotating, some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
roTuKa committed Aug 12, 2008
1 parent fd508da commit a0f90fa
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/annotate_models.rb
@@ -1,9 +1,10 @@
require "config/environment"

MODEL_DIR = File.join(RAILS_ROOT, "app/models")
MODEL_DIR = File.join(RAILS_ROOT, "app/models" )
SPEC_MODEL_DIR = File.join(RAILS_ROOT, "spec/models")
FIXTURE_DIR = File.join(RAILS_ROOT, "#{ENV['FIXTURES'] ? ENV['FIXTURES'] : SPEC_MODEL_DIR ? "spec" : "test"}/fixtures")
SORT_COLUMNS = ENV['SORT'] ? ENV['SORT'] != 'no' : true
UNIT_TEST_DIR = File.join(RAILS_ROOT, "test/unit" )
FIXTURE_DIR = ENV['FIXTURES'] ? "#{ENV['FIXTURES']}/fixtures" : [File.join(RAILS_ROOT, "spec/fixtures"), File.join(RAILS_ROOT, "test/fixtures")].detect { |dir| File.exists?(dir) }
SORT_COLUMNS = ENV['SORT'] ? ENV['SORT'] != 'no' : true

module AnnotateModels

Expand Down Expand Up @@ -88,14 +89,12 @@ def self.annotate_one_file(file_name, info_block)
def self.annotate(klass, header)
info = get_schema_info(klass, header)

model_file_name = File.join(MODEL_DIR, klass.name.underscore + ".rb")
annotate_one_file(model_file_name, info)

rspec_model_file_name = File.join(SPEC_MODEL_DIR, klass.name.underscore + "_spec.rb")
annotate_one_file(rspec_model_file_name, info)

fixture_file_name = File.join(FIXTURE_DIR, klass.table_name + ".yml")
annotate_one_file(fixture_file_name, info)
[
File.join(MODEL_DIR, klass.name.underscore + ".rb"), # model
File.join(SPEC_MODEL_DIR, klass.name.underscore + "_spec.rb"), # spec
File.join(UNIT_TEST_DIR, klass.name.underscore + "_test.rb"), # test
File.join(FIXTURE_DIR, klass.table_name + ".yml"), # fixture
].each { |file| annotate_one_file(file, info) }
end

# Return a list of the model files to annotate. If we have
Expand Down

0 comments on commit a0f90fa

Please sign in to comment.