BigW Consortium Gitlab

branch_formatter_spec.rb 1.75 KB
Newer Older
1 2 3
require 'spec_helper'

describe Gitlab::GithubImport::BranchFormatter, lib: true do
4
  let(:project) { create(:project, :repository) }
5
  let(:commit) { create(:commit, project: project) }
6 7 8
  let(:repo) { double }
  let(:raw) do
    {
9
      ref: 'branch-merged',
10
      repo: repo,
11
      sha: commit.id
12 13 14 15
    }
  end

  describe '#exists?' do
16
    it 'returns true when branch exists and commit is part of the branch' do
17 18 19 20 21
      branch = described_class.new(project, double(raw))

      expect(branch.exists?).to eq true
    end

22 23
    it 'returns false when branch exists and commit is not part of the branch' do
      branch = described_class.new(project, double(raw.merge(ref: 'feature')))
24 25 26

      expect(branch.exists?).to eq false
    end
27

28 29
    it 'returns false when branch does not exist' do
      branch = described_class.new(project, double(raw.merge(ref: 'removed-branch')))
30 31 32

      expect(branch.exists?).to eq false
    end
33 34 35 36 37 38 39 40 41 42 43 44 45 46
  end

  describe '#repo' do
    it 'returns raw repo' do
      branch = described_class.new(project, double(raw))

      expect(branch.repo).to eq repo
    end
  end

  describe '#sha' do
    it 'returns raw sha' do
      branch = described_class.new(project, double(raw))

47
      expect(branch.sha).to eq commit.id
48 49
    end
  end
50 51

  describe '#valid?' do
52
    it 'returns true when raw sha and ref are present' do
53 54 55 56 57
      branch = described_class.new(project, double(raw))

      expect(branch.valid?).to eq true
    end

58 59 60 61 62 63 64 65
    it 'returns false when raw sha is blank' do
      branch = described_class.new(project, double(raw.merge(sha: nil)))

      expect(branch.valid?).to eq false
    end

    it 'returns false when raw ref is blank' do
      branch = described_class.new(project, double(raw.merge(ref: nil)))
66 67 68 69

      expect(branch.valid?).to eq false
    end
  end
70
end