debian-mirror-gitlab/spec/services/git_tag_push_service_spec.rb

90 lines
2.7 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe GitTagPushService, services: true do
2015-04-26 12:48:37 +05:30
include RepoHelpers
2015-09-11 14:41:01 +05:30
let(:user) { create :user }
let(:project) { create :project }
2016-06-02 11:05:42 +05:30
let(:service) { GitTagPushService.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
2014-09-02 18:07:02 +05:30
2016-06-02 11:05:42 +05:30
let(:oldrev) { Gitlab::Git::BLANK_SHA }
let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0
let(:ref) { 'refs/tags/v1.1.0' }
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
describe "Git Tag Push Data" do
2014-09-02 18:07:02 +05:30
before do
2016-06-02 11:05:42 +05:30
service.execute
2014-09-02 18:07:02 +05:30
@push_data = service.push_data
2016-06-02 11:05:42 +05:30
@tag_name = Gitlab::Git.ref_name(ref)
2015-04-26 12:48:37 +05:30
@tag = project.repository.find_tag(@tag_name)
2015-09-11 14:41:01 +05:30
@commit = project.commit(@tag.target)
2014-09-02 18:07:02 +05:30
end
subject { @push_data }
2015-04-26 12:48:37 +05:30
it { is_expected.to include(object_kind: 'tag_push') }
2016-06-02 11:05:42 +05:30
it { is_expected.to include(ref: ref) }
it { is_expected.to include(before: oldrev) }
it { is_expected.to include(after: newrev) }
2015-04-26 12:48:37 +05:30
it { is_expected.to include(message: @tag.message) }
it { is_expected.to include(user_id: user.id) }
it { is_expected.to include(user_name: user.name) }
it { is_expected.to include(project_id: project.id) }
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
context "with repository data" do
2014-09-02 18:07:02 +05:30
subject { @push_data[:repository] }
2015-04-26 12:48:37 +05:30
it { is_expected.to include(name: project.name) }
it { is_expected.to include(url: project.url_to_repo) }
it { is_expected.to include(description: project.description) }
it { is_expected.to include(homepage: project.web_url) }
end
context "with commits" do
subject { @push_data[:commits] }
it { is_expected.to be_an(Array) }
it 'has 1 element' do
expect(subject.size).to eq(1)
end
context "the commit" do
subject { @push_data[:commits].first }
it { is_expected.to include(id: @commit.id) }
it { is_expected.to include(message: @commit.safe_message) }
it { is_expected.to include(timestamp: @commit.date.xmlschema) }
it do
is_expected.to include(
2015-12-23 02:04:40 +05:30
url: [
Gitlab.config.gitlab.url,
project.namespace.to_param,
project.to_param,
'commit',
@commit.id
].join('/')
)
2015-04-26 12:48:37 +05:30
end
context "with a author" do
subject { @push_data[:commits].first[:author] }
it { is_expected.to include(name: @commit.author_name) }
it { is_expected.to include(email: @commit.author_email) }
end
end
2014-09-02 18:07:02 +05:30
end
end
2016-06-02 11:05:42 +05:30
describe "Webhooks" do
context "execute webhooks" do
let(:service) { GitTagPushService.new(project, user, oldrev: 'oldrev', newrev: 'newrev', ref: 'refs/tags/v1.0.0') }
2014-09-02 18:07:02 +05:30
it "when pushing tags" do
2015-04-26 12:48:37 +05:30
expect(project).to receive(:execute_hooks)
2016-06-02 11:05:42 +05:30
service.execute
2014-09-02 18:07:02 +05:30
end
end
end
end