Skip to content

Commit

Permalink
Correctly capture columns that have a multibyte comment
Browse files Browse the repository at this point in the history
Fixes #836.
  • Loading branch information
y-yagi committed May 16, 2023
1 parent 3a78787 commit b3fbb5e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def annotate_one_file(file_name, info_block, position, options = {})
old_header = old_content.match(header_pattern).to_s
new_header = info_block.match(header_pattern).to_s

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

Expand Down
28 changes: 28 additions & 0 deletions spec/lib/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2782,6 +2782,34 @@ def annotate_one_file(options = {})
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
end
end

context 'of multibyte comments' do
before do
klass = mock_class(:users,
:id,
[
mock_column(:id, :integer, comment: 'ID'),
],
[],
[])
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', with_comment: true)
annotate_one_file
end

it 'should update columns' do
klass = mock_class(:users,
:id,
[
mock_column(:id, :integer, comment: 'ID'),
mock_column(:active, :boolean, limit: 1, comment: 'ACTIVE'),
],
[],
[])
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', with_comment: true)
annotate_one_file
expect(File.read(@model_file_name)).to eq("#{@schema_info}#{@file_content}")
end
end
end

describe 'with existing annotation => :before' do
Expand Down

0 comments on commit b3fbb5e

Please sign in to comment.