Commit 5219c7eb by Alexander Belozerov Committed by Cuong Tran

[Fix #570] Change of foreign key should be considered as a column change (#678)

parent a631f5ad
...@@ -414,7 +414,7 @@ Metrics/AbcSize: ...@@ -414,7 +414,7 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, ExcludedMethods. # Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine # ExcludedMethods: refine
Metrics/BlockLength: Metrics/BlockLength:
Max: 244 Max: 259
# Offense count: 1 # Offense count: 1
# Configuration parameters: CountBlocks. # Configuration parameters: CountBlocks.
......
...@@ -518,7 +518,7 @@ module AnnotateModels ...@@ -518,7 +518,7 @@ module AnnotateModels
old_header = old_content.match(header_pattern).to_s old_header = old_content.match(header_pattern).to_s
new_header = info_block.match(header_pattern).to_s new_header = info_block.match(header_pattern).to_s
column_pattern = /^#[\t ]+[\w\*`]+[\t ]+.+$/ column_pattern = /^#[\t ]+[\w\*\.`]+[\t ]+.+$/
old_columns = old_header && old_header.scan(column_pattern).sort old_columns = old_header && old_header.scan(column_pattern).sort
new_columns = new_header && new_header.scan(column_pattern).sort new_columns = new_header && new_header.scan(column_pattern).sort
......
...@@ -1758,6 +1758,49 @@ end ...@@ -1758,6 +1758,49 @@ end
.to eq("# START\n#{@schema_info}# END\n\n#{@file_content}") .to eq("# START\n#{@schema_info}# END\n\n#{@file_content}")
end end
describe 'with existing annotation' do
context 'of a foreign key' do
before do
klass = mock_class(:users,
:id,
[
mock_column(:id, :integer),
mock_column(:foreign_thing_id, :integer)
],
[],
[
mock_foreign_key('fk_rails_cf2568e89e',
'foreign_thing_id',
'foreign_things',
'id',
on_delete: :cascade)
])
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', show_foreign_keys: true)
annotate_one_file
end
it 'should update foreign key constraint' do
klass = mock_class(:users,
:id,
[
mock_column(:id, :integer),
mock_column(:foreign_thing_id, :integer)
],
[],
[
mock_foreign_key('fk_rails_cf2568e89e',
'foreign_thing_id',
'foreign_things',
'id',
on_delete: :restrict)
])
@schema_info = AnnotateModels.get_schema_info(klass, '== Schema Info', show_foreign_keys: true)
annotate_one_file
expect(File.read(@model_file_name)).to eq("#{@schema_info}\n#{@file_content}")
end
end
end
describe 'with existing annotation => :before' do describe 'with existing annotation => :before' do
before do before do
annotate_one_file position: :before annotate_one_file position: :before
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment