File tree Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Expand file tree Collapse file tree 2 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -83,9 +83,9 @@ module AnnotateModels
83
83
class << self
84
84
def annotate_pattern ( options = { } )
85
85
if options [ :wrapper_open ]
86
- return /(?:^\n ?# (?:#{ options [ :wrapper_open ] } ).*\n ?# (?:#{ COMPAT_PREFIX } |#{ COMPAT_PREFIX_MD } ).*?\n (#.*\n )* \n *)|^\n ?# (?:#{ COMPAT_PREFIX } |#{ COMPAT_PREFIX_MD } ).*?\n (#.*\n )* \n */
86
+ return /(?:^( \n | \r \n ) ?# (?:#{ options [ :wrapper_open ] } ).*( \n | \r \n ) ?# (?:#{ COMPAT_PREFIX } |#{ COMPAT_PREFIX_MD } ).*?( \n | \r \n ) (#.*( \n | \r \n ))*( \n | \r \n ) *)|^( \n | \r \n ) ?# (?:#{ COMPAT_PREFIX } |#{ COMPAT_PREFIX_MD } ).*?( \n | \r \n ) (#.*( \n | \r \n ))*( \n | \r \n ) */
87
87
end
88
- /^\n ?# (?:#{ COMPAT_PREFIX } |#{ COMPAT_PREFIX_MD } ).*?\n (#.*\n )* \n */
88
+ /^( \n | \r \n ) ?# (?:#{ COMPAT_PREFIX } |#{ COMPAT_PREFIX_MD } ).*?( \n | \r \n ) (#.*( \n | \r \n ))*( \n | \r \n ) */
89
89
end
90
90
91
91
def model_dir
Original file line number Diff line number Diff line change @@ -1153,6 +1153,28 @@ def content(path)
1153
1153
# updated_at :datetime
1154
1154
#
1155
1155
1156
+ class Foo < ActiveRecord::Base
1157
+ end
1158
+ EOS
1159
+
1160
+ AnnotateModels . remove_annotation_of_file ( path )
1161
+
1162
+ expect ( content ( path ) ) . to eq <<-EOS
1163
+ class Foo < ActiveRecord::Base
1164
+ end
1165
+ EOS
1166
+ end
1167
+
1168
+ it 'should remove annotate if CRLF is used for line breaks' do
1169
+ path = create 'before.rb' , <<-EOS
1170
+ # == Schema Information
1171
+ #
1172
+ # Table name: foo\r \n #
1173
+ # id :integer not null, primary key
1174
+ # created_at :datetime
1175
+ # updated_at :datetime
1176
+ #
1177
+ \r \n
1156
1178
class Foo < ActiveRecord::Base
1157
1179
end
1158
1180
EOS
@@ -1201,6 +1223,29 @@ class Foo < ActiveRecord::Base
1201
1223
# updated_at :datetime
1202
1224
#
1203
1225
1226
+ class Foo < ActiveRecord::Base
1227
+ end
1228
+ EOS
1229
+
1230
+ AnnotateModels . remove_annotation_of_file ( path , wrapper_open : 'wrapper' )
1231
+
1232
+ expect ( content ( path ) ) . to eq <<-EOS
1233
+ class Foo < ActiveRecord::Base
1234
+ end
1235
+ EOS
1236
+ end
1237
+
1238
+ it 'should remove wrapper if CRLF is used for line breaks' do
1239
+ path = create 'opening_wrapper.rb' , <<-EOS
1240
+ # wrapper\r \n # == Schema Information
1241
+ #
1242
+ # Table name: foo
1243
+ #
1244
+ # id :integer not null, primary key
1245
+ # created_at :datetime
1246
+ # updated_at :datetime
1247
+ #
1248
+
1204
1249
class Foo < ActiveRecord::Base
1205
1250
end
1206
1251
EOS
You can’t perform that action at this time.
0 commit comments