BigW Consortium Gitlab

push_spec.rb 2.15 KB
Newer Older
1 2
require 'spec_helper'

3
describe Gitlab::DataBuilder::Push, lib: true do
4 5 6
  let(:project) { create(:project) }
  let(:user) { create(:user) }

7 8
  describe '.build_sample' do
    let(:data) { described_class.build_sample(project, user) }
9

10 11 12 13 14 15
    it { expect(data).to be_a(Hash) }
    it { expect(data[:before]).to eq('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
    it { expect(data[:after]).to eq('5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
    it { expect(data[:ref]).to eq('refs/heads/master') }
    it { expect(data[:commits].size).to eq(3) }
    it { expect(data[:total_commits_count]).to eq(3) }
16 17
    it { expect(data[:commits].first[:added]).to eq(['gitlab-grack']) }
    it { expect(data[:commits].first[:modified]).to eq(['.gitmodules']) }
18
    it { expect(data[:commits].first[:removed]).to eq([]) }
19

20
    include_examples 'project hook data with deprecateds'
21
    include_examples 'deprecated repository hook data'
22 23
  end

24
  describe '.build' do
25
    let(:data) do
26 27 28
      described_class.build(project, user, Gitlab::Git::BLANK_SHA,
                            '8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b',
                            'refs/tags/v1.1.0')
29 30
    end

31 32 33 34 35
    it { expect(data).to be_a(Hash) }
    it { expect(data[:before]).to eq(Gitlab::Git::BLANK_SHA) }
    it { expect(data[:checkout_sha]).to eq('5937ac0a7beb003549fc5fd26fc247adbce4a52e') }
    it { expect(data[:after]).to eq('8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b') }
    it { expect(data[:ref]).to eq('refs/tags/v1.1.0') }
36 37 38 39 40 41
    it { expect(data[:user_id]).to eq(user.id) }
    it { expect(data[:user_name]).to eq(user.name) }
    it { expect(data[:user_email]).to eq(user.email) }
    it { expect(data[:user_avatar]).to eq(user.avatar_url) }
    it { expect(data[:project_id]).to eq(project.id) }
    it { expect(data[:project]).to be_a(Hash) }
42 43
    it { expect(data[:commits]).to be_empty }
    it { expect(data[:total_commits_count]).to be_zero }
44

45 46 47
    include_examples 'project hook data with deprecateds'
    include_examples 'deprecated repository hook data'

48 49 50 51
    it 'does not raise an error when given nil commits' do
      expect { described_class.build(spy, spy, spy, spy, spy, nil) }.
        not_to raise_error
    end
52 53
  end
end