summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-02-04 20:20:57 +0000
committerValery Sizov <valery@gitlab.com>2015-02-04 20:20:57 +0000
commitb98b7e904b84d58d7f945569f51047149d1d4dda (patch)
treeef51cec8475c641a4269c550adfee5007b0c7bc9 /spec
parentac7249d3fa579bdb8abb184cd4d6414f3143753c (diff)
parent7cb0a536330f36d67aae007617f11cab25e77c5a (diff)
downloadgitlab-ci-b98b7e904b84d58d7f945569f51047149d1d4dda.tar.gz
Merge branch 'topic/settings-email' into 'master'
Migrate E-mail notification to Services menu As discussed earlier e-mail notifications lives now under Services menu. Let me know if this is right direction. I think now that maybe I shouldn't migrate email_add_committer and email_recipients to MailService and instead use parameters from Project. What guys do you think? Tests results are here: https://semaphoreapp.com/ayufan/gitlab-ci/branches/topic-settings-email See merge request !30
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/commits.rb24
-rw-r--r--spec/models/mail_service_spec.rb192
-rw-r--r--spec/services/notification_service_spec.rb56
3 files changed, 214 insertions, 58 deletions
diff --git a/spec/factories/commits.rb b/spec/factories/commits.rb
index f767cac..156fabe 100644
--- a/spec/factories/commits.rb
+++ b/spec/factories/commits.rb
@@ -22,8 +22,28 @@ FactoryGirl.define do
push_data do
{
ref: 'refs/heads/master',
- before_sha: '76de212e80737a608d939f648d959671fb0a0142',
- after_sha: '97de212e80737a608d939f648d959671fb0a0142'
+ before: '76de212e80737a608d939f648d959671fb0a0142',
+ after: '97de212e80737a608d939f648d959671fb0a0142',
+ user_name: 'Git User',
+ repository: {
+ name: 'test-data',
+ url: 'ssh://git@gitlab.com/test/test-data.git',
+ description: '',
+ homepage: 'http://gitlab.com/test/test-data'
+ },
+ commits: [
+ {
+ id: '97de212e80737a608d939f648d959671fb0a0142',
+ message: 'Test commit message',
+ timestamp: '2014-09-23T13:12:25+02:00',
+ url: 'https://gitlab.com/test/test-data/commit/97de212e80737a608d939f648d959671fb0a0142',
+ author: {
+ name: 'Git User',
+ email: 'git@user.com'
+ }
+ }
+ ],
+ total_commits_count: 1
}
end
end
diff --git a/spec/models/mail_service_spec.rb b/spec/models/mail_service_spec.rb
new file mode 100644
index 0000000..7a43978
--- /dev/null
+++ b/spec/models/mail_service_spec.rb
@@ -0,0 +1,192 @@
+require 'spec_helper'
+
+describe MailService do
+ describe "Associations" do
+ it { should belong_to :project }
+ end
+
+ describe "Validations" do
+ context "active" do
+ before do
+ subject.active = true
+ end
+ end
+ end
+
+ describe 'Sends email for' do
+ let(:mail) { MailService.new }
+
+ describe 'failed build' do
+ let(:project) { FactoryGirl.create(:project, email_add_committer: true) }
+ let(:commit) { FactoryGirl.create(:commit, project: project) }
+ let(:build) { FactoryGirl.create(:build, status: :failed, commit: commit) }
+
+ before do
+ mail.stub(
+ project: project
+ )
+ end
+
+ it do
+ should_email(commit.git_author_email)
+ mail.execute(build)
+ end
+
+ def should_email(email)
+ Notify.should_receive(:build_fail_email).with(build.id, email)
+ Notify.should_not_receive(:build_success_email).with(build.id, email)
+ end
+ end
+
+ describe 'successfull build' do
+ let(:project) { FactoryGirl.create(:project, email_add_committer: true, email_only_broken_builds: false) }
+ let(:commit) { FactoryGirl.create(:commit, project: project) }
+ let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
+
+ before do
+ mail.stub(
+ project: project
+ )
+ end
+
+ it do
+ should_email(commit.git_author_email)
+ mail.execute(build)
+ end
+
+ def should_email(email)
+ Notify.should_receive(:build_success_email).with(build.id, email)
+ Notify.should_not_receive(:build_fail_email).with(build.id, email)
+ end
+ end
+
+ describe 'successfull build and project has email_recipients' do
+ let(:project) {
+ FactoryGirl.create(:project,
+ email_add_committer: true,
+ email_only_broken_builds: false,
+ email_recipients: "jeroen@example.com")
+ }
+ let(:commit) { FactoryGirl.create(:commit, project: project) }
+ let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
+
+ before do
+ mail.stub(
+ project: project
+ )
+ end
+
+ it do
+ should_email(commit.git_author_email)
+ should_email("jeroen@example.com")
+ mail.execute(build)
+ end
+
+ def should_email(email)
+ Notify.should_receive(:build_success_email).with(build.id, email)
+ Notify.should_not_receive(:build_fail_email).with(build.id, email)
+ end
+ end
+
+ describe 'successful build and notify only broken builds' do
+ let(:project) {
+ FactoryGirl.create(:project,
+ email_add_committer: true,
+ email_only_broken_builds: true,
+ email_recipients: "jeroen@example.com")
+ }
+ let(:commit) { FactoryGirl.create(:commit, project: project) }
+ let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
+
+ before do
+ mail.stub(
+ project: project
+ )
+ end
+
+ it do
+ should_email(commit.git_author_email)
+ should_email("jeroen@example.com")
+ mail.execute(build)
+ end
+
+ def should_email(email)
+ Notify.should_not_receive(:build_success_email).with(build.id, email)
+ Notify.should_not_receive(:build_fail_email).with(build.id, email)
+ end
+ end
+
+ describe 'successful build and can test service' do
+ let(:project) {
+ FactoryGirl.create(:project,
+ email_add_committer: true,
+ email_only_broken_builds: false,
+ email_recipients: "jeroen@example.com")
+ }
+ let(:commit) { FactoryGirl.create(:commit, project: project) }
+ let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
+
+ before do
+ mail.stub(
+ project: project
+ )
+ build
+ end
+
+ it do
+ mail.can_test?.should == true
+ end
+ end
+
+ describe 'successful build and cannot test service' do
+ let(:project) {
+ FactoryGirl.create(:project,
+ email_add_committer: true,
+ email_only_broken_builds: true,
+ email_recipients: "jeroen@example.com")
+ }
+ let(:commit) { FactoryGirl.create(:commit, project: project) }
+ let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
+
+ before do
+ mail.stub(
+ project: project
+ )
+ build
+ end
+
+ it do
+ mail.can_test?.should == false
+ end
+ end
+
+ describe 'retried build should not receive email' do
+ let(:project) {
+ FactoryGirl.create(:project,
+ email_add_committer: true,
+ email_only_broken_builds: true,
+ email_recipients: "jeroen@example.com")
+ }
+ let(:commit) { FactoryGirl.create(:commit, project: project) }
+ let(:build) { FactoryGirl.create(:build, status: :failed, commit: commit) }
+
+ before do
+ mail.stub(
+ project: project
+ )
+ end
+
+ it do
+ Build.retry(build)
+ should_email(commit.git_author_email)
+ should_email("jeroen@example.com")
+ mail.execute(build)
+ end
+
+ def should_email(email)
+ Notify.should_not_receive(:build_success_email).with(build.id, email)
+ Notify.should_not_receive(:build_fail_email).with(build.id, email)
+ end
+ end
+ end
+end
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
deleted file mode 100644
index 413523c..0000000
--- a/spec/services/notification_service_spec.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-require 'spec_helper'
-
-describe NotificationService do
- let(:notification) { NotificationService.new }
-
- describe 'Builds' do
-
- describe 'failed build' do
- let(:project) { FactoryGirl.create(:project) }
- let(:commit) { FactoryGirl.create(:commit, project: project) }
- let(:build) { FactoryGirl.create(:build, status: :failed, commit: commit) }
-
- it do
- should_email(commit.git_author_email)
- notification.build_ended(build)
- end
-
- def should_email(email)
- Notify.should_receive(:build_fail_email).with(build.id, email)
- Notify.should_not_receive(:build_success_email).with(build.id, email)
- end
- end
-
- describe 'successfull build' do
- let(:project) { FactoryGirl.create(:project) }
- let(:commit) { FactoryGirl.create(:commit, project: project) }
- let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
- it do
- should_email(commit.git_author_email)
- notification.build_ended(build)
- end
-
- def should_email(email)
- Notify.should_receive(:build_success_email).with(build.id, email)
- Notify.should_not_receive(:build_fail_email).with(build.id, email)
- end
- end
-
- describe 'successfull build and project has email_recipients' do
- let(:project) { FactoryGirl.create(:project, email_recipients: "jeroen@example.com") }
- let(:commit) { FactoryGirl.create(:commit, project: project) }
- let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
-
- it do
- should_email(commit.git_author_email)
- should_email("jeroen@example.com")
- notification.build_ended(build)
- end
-
- def should_email(email)
- Notify.should_receive(:build_success_email).with(build.id, email)
- Notify.should_not_receive(:build_fail_email).with(build.id, email)
- end
- end
- end
-end