Skip to content

Commit a68493a

Browse files
sashabelozerovvfonic
authored andcommitted
[Fix ctran#570] Change of foreign key should be considered as a column change (ctran#678)
1 parent b2b1747 commit a68493a

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ Metrics/AbcSize:
414414
# Configuration parameters: CountComments, ExcludedMethods.
415415
# ExcludedMethods: refine
416416
Metrics/BlockLength:
417-
Max: 244
417+
Max: 259
418418

419419
# Offense count: 1
420420
# Configuration parameters: CountBlocks.

lib/annotate/annotate_models.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def annotate_one_file(file_name, info_block, position, options = {})
518518
old_header = old_content.match(header_pattern).to_s
519519
new_header = info_block.match(header_pattern).to_s
520520

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

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,49 @@ def magic_comments_list_each
17581758
.to eq("# START\n#{@schema_info}# END\n\n#{@file_content}")
17591759
end
17601760

1761+
describe 'with existing annotation' do
1762+
context 'of a foreign key' do
1763+
before do
1764+
klass = mock_class(:users,
1765+
:id,
1766+
[
1767+
mock_column(:id, :integer),
1768+
mock_column(:foreign_thing_id, :integer)
1769+
],
1770+
[],
1771+
[
1772+
mock_foreign_key('fk_rails_cf2568e89e',
1773+
'foreign_thing_id',
1774+
'foreign_things',
1775+
'id',
1776+
on_delete: :cascade)
1777+
])
1778+
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', show_foreign_keys: true)
1779+
annotate_one_file
1780+
end
1781+
1782+
it 'should update foreign key constraint' do
1783+
klass = mock_class(:users,
1784+
:id,
1785+
[
1786+
mock_column(:id, :integer),
1787+
mock_column(:foreign_thing_id, :integer)
1788+
],
1789+
[],
1790+
[
1791+
mock_foreign_key('fk_rails_cf2568e89e',
1792+
'foreign_thing_id',
1793+
'foreign_things',
1794+
'id',
1795+
on_delete: :restrict)
1796+
])
1797+
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', show_foreign_keys: true)
1798+
annotate_one_file
1799+
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
1800+
end
1801+
end
1802+
end
1803+
17611804
describe 'with existing annotation => :before' do
17621805
before do
17631806
annotate_one_file position: :before

0 commit comments

Comments
 (0)