Commit 38fd773b authored by Sean McGivern's avatar Sean McGivern

Fix ShaAttribute concern when there is no table

When this is added to a new model, it would fail before the migrations were run
- including when trying to run migrations in production mode!
parent de2d5ce6
...@@ -3,6 +3,8 @@ module ShaAttribute ...@@ -3,6 +3,8 @@ module ShaAttribute
module ClassMethods module ClassMethods
def sha_attribute(name) def sha_attribute(name)
return unless table_exists?
column = columns.find { |c| c.name == name.to_s } 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, # In case the table doesn't exist we won't be able to find the column,
......
...@@ -13,6 +13,11 @@ describe ShaAttribute do ...@@ -13,6 +13,11 @@ describe ShaAttribute do
end end
describe '#sha_attribute' do describe '#sha_attribute' do
context' when the table exists' do
before do
allow(model).to receive(:table_exists?).and_return(true)
end
it 'defines a SHA attribute for a binary column' do it 'defines a SHA attribute for a binary column' do
expect(model).to receive(:attribute) expect(model).to receive(:attribute)
.with(:sha1, an_instance_of(Gitlab::Database::ShaAttribute)) .with(:sha1, an_instance_of(Gitlab::Database::ShaAttribute))
...@@ -24,4 +29,18 @@ describe ShaAttribute do ...@@ -24,4 +29,18 @@ describe ShaAttribute do
expect { model.sha_attribute(:name) }.to raise_error(ArgumentError) expect { model.sha_attribute(:name) }.to raise_error(ArgumentError)
end end
end end
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 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