summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-07-21 10:49:40 +0000
committerRémy Coutable <remy@rymai.me>2016-07-21 10:49:40 +0000
commit1459aa77bb998b838d8ad1c1abc73b1a69635357 (patch)
tree199c7a15f35c61870eb0446542f7afb8e0a506d6
parent479814b29289ab5598117ff22b63e386a3d2d9f3 (diff)
parent331571e0671baf606fd0c5cf694441b9a4036419 (diff)
downloadgitlab-ce-1459aa77bb998b838d8ad1c1abc73b1a69635357.tar.gz
Merge branch '20061-emailsonpushworker-fails-on-new-branch-pushes' into 'master'
Fix emails on push for new and deleted branches ## What does this MR do? Fix EmailsOnPushWorker when the push is either a new branch or a deleted branch. ## Are there points in the code the reviewer needs to double check? Don't think so. ## Why was this MR needed? / What are the relevant issue numbers? Closes #20061. ## Does this MR meet the acceptance criteria? - ~~[CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added~~ (regression) - ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~ - ~~API support added~~ - Tests - [x] Added for this feature/bug - [ ] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !5390
-rw-r--r--app/workers/emails_on_push_worker.rb4
-rw-r--r--spec/workers/emails_on_push_worker_spec.rb36
2 files changed, 38 insertions, 2 deletions
diff --git a/app/workers/emails_on_push_worker.rb b/app/workers/emails_on_push_worker.rb
index 8551288e2f2..0b6a01a3200 100644
--- a/app/workers/emails_on_push_worker.rb
+++ b/app/workers/emails_on_push_worker.rb
@@ -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(
diff --git a/spec/workers/emails_on_push_worker_spec.rb b/spec/workers/emails_on_push_worker_spec.rb
index 439da765c2c..796751efe8d 100644
--- a/spec/workers/emails_on_push_worker_spec.rb
+++ b/spec/workers/emails_on_push_worker_spec.rb
@@ -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 }