diff options
author | Stan Hu <stanhu@gmail.com> | 2018-05-10 16:43:13 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-05-10 16:43:13 +0000 |
commit | 6c70d7f90bf8be05b67b3ec9ed2eeda3e9f524ea (patch) | |
tree | 486b833e7d83c75289621bcf166b01c103dcff5a | |
parent | 0afcfd31bdf8d23bc180d5a36796aba8e66dbd33 (diff) | |
parent | 42d27f0b43df544bab2ad5bc4e082728d86c7388 (diff) | |
download | gitlab-ce-6c70d7f90bf8be05b67b3ec9ed2eeda3e9f524ea.tar.gz |
Merge branch 'bw-fix-sha-attribute' into 'master'
ShaAttribute crashes with ArgumentError if column doesn't exist
See merge request gitlab-org/gitlab-ce!18880
-rw-r--r-- | app/models/concerns/sha_attribute.rb | 3 | ||||
-rw-r--r-- | spec/models/concerns/sha_attribute_spec.rb | 10 |
2 files changed, 8 insertions, 5 deletions
diff --git a/app/models/concerns/sha_attribute.rb b/app/models/concerns/sha_attribute.rb index 3340dc96e9f..3796737427a 100644 --- a/app/models/concerns/sha_attribute.rb +++ b/app/models/concerns/sha_attribute.rb @@ -22,7 +22,8 @@ module ShaAttribute column = columns.find { |c| c.name == name.to_s } unless column - raise ArgumentError.new("sha_attribute #{name.inspect} is invalid since the column doesn't exist") + warn "WARNING: sha_attribute #{name.inspect} is invalid since the column doesn't exist - you may need to run database migrations" + return end unless column.type == :binary diff --git a/spec/models/concerns/sha_attribute_spec.rb b/spec/models/concerns/sha_attribute_spec.rb index 592feddf1dc..0d3beb6a6e3 100644 --- a/spec/models/concerns/sha_attribute_spec.rb +++ b/spec/models/concerns/sha_attribute_spec.rb @@ -36,24 +36,26 @@ describe ShaAttribute do end context 'when the table does not exist' do - it 'allows the attribute to be added' do + it 'allows the attribute to be added and issues a warning' do allow(model).to receive(:table_exists?).and_return(false) expect(model).not_to receive(:columns) expect(model).to receive(:attribute) + expect(model).to receive(:warn) model.sha_attribute(:name) end end context 'when the column does not exist' do - it 'raises ArgumentError' do + it 'allows the attribute to be added and issues a warning' do allow(model).to receive(:table_exists?).and_return(true) expect(model).to receive(:columns) - expect(model).not_to receive(:attribute) + expect(model).to receive(:attribute) + expect(model).to receive(:warn) - expect { model.sha_attribute(:no_name) }.to raise_error(ArgumentError) + model.sha_attribute(:no_name) end end |