@@ -368,31 +368,67 @@ def encoding_comments_list_each
368
368
] . each { |encoding_comment | yield encoding_comment }
369
369
end
370
370
371
- it "should annotate the file before the model if position == 'before'" do
371
+ it "should put annotation before class if : position == 'before'" do
372
372
annotate_one_file :position => "before"
373
373
File . read ( @model_file_name ) . should == "#{ @schema_info } \n #{ @file_content } "
374
374
end
375
375
376
- it "should annotate before if given :position => :before" do
376
+ it "should put annotation before class if :position => :before" do
377
377
annotate_one_file :position => :before
378
378
File . read ( @model_file_name ) . should == "#{ @schema_info } \n #{ @file_content } "
379
379
end
380
380
381
- it "should annotate after if given :position => :after" do
381
+ it "should put annotation after class if :position => :after" do
382
382
annotate_one_file :position => :after
383
383
File . read ( @model_file_name ) . should == "#{ @file_content } \n #{ @schema_info } "
384
384
end
385
385
386
- it "should update annotate position" do
387
- annotate_one_file :position => :before
386
+ describe "with existing annotation => :before" do
387
+ before do
388
+ annotate_one_file :position => :before
389
+ another_schema_info = AnnotateModels . get_schema_info ( mock_class ( :users , :id , [ mock_column ( :id , :integer ) , ] ) ,
390
+ "== Schema Info" )
391
+ @schema_info = another_schema_info
392
+ end
393
+
394
+ it "should retain current position" do
395
+ annotate_one_file
396
+ File . read ( @model_file_name ) . should == "#{ @schema_info } \n #{ @file_content } "
397
+ end
398
+
399
+ it "should retain current position even when :position is changed to :after" do
400
+ annotate_one_file :position => :after
401
+ File . read ( @model_file_name ) . should == "#{ @schema_info } \n #{ @file_content } "
402
+ end
403
+
404
+ it "should change position to :after when :force => true" do
405
+ annotate_one_file :position => :after , :force => true
406
+ File . read ( @model_file_name ) . should == "#{ @file_content } \n #{ @schema_info } "
407
+ end
408
+ end
388
409
389
- another_schema_info = AnnotateModels . get_schema_info ( mock_class ( :users , :id , [ mock_column ( :id , :integer ) , ] ) ,
410
+ describe "with existing annotation => :after" do
411
+ before do
412
+ annotate_one_file :position => :after
413
+ another_schema_info = AnnotateModels . get_schema_info ( mock_class ( :users , :id , [ mock_column ( :id , :integer ) , ] ) ,
390
414
"== Schema Info" )
415
+ @schema_info = another_schema_info
416
+ end
391
417
392
- @schema_info = another_schema_info
393
- annotate_one_file :position => :after
418
+ it "should retain current position" do
419
+ annotate_one_file
420
+ File . read ( @model_file_name ) . should == "#{ @file_content } \n #{ @schema_info } "
421
+ end
394
422
395
- File . read ( @model_file_name ) . should == "#{ @file_content } \n #{ another_schema_info } "
423
+ it "should retain current position even when :position is changed to :before" do
424
+ annotate_one_file :position => :before
425
+ File . read ( @model_file_name ) . should == "#{ @file_content } \n #{ @schema_info } "
426
+ end
427
+
428
+ it "should change position to :before when :force => true" do
429
+ annotate_one_file :position => :before , :force => true
430
+ File . read ( @model_file_name ) . should == "#{ @schema_info } \n #{ @file_content } "
431
+ end
396
432
end
397
433
398
434
it 'should skip columns with option[:ignore_columns] set' do
0 commit comments