summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-01-29 16:36:10 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2015-01-29 16:38:20 +0100
commit7cb0a536330f36d67aae007617f11cab25e77c5a (patch)
tree2eb42d7d5bacba30f038234b978eac33dcd0bb22
parentb24744aee7f2221d462bf6433c48254a6b0996ca (diff)
downloadgitlab-ci-7cb0a536330f36d67aae007617f11cab25e77c5a.tar.gz
Fixed tests
-rw-r--r--app/models/project.rb6
-rw-r--r--lib/api/projects.rb1
-rw-r--r--spec/factories/commits.rb24
-rw-r--r--spec/models/mail_service_spec.rb122
4 files changed, 138 insertions, 15 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 4877bed..7186d37 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -64,8 +64,6 @@ class Project < ActiveRecord::Base
before_validation :set_default_values
- after_initialize :build_missing_services
-
class << self
def base_build_script
<<-eos
@@ -87,7 +85,9 @@ ls -la
email_only_broken_builds: GitlabCi.config.gitlab_ci.all_broken_builds,
}
- Project.new(params)
+ project = Project.new(params)
+ project.build_missing_services
+ project
end
def from_gitlab(user, page, per_page, scope = :owned)
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 632aa51..a3cc9f3 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -94,6 +94,7 @@ module API
}
project = Project.new(filtered_params)
+ project.build_missing_services
project.build_default_job
if project.save
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
index 70f4253..7a43978 100644
--- a/spec/models/mail_service_spec.rb
+++ b/spec/models/mail_service_spec.rb
@@ -17,14 +17,13 @@ describe MailService do
let(:mail) { MailService.new }
describe 'failed build' do
- let(:project) { FactoryGirl.create(:project) }
+ 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,
- project_id: project.id
+ project: project
)
end
@@ -40,14 +39,13 @@ describe MailService do
end
describe 'successfull build' do
- let(:project) { FactoryGirl.create(:project) }
+ 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,
- project_id: project.id
+ project: project
)
end
@@ -63,15 +61,18 @@ describe MailService do
end
describe 'successfull build and project has email_recipients' do
- let(:project) { FactoryGirl.create(:project, email_recipients: "jeroen@example.com") }
+ 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) }
- let(:recipients) { "jeroen@example.com" }
before do
mail.stub(
- project: project,
- project_id: project.id
+ project: project
)
end
@@ -86,5 +87,106 @@ describe MailService do
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