debian-mirror-gitlab/spec/lib/gitlab/email/message/repository_push_spec.rb

148 lines
3.5 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2015-12-23 02:04:40 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Email::Message::RepositoryPush do
2015-12-23 02:04:40 +05:30
include RepoHelpers
let!(:group) { create(:group, name: 'my_group') }
2017-09-10 17:25:29 +05:30
let!(:project) { create(:project, :repository, namespace: group) }
2015-12-23 02:04:40 +05:30
let!(:author) { create(:author, name: 'Author') }
let(:message) do
2016-06-02 11:05:42 +05:30
described_class.new(Notify, project.id, opts)
2015-12-23 02:04:40 +05:30
end
context 'new commits have been pushed to repository' do
let(:opts) do
{ author_id: author.id, ref: 'master', action: :push, compare: compare,
send_from_committer_email: true }
end
2020-10-24 23:57:45 +05:30
2016-09-13 17:45:13 +05:30
let(:raw_compare) do
2015-12-23 02:04:40 +05:30
Gitlab::Git::Compare.new(project.repository.raw_repository,
2016-09-13 17:45:13 +05:30
sample_image_commit.id, sample_commit.id)
end
2020-10-24 23:57:45 +05:30
2016-09-13 17:45:13 +05:30
let(:compare) do
Compare.decorate(raw_compare, project)
2015-12-23 02:04:40 +05:30
end
describe '#project' do
subject { message.project }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to eq project }
it { is_expected.to be_an_instance_of Project }
end
describe '#project_namespace' do
subject { message.project_namespace }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to eq group }
it { is_expected.to be_kind_of Namespace }
end
describe '#project_name_with_namespace' do
subject { message.project_name_with_namespace }
2019-12-21 20:55:43 +05:30
2017-09-10 17:25:29 +05:30
it { is_expected.to eq "#{group.name} / #{project.path}" }
2015-12-23 02:04:40 +05:30
end
describe '#author' do
subject { message.author }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to eq author }
it { is_expected.to be_an_instance_of User }
end
describe '#author_name' do
subject { message.author_name }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to eq 'Author' }
end
describe '#commits' do
subject { message.commits }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to be_kind_of Array }
it { is_expected.to all(be_instance_of Commit) }
end
describe '#diffs' do
subject { message.diffs }
2019-12-21 20:55:43 +05:30
2020-04-22 19:07:51 +05:30
it { is_expected.to all(be_an_instance_of(Gitlab::Diff::File)) }
2015-12-23 02:04:40 +05:30
end
describe '#diffs_count' do
subject { message.diffs_count }
2019-12-21 20:55:43 +05:30
2016-09-13 17:45:13 +05:30
it { is_expected.to eq raw_compare.diffs.size }
2015-12-23 02:04:40 +05:30
end
describe '#compare' do
subject { message.compare }
2019-12-21 20:55:43 +05:30
2016-09-13 17:45:13 +05:30
it { is_expected.to be_an_instance_of Compare }
2015-12-23 02:04:40 +05:30
end
describe '#compare_timeout' do
subject { message.compare_timeout }
2019-12-21 20:55:43 +05:30
2016-09-13 17:45:13 +05:30
it { is_expected.to eq raw_compare.diffs.overflow? }
2015-12-23 02:04:40 +05:30
end
describe '#reverse_compare?' do
subject { message.reverse_compare? }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to eq false }
end
describe '#disable_diffs?' do
subject { message.disable_diffs? }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to eq false }
end
describe '#send_from_committer_email?' do
subject { message.send_from_committer_email? }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to eq true }
end
describe '#action_name' do
subject { message.action_name }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to eq 'pushed to' }
end
describe '#ref_name' do
subject { message.ref_name }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to eq 'master' }
end
describe '#ref_type' do
subject { message.ref_type }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to eq 'branch' }
end
describe '#target_url' do
subject { message.target_url }
2019-12-21 20:55:43 +05:30
2015-12-23 02:04:40 +05:30
it { is_expected.to include 'compare' }
it { is_expected.to include compare.commits.first.parents.first.id }
it { is_expected.to include compare.commits.last.id }
end
describe '#subject' do
subject { message.subject }
2019-12-21 20:55:43 +05:30
2017-09-10 17:25:29 +05:30
it { is_expected.to include "[Git][#{project.full_path}]" }
2015-12-23 02:04:40 +05:30
it { is_expected.to include "#{compare.commits.length} commits" }
it { is_expected.to include compare.commits.first.message.split("\n").first }
end
end
end