2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::DataBuilder::Push do
|
2019-10-12 21:52:04 +05:30
|
|
|
include RepoHelpers
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2019-02-02 18:00:53 +05:30
|
|
|
let(:user) { build(:user, public_email: 'public-email@example.com') }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
describe '.build' do
|
|
|
|
let(:sample) { RepoHelpers.sample_compare }
|
|
|
|
let(:commits) { project.repository.commits_between(sample.commits.first, sample.commits.last) }
|
|
|
|
let(:subject) do
|
|
|
|
described_class.build(project: project,
|
|
|
|
user: user,
|
|
|
|
ref: sample.target_branch,
|
|
|
|
commits: commits,
|
|
|
|
commits_count: commits.length,
|
|
|
|
message: 'test message',
|
|
|
|
with_changed_files: with_changed_files)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with changed files' do
|
|
|
|
let(:with_changed_files) { true }
|
|
|
|
|
|
|
|
it 'returns commit hook data' do
|
|
|
|
expect(subject[:project]).to eq(project.hook_attrs)
|
|
|
|
expect(subject[:commits].first.keys).to include(*%i(added removed modified))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without changed files' do
|
|
|
|
let(:with_changed_files) { false }
|
|
|
|
|
|
|
|
it 'returns commit hook data without include deltas' do
|
|
|
|
expect(subject[:project]).to eq(project.hook_attrs)
|
|
|
|
expect(subject[:commits].first.keys).not_to include(*%i(added removed modified))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
describe '.build_sample' do
|
|
|
|
let(:data) { described_class.build_sample(project, user) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
it { expect(data).to be_a(Hash) }
|
2016-11-03 12:29:30 +05:30
|
|
|
it { expect(data[:before]).to eq('1b12f15a11fc6e62177bef08f47bc7b5ce50b141') }
|
|
|
|
it { expect(data[:after]).to eq('b83d6e391c22777fca1ed3012fce84f633d7fed0') }
|
2015-04-26 12:48:37 +05:30
|
|
|
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) }
|
2016-11-03 12:29:30 +05:30
|
|
|
it { expect(data[:commits].first[:added]).to eq(['bar/branch-test.txt']) }
|
|
|
|
it { expect(data[:commits].first[:modified]).to eq([]) }
|
2015-12-23 02:04:40 +05:30
|
|
|
it { expect(data[:commits].first[:removed]).to eq([]) }
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
include_examples 'project hook data with deprecateds'
|
2016-04-02 18:10:28 +05:30
|
|
|
include_examples 'deprecated repository hook data'
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
describe '.sample_data' do
|
|
|
|
let(:data) { described_class.sample_data }
|
|
|
|
|
|
|
|
it { expect(data).to be_a(Hash) }
|
|
|
|
it { expect(data[:before]).to eq('95790bf891e76fee5e1747ab589903a6a1f80f22') }
|
|
|
|
it { expect(data[:after]).to eq('da1560886d4f094c3e6c9ef40349f7d38b5d27d7') }
|
|
|
|
it { expect(data[:ref]).to eq('refs/heads/master') }
|
|
|
|
it { expect(data[:project_id]).to eq(15) }
|
|
|
|
it { expect(data[:commits].size).to eq(1) }
|
|
|
|
it { expect(data[:total_commits_count]).to eq(1) }
|
|
|
|
it 'contains project data' do
|
|
|
|
expect(data[:project]).to be_a(Hash)
|
|
|
|
expect(data[:project][:id]).to eq(15)
|
|
|
|
expect(data[:project][:name]).to eq('gitlab')
|
|
|
|
expect(data[:project][:description]).to eq('')
|
|
|
|
expect(data[:project][:web_url]).to eq('http://test.example.com/gitlab/gitlab')
|
|
|
|
expect(data[:project][:avatar_url]).to eq('https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80')
|
|
|
|
expect(data[:project][:git_http_url]).to eq('http://test.example.com/gitlab/gitlab.git')
|
|
|
|
expect(data[:project][:git_ssh_url]).to eq('git@test.example.com:gitlab/gitlab.git')
|
|
|
|
expect(data[:project][:namespace]).to eq('gitlab')
|
|
|
|
expect(data[:project][:visibility_level]).to eq(0)
|
|
|
|
expect(data[:project][:path_with_namespace]).to eq('gitlab/gitlab')
|
|
|
|
expect(data[:project][:default_branch]).to eq('master')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
describe '.build' do
|
2015-04-26 12:48:37 +05:30
|
|
|
let(:data) do
|
2019-07-31 22:56:46 +05:30
|
|
|
described_class.build(
|
|
|
|
project: project,
|
|
|
|
user: user,
|
|
|
|
oldrev: Gitlab::Git::BLANK_SHA,
|
|
|
|
newrev: '8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b',
|
|
|
|
ref: 'refs/tags/v1.1.0')
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
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') }
|
2016-06-02 11:05:42 +05:30
|
|
|
it { expect(data[:user_id]).to eq(user.id) }
|
|
|
|
it { expect(data[:user_name]).to eq(user.name) }
|
2017-09-10 17:25:29 +05:30
|
|
|
it { expect(data[:user_username]).to eq(user.username) }
|
2019-02-02 18:00:53 +05:30
|
|
|
it { expect(data[:user_email]).to eq(user.public_email) }
|
2016-06-02 11:05:42 +05:30
|
|
|
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) }
|
2015-04-26 12:48:37 +05:30
|
|
|
it { expect(data[:commits]).to be_empty }
|
|
|
|
it { expect(data[:total_commits_count]).to be_zero }
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
include_examples 'project hook data with deprecateds'
|
|
|
|
include_examples 'deprecated repository hook data'
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
it 'does not raise an error when given nil commits' do
|
2019-07-31 22:56:46 +05:30
|
|
|
expect { described_class.build(project: spy, user: spy, ref: 'refs/tags/v1.1.0', commits: nil) }
|
2017-09-10 17:25:29 +05:30
|
|
|
.not_to raise_error
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
describe '.build_bulk' do
|
|
|
|
subject do
|
|
|
|
described_class.build_bulk(action: :created, ref_type: :branch, changes: [double, double])
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(action: :created, ref_count: 2, ref_type: :branch) }
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|