summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-07-07 10:57:34 +0100
committerSean McGivern <sean@gitlab.com>2017-07-07 12:42:38 +0100
commit38fd773bd3bb7ff479ca3d607da6966139e262e3 (patch)
treed866d1f88f52388b554699b2e19c832c9fe284bd /spec/models
parentde2d5ce685877249434ba412b5839910bc703882 (diff)
downloadgitlab-ce-38fd773bd3bb7ff479ca3d607da6966139e262e3.tar.gz
Fix ShaAttribute concern when there is no tablefix-sha-attribute-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!
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/concerns/sha_attribute_spec.rb31
1 files changed, 25 insertions, 6 deletions
diff --git a/spec/models/concerns/sha_attribute_spec.rb b/spec/models/concerns/sha_attribute_spec.rb
index 9e37c2b20c4..610793ee557 100644
--- a/spec/models/concerns/sha_attribute_spec.rb
+++ b/spec/models/concerns/sha_attribute_spec.rb
@@ -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