summaryrefslogtreecommitdiff
path: root/spec/validators
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2019-03-14 10:05:17 +0000
committerDouwe Maan <douwe@gitlab.com>2019-03-14 10:05:17 +0000
commit150f7c1e9c8d4a9d8134664d00a6385ac21a1939 (patch)
tree5a5fc090c6ebcd856a384fd90b38d9b708c916b8 /spec/validators
parentd0053d51719c4f9719bbe2d043c7aff23d9eabd1 (diff)
downloadgitlab-ce-150f7c1e9c8d4a9d8134664d00a6385ac21a1939.tar.gz
Fix Bitbucket import
In https://gitlab.com/gitlab-org/gitlab-ce/commit/ebf16ada856efb85424a98848c141f21e609886a we introduced a SHA validator, to ensure that the data provided in merge request diffs, was legit. Nevertheless, the validator assumed that the SHA should be 40 chars long. When we import a project from BitBucket, the retrieved SHA is shorter (12 chars long). Therefore, this validator prevented to create a valid MergeRequestDiff for ever MergeRequest (triggering an exception).
Diffstat (limited to 'spec/validators')
-rw-r--r--spec/validators/sha_validator_spec.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/spec/validators/sha_validator_spec.rb b/spec/validators/sha_validator_spec.rb
index dc1539cf318..0a76570f65e 100644
--- a/spec/validators/sha_validator_spec.rb
+++ b/spec/validators/sha_validator_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
describe ShaValidator do
let(:validator) { described_class.new(attributes: [:base_commit_sha]) }
- let(:merge_diff) { build(:merge_request_diff) }
+ let!(:merge_diff) { build(:merge_request_diff) }
subject { validator.validate_each(merge_diff, :base_commit_sha, value) }
@@ -12,6 +12,8 @@ describe ShaValidator do
let(:value) { nil }
it 'does not add any error if value is empty' do
+ expect(Commit).not_to receive(:valid_hash?)
+
subject
expect(merge_diff.errors).to be_empty
@@ -21,7 +23,9 @@ describe ShaValidator do
context 'with valid sha' do
let(:value) { Digest::SHA1.hexdigest(SecureRandom.hex) }
- it 'does not add any error if value is empty' do
+ it 'does not add any error' do
+ expect(Commit).to receive(:valid_hash?).and_call_original
+
subject
expect(merge_diff.errors).to be_empty
@@ -32,6 +36,7 @@ describe ShaValidator do
let(:value) { 'foo' }
it 'adds error to the record' do
+ expect(Commit).to receive(:valid_hash?).and_call_original
expect(merge_diff.errors).to be_empty
subject