Commit 87d90b5b authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'fix-sha-attribute-no-table' into 'master'

Fix ShaAttribute concern when there is no table

Closes #34798

See merge request !12705
parents c0e18e86 38fd773b
......@@ -3,6 +3,8 @@ module ShaAttribute
module ClassMethods
def sha_attribute(name)
return unless table_exists?
column = columns.find { |c| c.name == name.to_s }
# In case the table doesn't exist we won't be able to find the column,
......
......@@ -13,15 +13,34 @@ describe ShaAttribute do
end
describe '#sha_attribute' do
it 'defines a SHA attribute for a binary column' do
expect(model).to receive(:attribute)
.with(:sha1, an_instance_of(Gitlab::Database::ShaAttribute))
context' when the table exists' do
before do
allow(model).to receive(:table_exists?).and_return(true)
end
model.sha_attribute(:sha1)
it 'defines a SHA attribute for a binary column' do
expect(model).to receive(:attribute)
.with(:sha1, an_instance_of(Gitlab::Database::ShaAttribute))
model.sha_attribute(:sha1)
end
it 'raises ArgumentError when the column type is not :binary' do
expect { model.sha_attribute(:name) }.to raise_error(ArgumentError)
end
end
it 'raises ArgumentError when the column type is not :binary' do
expect { model.sha_attribute(:name) }.to raise_error(ArgumentError)
context' when the table does not exist' do
before do
allow(model).to receive(:table_exists?).and_return(false)
end
it 'does nothing' do
expect(model).not_to receive(:columns)
expect(model).not_to receive(:attribute)
model.sha_attribute(:name)
end
end
end
end
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