Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sha_validator_spec.rb « validators « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cf2c7a728832ef8c5284805d8da13863e5484c80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ShaValidator do
  let(:validator) { described_class.new(attributes: [:base_commit_sha]) }
  let!(:merge_diff) { build(:merge_request_diff) }

  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
      expect(Commit).not_to receive(:valid_hash?)

      subject

      expect(merge_diff.errors).to be_empty
    end
  end

  context 'with valid sha' do
    let(:value) { Digest::SHA1.hexdigest(SecureRandom.hex) }

    it 'does not add any error' do
      expect(Commit).to receive(:valid_hash?).and_call_original

      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
      expect(Commit).to receive(:valid_hash?).and_call_original
      expect(merge_diff.errors).to be_empty

      subject

      expect(merge_diff.errors).not_to be_empty
    end
  end
end