Skip to content

Commit 5664ea5

Browse files
committed
Show regex does not work
1 parent 2472836 commit 5664ea5

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

lib/annotate_rb/model_annotator/annotation_diff_generator.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module ModelAnnotator
55
# Compares the current file content and new annotation block and generates the column annotation differences
66
class AnnotationDiffGenerator
77
HEADER_PATTERN = /(^# Table name:.*?\n(#.*[\r]?\n)*[\r]?)/.freeze
8-
COLUMN_PATTERN = /^#[\t ]+[\w\*\.`\[\]():]+[\t ]+.+$/.freeze
8+
# COLUMN_PATTERN = /^#[\t ]+[\w\*\.`\[\]():]+[\t ]+.+$/.freeze
9+
COLUMN_PATTERN = /^#[\t ]+[^\t ]+[\t ]+.+$/.freeze
910

1011
class << self
1112
def call(file_content, annotation_block)

spec/lib/annotate_rb/model_annotator/annotation_diff_generator_spec.rb

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# frozen_string_literal: true
22

33
RSpec.describe AnnotateRb::ModelAnnotator::AnnotationDiffGenerator do
4+
include AnnotateTestHelpers
5+
46
def test_columns_match_expected
5-
remove_whitespace = Proc.new { |str| str.delete(" \t\r\n") }
7+
remove_whitespace = Proc.new { |str| str.delete(" \t\r\n") }
68

79
resulting_current_columns_data = subject.current_columns.map(&remove_whitespace)
810
expected_current_columns_data = current_columns.map(&remove_whitespace)
@@ -142,5 +144,53 @@ class User < ApplicationRecord
142144
expect(subject.changed?).to eq(true)
143145
end
144146
end
147+
148+
context 'when model file has existing annotations with column multi-byte comments' do
149+
let(:annotation_block) do
150+
klass = mock_class(:users,
151+
:id,
152+
[
153+
mock_column(:id, :bigint, comment: 'ID'),
154+
mock_column(:active, :boolean, limit: 1, comment: 'ACTIVE'),
155+
],
156+
[],
157+
[])
158+
options = AnnotateRb::Options.from({})
159+
AnnotateRb::ModelAnnotator::AnnotationBuilder.new(klass, options).build
160+
end
161+
162+
let(:file_content) do
163+
<<~FILE
164+
# == Schema Information
165+
#
166+
# Table name: users
167+
#
168+
# id(ID) :bigint not null, primary key
169+
#
170+
class User < ApplicationRecord
171+
end
172+
FILE
173+
end
174+
175+
let(:current_columns) do
176+
[
177+
"# id(ID) :bigint not null, primary key",
178+
"# Table name: users"
179+
]
180+
end
181+
let(:new_columns) do
182+
[
183+
"# id(ID) :bigint not null, primary key",
184+
"# active(ACTIVE) :boolean not null",
185+
"# Table name: users"
186+
]
187+
end
188+
189+
it 'returns an AnnotationDiff object with the expected old and new columns' do
190+
test_columns_match_expected
191+
192+
expect(subject.changed?).to eq(true)
193+
end
194+
end
145195
end
146196
end

0 commit comments

Comments
 (0)