6
6
require 'files'
7
7
8
8
describe AnnotateModels do # rubocop:disable Metrics/BlockLength
9
+ MAGIC_COMMENTS = [
10
+ '# encoding: UTF-8' ,
11
+ '# coding: UTF-8' ,
12
+ '# -*- coding: UTF-8 -*-' ,
13
+ '#encoding: utf-8' ,
14
+ '# encoding: utf-8' ,
15
+ '# -*- encoding : utf-8 -*-' ,
16
+ "# encoding: utf-8\n # frozen_string_literal: true" ,
17
+ "# frozen_string_literal: true\n # encoding: utf-8" ,
18
+ '# frozen_string_literal: true' ,
19
+ '#frozen_string_literal: false' ,
20
+ '# -*- frozen_string_literal : true -*-'
21
+ ] . freeze
22
+
9
23
def mock_index ( name , params = { } )
10
24
double ( 'IndexKeyDefinition' ,
11
25
name : name ,
@@ -1955,22 +1969,6 @@ def annotate_one_file(options = {})
1955
1969
Annotate ::Constants ::PATH_OPTIONS . each { |key | ENV [ key . to_s ] = '' }
1956
1970
end
1957
1971
1958
- def magic_comments_list_each
1959
- [
1960
- '# encoding: UTF-8' ,
1961
- '# coding: UTF-8' ,
1962
- '# -*- coding: UTF-8 -*-' ,
1963
- '#encoding: utf-8' ,
1964
- '# encoding: utf-8' ,
1965
- '# -*- encoding : utf-8 -*-' ,
1966
- "# encoding: utf-8\n # frozen_string_literal: true" ,
1967
- "# frozen_string_literal: true\n # encoding: utf-8" ,
1968
- '# frozen_string_literal: true' ,
1969
- '#frozen_string_literal: false' ,
1970
- '# -*- frozen_string_literal : true -*-'
1971
- ] . each { |magic_comment | yield magic_comment }
1972
- end
1973
-
1974
1972
[ 'before' , :before , 'top' , :top ] . each do |position |
1975
1973
it "should put annotation before class if :position == #{ position } " do
1976
1974
annotate_one_file position : position
@@ -2106,7 +2104,7 @@ class Foo::User < ActiveRecord::Base
2106
2104
end
2107
2105
2108
2106
it 'should not touch magic comments' do
2109
- magic_comments_list_each do |magic_comment |
2107
+ MAGIC_COMMENTS . each do |magic_comment |
2110
2108
write_model 'user.rb' , <<-EOS
2111
2109
#{ magic_comment }
2112
2110
class User < ActiveRecord::Base
@@ -2126,7 +2124,7 @@ class User < ActiveRecord::Base
2126
2124
2127
2125
it 'adds an empty line between magic comments and annotation (position :before)' do
2128
2126
content = "class User < ActiveRecord::Base\n end\n "
2129
- magic_comments_list_each do |magic_comment |
2127
+ MAGIC_COMMENTS . each do |magic_comment |
2130
2128
model_file_name , = write_model 'user.rb' , "#{ magic_comment } \n #{ content } "
2131
2129
2132
2130
annotate_one_file position : :before
@@ -2138,7 +2136,7 @@ class User < ActiveRecord::Base
2138
2136
2139
2137
it 'only keeps a single empty line around the annotation (position :before)' do
2140
2138
content = "class User < ActiveRecord::Base\n end\n "
2141
- magic_comments_list_each do |magic_comment |
2139
+ MAGIC_COMMENTS . each do |magic_comment |
2142
2140
schema_info = AnnotateModels . get_schema_info ( @klass , '== Schema Info' )
2143
2141
model_file_name , = write_model 'user.rb' , "#{ magic_comment } \n \n \n \n #{ content } "
2144
2142
@@ -2150,7 +2148,7 @@ class User < ActiveRecord::Base
2150
2148
2151
2149
it 'does not change whitespace between magic comments and model file content (position :after)' do
2152
2150
content = "class User < ActiveRecord::Base\n end\n "
2153
- magic_comments_list_each do |magic_comment |
2151
+ MAGIC_COMMENTS . each do |magic_comment |
2154
2152
model_file_name , = write_model 'user.rb' , "#{ magic_comment } \n #{ content } "
2155
2153
2156
2154
annotate_one_file position : :after
0 commit comments