summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorJeroen Knoops <jeroen.knoops@gmail.com>2013-11-12 10:44:14 +0100
committerJeroen Knoops <jeroen.knoops@gmail.com>2013-11-12 20:51:57 +0100
commitcb9900c32c3023f0c416e646aad7b665e54e2deb (patch)
treeb43234b7db5804a5a34f51300a4d3383c68b1cb6 /spec/services
parent25298b9a01b102389205b58ffea51a4665006ce4 (diff)
downloadgitlab-ci-cb9900c32c3023f0c416e646aad7b665e54e2deb.tar.gz
Add email notification to committer
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/notification_service_spec.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
new file mode 100644
index 0000000..2ef34b9
--- /dev/null
+++ b/spec/services/notification_service_spec.rb
@@ -0,0 +1,66 @@
+require 'spec_helper'
+
+describe NotificationService do
+ let(:notification) { NotificationService.new }
+
+ describe 'Builds' do
+ let(:project) { FactoryGirl.create(:project)}
+
+ describe 'failed build' do
+ let(:build) { FactoryGirl.create(:build, :status => :failed, :project => project) }
+ it do
+ should_email(build.git_author_email)
+ notification.build_ended(build)
+ end
+
+ def should_email(user_id)
+ Notify.should_receive(:build_fail_email).with(build.id)
+ Notify.should_not_receive(:build_success_email).with(build.id)
+ end
+ end
+
+ describe 'successfull build with default settings' do
+ before(:each) do
+ @settings = double("settings")
+ @settings.stub(:only_fail_notifications) { true }
+ stub_const("Settings", Class.new)
+ Settings.stub_chain(:gitlab_ci).and_return(@settings)
+ end
+
+ let(:build) { FactoryGirl.create(:build, :status => :success, :project => project) }
+ it do
+ should_not_email(build.git_author_email)
+ notification.build_ended(build)
+ end
+
+ def should_not_email(user_id)
+ Notify.should_not_receive(:build_success_email).with(build.id)
+ Notify.should_not_receive(:build_fail_email).with(build.id)
+ end
+ end
+
+ describe 'successfull build with changed settings' do
+ before(:each) do
+ @settings = double("settings")
+ @settings.stub(:only_fail_notifications) { false }
+ stub_const("Settings", Class.new)
+ Settings.stub_chain(:gitlab_ci).and_return(@settings)
+ end
+
+ let(:build) { FactoryGirl.create(:build, :status => :success, :project => project) }
+
+ it do
+ should_email(build.git_author_email)
+ notification.build_ended(build)
+ end
+
+ def should_email(user_id)
+ Notify.should_receive(:build_success_email).with(build.id)
+ Notify.should_not_receive(:build_fail_email).with(build.id)
+ end
+ end
+
+
+ end
+
+end