Commit f89bbf2a by Joshua Plicque

Annotate nested fixtures

parent c479e5af
...@@ -48,6 +48,8 @@ module AnnotateModels ...@@ -48,6 +48,8 @@ module AnnotateModels
FIXTURE_PATTERNS = [ FIXTURE_PATTERNS = [
File.join(FIXTURE_TEST_DIR, "%TABLE_NAME%.yml"), File.join(FIXTURE_TEST_DIR, "%TABLE_NAME%.yml"),
File.join(FIXTURE_SPEC_DIR, "%TABLE_NAME%.yml"), File.join(FIXTURE_SPEC_DIR, "%TABLE_NAME%.yml"),
File.join(FIXTURE_TEST_DIR, "%PLURALIZED_MODEL_NAME%.yml"),
File.join(FIXTURE_SPEC_DIR, "%PLURALIZED_MODEL_NAME%.yml"),
] ]
FACTORY_PATTERNS = [ FACTORY_PATTERNS = [
...@@ -527,6 +529,7 @@ module AnnotateModels ...@@ -527,6 +529,7 @@ module AnnotateModels
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).
gsub('%PLURALIZED_MODEL_NAME%', model_name.pluralize).
gsub('%TABLE_NAME%', table_name || model_name.pluralize) gsub('%TABLE_NAME%', table_name || model_name.pluralize)
end end
......
...@@ -435,6 +435,35 @@ end ...@@ -435,6 +435,35 @@ end
end end
end end
describe '#resolve_filename' do
it 'should return the test path for a model' do
filename_template = 'test/unit/%MODEL_NAME%_test.rb'
model_name = 'example_model'
table_name = 'example_models'
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
expect(filename). to eq 'test/unit/example_model_test.rb'
end
it 'should return the fixture path for a model' do
filename_template = 'test/fixtures/%TABLE_NAME%.yml'
model_name = 'example_model'
table_name = 'example_models'
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
expect(filename). to eq 'test/fixtures/example_models.yml'
end
it 'should return the fixture path for a nested model' do
filename_template = 'test/fixtures/%PLURALIZED_MODEL_NAME%.yml'
model_name = 'parent/child'
table_name = 'parent_children'
filename = AnnotateModels.resolve_filename(filename_template, model_name, table_name)
expect(filename). to eq 'test/fixtures/parent/children.yml'
end
end
describe "annotating a file" do describe "annotating a file" do
before do before do
@model_dir = Dir.mktmpdir('annotate_models') @model_dir = Dir.mktmpdir('annotate_models')
......
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