debian-mirror-gitlab/spec/validators/sha_validator_spec.rb

48 lines
1 KiB
Ruby
Raw Normal View History

2019-05-18 00:54:41 +05:30
# frozen_string_literal: true
2019-03-13 22:55:13 +05:30
require 'spec_helper'
describe ShaValidator do
let(:validator) { described_class.new(attributes: [:base_commit_sha]) }
2019-05-03 19:53:19 +05:30
let!(:merge_diff) { build(:merge_request_diff) }
2019-03-13 22:55:13 +05:30
subject { validator.validate_each(merge_diff, :base_commit_sha, value) }
context 'with empty value' do
let(:value) { nil }
it 'does not add any error if value is empty' do
2019-05-03 19:53:19 +05:30
expect(Commit).not_to receive(:valid_hash?)
2019-03-13 22:55:13 +05:30
subject
expect(merge_diff.errors).to be_empty
end
end
context 'with valid sha' do
let(:value) { Digest::SHA1.hexdigest(SecureRandom.hex) }
2019-05-03 19:53:19 +05:30
it 'does not add any error' do
expect(Commit).to receive(:valid_hash?).and_call_original
2019-03-13 22:55:13 +05:30
subject
expect(merge_diff.errors).to be_empty
end
end
context 'with invalid sha' do
let(:value) { 'foo' }
it 'adds error to the record' do
2019-05-03 19:53:19 +05:30
expect(Commit).to receive(:valid_hash?).and_call_original
2019-03-13 22:55:13 +05:30
expect(merge_diff.errors).to be_empty
subject
expect(merge_diff.errors).not_to be_empty
end
end
end