Skip to content

Commit 9717c31

Browse files
committed
Correctly capture columns that have a multibyte comment
Fixes ctran#836.
1 parent 3a78787 commit 9717c31

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/annotate/annotate_models.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def annotate_one_file(file_name, info_block, position, options = {})
412412
old_header = old_content.match(header_pattern).to_s
413413
new_header = info_block.match(header_pattern).to_s
414414

415-
column_pattern = /^#[\t ]+[\w\*\.`]+[\t ]+.+$/
415+
column_pattern = /^#[\t ]+[^\t ]+[\t ]+.+$/
416416
old_columns = old_header && old_header.scan(column_pattern).sort
417417
new_columns = new_header && new_header.scan(column_pattern).sort
418418

spec/lib/annotate/annotate_models_spec.rb

+28
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,34 @@ def annotate_one_file(options = {})
27822782
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
27832783
end
27842784
end
2785+
2786+
context 'of multibyte comments' do
2787+
before do
2788+
klass = mock_class(:users,
2789+
:id,
2790+
[
2791+
mock_column(:id, :integer, comment: 'ID'),
2792+
],
2793+
[],
2794+
[])
2795+
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', with_comment: true)
2796+
annotate_one_file
2797+
end
2798+
2799+
it 'should update column' do
2800+
klass = mock_class(:users,
2801+
:id,
2802+
[
2803+
mock_column(:id, :integer, comment: 'ID'),
2804+
mock_column(:active, :boolean, limit: 1, comment: 'ACTIVE'),
2805+
],
2806+
[],
2807+
[])
2808+
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', with_comment: true)
2809+
annotate_one_file
2810+
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
2811+
end
2812+
end
27852813
end
27862814

27872815
describe 'with existing annotation => :before' do

0 commit comments

Comments
 (0)