Commit f1af392d by Cuong Tran

Merge pull request #120 from AMekss/master

Fix #113 (for encoding comments generated by magic_encoding gem)
parents 3faf06f1 3aac227a
......@@ -216,7 +216,7 @@ module AnnotateModels
old_columns = old_header && old_header.scan(column_pattern).sort
new_columns = new_header && new_header.scan(column_pattern).sort
encoding = Regexp.new(/(^#\s*encoding:.*\n)|(^# coding:.*\n)|(^# -\*- coding:.*\n)/)
encoding = Regexp.new(/(^#\s*encoding:.*\n)|(^# coding:.*\n)|(^# -\*- coding:.*\n)|(^# -\*- encoding\s?:.*\n)/)
encoding_header = old_content.match(encoding).to_s
if old_columns == new_columns && !options[:force]
......
......@@ -359,6 +359,16 @@ end
Annotate::PATH_OPTIONS.each { |key| ENV[key.to_s] = '' }
end
def encoding_comments_list_each
[
'# encoding: UTF-8',
'# coding: UTF-8',
'# -*- coding: UTF-8 -*-',
'#encoding: utf-8',
'# -*- encoding : utf-8 -*-'
].each{|encoding_comment| yield encoding_comment }
end
it "should annotate the file before the model if position == 'before'" do
annotate_one_file :position => "before"
File.read(@model_file_name).should == "#{@schema_info}\n#{@file_content}"
......@@ -401,6 +411,20 @@ end
File.read(model_file_name).should == "#{schema_info}\n#{file_content}"
end
it "should not touch encoding comments" do
encoding_comments_list_each do |encoding_comment|
write_model "user.rb", <<-EOS
#{encoding_comment}
class User < ActiveRecord::Base
end
EOS
annotate_one_file :position => :before
File.open(@model_file_name, &:readline).should == "#{encoding_comment}\n"
end
end
describe "if a file can't be annotated" do
before do
write_model('user.rb', <<-EOS)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment