Skip to content

Commit a0f37e5

Browse files
committed
Add constant MAGIC_COMMENTS
1 parent d265dca commit a0f37e5

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66
require 'files'
77

88
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+
923
def mock_index(name, params = {})
1024
double('IndexKeyDefinition',
1125
name: name,
@@ -1955,22 +1969,6 @@ def annotate_one_file(options = {})
19551969
Annotate::Constants::PATH_OPTIONS.each { |key| ENV[key.to_s] = '' }
19561970
end
19571971

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-
19741972
['before', :before, 'top', :top].each do |position|
19751973
it "should put annotation before class if :position == #{position}" do
19761974
annotate_one_file position: position
@@ -2106,7 +2104,7 @@ class Foo::User < ActiveRecord::Base
21062104
end
21072105

21082106
it 'should not touch magic comments' do
2109-
magic_comments_list_each do |magic_comment|
2107+
MAGIC_COMMENTS.each do |magic_comment|
21102108
write_model 'user.rb', <<-EOS
21112109
#{magic_comment}
21122110
class User < ActiveRecord::Base
@@ -2126,7 +2124,7 @@ class User < ActiveRecord::Base
21262124

21272125
it 'adds an empty line between magic comments and annotation (position :before)' do
21282126
content = "class User < ActiveRecord::Base\nend\n"
2129-
magic_comments_list_each do |magic_comment|
2127+
MAGIC_COMMENTS.each do |magic_comment|
21302128
model_file_name, = write_model 'user.rb', "#{magic_comment}\n#{content}"
21312129

21322130
annotate_one_file position: :before
@@ -2138,7 +2136,7 @@ class User < ActiveRecord::Base
21382136

21392137
it 'only keeps a single empty line around the annotation (position :before)' do
21402138
content = "class User < ActiveRecord::Base\nend\n"
2141-
magic_comments_list_each do |magic_comment|
2139+
MAGIC_COMMENTS.each do |magic_comment|
21422140
schema_info = AnnotateModels.get_schema_info(@klass, '== Schema Info')
21432141
model_file_name, = write_model 'user.rb', "#{magic_comment}\n\n\n\n#{content}"
21442142

@@ -2150,7 +2148,7 @@ class User < ActiveRecord::Base
21502148

21512149
it 'does not change whitespace between magic comments and model file content (position :after)' do
21522150
content = "class User < ActiveRecord::Base\nend\n"
2153-
magic_comments_list_each do |magic_comment|
2151+
MAGIC_COMMENTS.each do |magic_comment|
21542152
model_file_name, = write_model 'user.rb', "#{magic_comment}\n#{content}"
21552153

21562154
annotate_one_file position: :after

0 commit comments

Comments
 (0)