Fix emails on push for new and deleted branches

This commit is contained in:
Sean McGivern 2016-07-21 10:53:38 +01:00
parent cb9f418bf8
commit 331571e067
2 changed files with 38 additions and 2 deletions

View file

@ -28,12 +28,12 @@ class EmailsOnPushWorker
:push
end
merge_base_sha = project.merge_base_commit(before_sha, after_sha).try(:sha)
diff_refs = nil
compare = nil
reverse_compare = false
if action == :push
merge_base_sha = project.merge_base_commit(before_sha, after_sha).try(:sha)
compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha)
diff_refs = Gitlab::Diff::DiffRefs.new(

View file

@ -12,6 +12,42 @@ describe EmailsOnPushWorker do
subject { EmailsOnPushWorker.new }
describe "#perform" do
context "when push is a new branch" do
let(:email) { ActionMailer::Base.deliveries.last }
before do
data_new_branch = data.stringify_keys.merge("before" => Gitlab::Git::BLANK_SHA)
subject.perform(project.id, recipients, data_new_branch)
end
it "sends a mail with the correct subject" do
expect(email.subject).to include("Pushed new branch")
end
it "sends the mail to the correct recipient" do
expect(email.to).to eq([user.email])
end
end
context "when push is a deleted branch" do
let(:email) { ActionMailer::Base.deliveries.last }
before do
data_deleted_branch = data.stringify_keys.merge("after" => Gitlab::Git::BLANK_SHA)
subject.perform(project.id, recipients, data_deleted_branch)
end
it "sends a mail with the correct subject" do
expect(email.subject).to include("Deleted branch")
end
it "sends the mail to the correct recipient" do
expect(email.to).to eq([user.email])
end
end
context "when there are no errors in sending" do
let(:email) { ActionMailer::Base.deliveries.last }