@@ -2922,6 +2922,65 @@ def annotate_one_file(options = {})
2922
2922
expect ( File . read ( @model_file_name ) ) . to eq ( "#{ @schema_info } #{ @file_content } " )
2923
2923
end
2924
2924
end
2925
+
2926
+ context 'of an index' do
2927
+ before do
2928
+ klass = mock_class ( :users ,
2929
+ :id ,
2930
+ [
2931
+ mock_column ( :id , :integer ) ,
2932
+ mock_column ( :foreign_thing_id , :integer )
2933
+ ] ,
2934
+ [
2935
+ mock_index ( 'index_rails_02e851e3b7' , columns : [ 'id' ] ) ,
2936
+ mock_index ( 'index_rails_02e851e3b8' , columns : [ 'foreign_thing_id' ] )
2937
+ ] )
2938
+ @schema_info = AnnotateModels . get_schema_info ( klass , '== Schema Info' , show_indexes : true )
2939
+ annotate_one_file
2940
+ end
2941
+
2942
+ it 'should update index' do
2943
+ klass = mock_class ( :users ,
2944
+ :id ,
2945
+ [
2946
+ mock_column ( :id , :integer ) ,
2947
+ mock_column ( :foreign_thing_id , :integer ) ,
2948
+ mock_column ( :another_column , :integer )
2949
+ ] ,
2950
+ [
2951
+ mock_index ( 'index_rails_02e851e3b7' , columns : [ 'id' ] ) ,
2952
+ mock_index ( 'index_rails_02e851e3b8' , columns : [ 'foreign_thing_id' ] ) ,
2953
+ mock_index ( 'index_rails_02e851e3b9' ,
2954
+ columns : [ 'another_column' ] ,
2955
+ where : "another_column IS NOT NULL"
2956
+ )
2957
+ ] )
2958
+ @schema_info = AnnotateModels . get_schema_info ( klass , '== Schema Info' , show_indexes : true )
2959
+ annotate_one_file
2960
+ expect ( File . read ( @model_file_name ) ) . to eq ( "#{ @schema_info } #{ @file_content } " )
2961
+ end
2962
+
2963
+ it 'should update index without escaping backslashes' do
2964
+ klass = mock_class ( :users ,
2965
+ :id ,
2966
+ [
2967
+ mock_column ( :id , :integer ) ,
2968
+ mock_column ( :foreign_thing_id , :integer ) ,
2969
+ mock_column ( :another_column , :text )
2970
+ ] ,
2971
+ [
2972
+ mock_index ( 'index_rails_02e851e3b7' , columns : [ 'id' ] ) ,
2973
+ mock_index ( 'index_rails_02e851e3b8' , columns : [ 'foreign_thing_id' ] ) ,
2974
+ mock_index ( 'index_rails_02e851e3b9' ,
2975
+ columns : [ 'another_column' ] ,
2976
+ where : "another_column LIKE '\\ \\ %'"
2977
+ )
2978
+ ] )
2979
+ @schema_info = AnnotateModels . get_schema_info ( klass , '== Schema Info' , show_indexes : true )
2980
+ annotate_one_file
2981
+ expect ( File . read ( @model_file_name ) ) . to eq ( "#{ @schema_info } #{ @file_content } " )
2982
+ end
2983
+ end
2925
2984
end
2926
2985
2927
2986
describe 'with existing annotation => :before' do
0 commit comments