@@ -368,31 +368,67 @@ def encoding_comments_list_each
368368 ] . each { |encoding_comment | yield encoding_comment }
369369 end
370370
371- it "should annotate the file before the model if position == 'before'" do
371+ it "should put annotation before class if : position == 'before'" do
372372 annotate_one_file :position => "before"
373373 File . read ( @model_file_name ) . should == "#{ @schema_info } \n #{ @file_content } "
374374 end
375375
376- it "should annotate before if given :position => :before" do
376+ it "should put annotation before class if :position => :before" do
377377 annotate_one_file :position => :before
378378 File . read ( @model_file_name ) . should == "#{ @schema_info } \n #{ @file_content } "
379379 end
380380
381- it "should annotate after if given :position => :after" do
381+ it "should put annotation after class if :position => :after" do
382382 annotate_one_file :position => :after
383383 File . read ( @model_file_name ) . should == "#{ @file_content } \n #{ @schema_info } "
384384 end
385385
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
388409
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 ) , ] ) ,
390414 "== Schema Info" )
415+ @schema_info = another_schema_info
416+ end
391417
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
394422
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
396432 end
397433
398434 it 'should skip columns with option[:ignore_columns] set' do
0 commit comments