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
This commit is contained in:
commit
6c70d7f90b
2 changed files with 8 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue