Skip to content

Commit d24f897

Browse files
Add 'top' and 'bottom' as synonyms for 'before' and 'after' models positions
1 parent 080fd67 commit d24f897

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/annotate/annotate_models.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def get_index_info(klass, options={})
224224
# === Options (opts)
225225
# :force<Symbol>:: whether to update the file even if it doesn't seem to need it.
226226
# :position_in_*<Symbol>:: where to place the annotated section in fixture or model file,
227-
# :before or :after. Default is :before.
227+
# :before, :top, :after or :bottom. Default is :before.
228228
#
229229
def annotate_one_file(file_name, info_block, position, options={})
230230
if File.exist?(file_name)
@@ -259,7 +259,7 @@ def annotate_one_file(file_name, info_block, position, options={})
259259
old_content.sub!(encoding, '')
260260
old_content.sub!(PATTERN, '')
261261

262-
new_content = options[position].to_s == 'after' ?
262+
new_content = %w(after bottom).include?(options[position].to_s) ?
263263
(encoding_header + (old_content.rstrip + "\n\n" + info_block)) :
264264
(encoding_header + info_block + "\n" + old_content)
265265
end

spec/annotate/annotate_models_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,16 @@ def encoding_comments_list_each
425425
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
426426
end
427427

428+
it "should put annotation before class if :position == 'top'" do
429+
annotate_one_file :position => "top"
430+
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
431+
end
432+
433+
it "should put annotation before class if :position => :top" do
434+
annotate_one_file :position => :top
435+
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
436+
end
437+
428438
it "should put annotation after class if :position => 'after'" do
429439
annotate_one_file :position => 'after'
430440
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
@@ -435,6 +445,16 @@ def encoding_comments_list_each
435445
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
436446
end
437447

448+
it "should put annotation after class if :position => 'bottom'" do
449+
annotate_one_file :position => 'bottom'
450+
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
451+
end
452+
453+
it "should put annotation after class if :position => :bottom" do
454+
annotate_one_file :position => :bottom
455+
expect(File.read(@model_file_name)).to eq("#{@file_content}\n#{@schema_info}")
456+
end
457+
438458
describe "with existing annotation => :before" do
439459
before do
440460
annotate_one_file :position => :before

0 commit comments

Comments
 (0)