Skip to content

Commit 102548a

Browse files
committed
Correctly capture columns that have a multibyte comment
Fixes #836.
1 parent e60a666 commit 102548a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Diff for: lib/annotate/annotate_models.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def annotate_one_file(file_name, info_block, position, options = {})
433433
old_header = old_content.match(header_pattern).to_s
434434
new_header = info_block.match(header_pattern).to_s
435435

436-
column_pattern = /^#[\t ]+[\w\*\.`]+[\t ]+.+$/
436+
column_pattern = /^#[\t ]+[^\t ]+[\t ]+.+$/
437437
old_columns = old_header && old_header.scan(column_pattern).sort
438438
new_columns = new_header && new_header.scan(column_pattern).sort
439439

Diff for: spec/lib/annotate/annotate_models_spec.rb

+28
Original file line numberDiff line numberDiff line change
@@ -2922,6 +2922,34 @@ def annotate_one_file(options = {})
29222922
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
29232923
end
29242924
end
2925+
2926+
context 'of multibyte comments' do
2927+
before do
2928+
klass = mock_class(:users,
2929+
:id,
2930+
[
2931+
mock_column(:id, :integer, comment: 'ID'),
2932+
],
2933+
[],
2934+
[])
2935+
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', with_comment: true)
2936+
annotate_one_file
2937+
end
2938+
2939+
it 'should update columns' do
2940+
klass = mock_class(:users,
2941+
:id,
2942+
[
2943+
mock_column(:id, :integer, comment: 'ID'),
2944+
mock_column(:active, :boolean, limit: 1, comment: 'ACTIVE'),
2945+
],
2946+
[],
2947+
[])
2948+
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', with_comment: true)
2949+
annotate_one_file
2950+
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
2951+
end
2952+
end
29252953
end
29262954

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

0 commit comments

Comments
 (0)