summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-10-05 13:12:00 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2015-10-05 13:12:00 +0200
commitd2d2df0738f3cd8311963c34d90ebc8ce4081aa6 (patch)
treed3f342088131b73b62eb0e5cf494693fd80e5557 /spec
parent361dc3641dd28c4ecefbda94f7a8dad299c349aa (diff)
downloadgitlab-ce-d2d2df0738f3cd8311963c34d90ebc8ce4081aa6.tar.gz
Fix next round of tests
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/ci/commits.rb4
-rw-r--r--spec/features/ci/commits_spec.rb5
-rw-r--r--spec/lib/ci/gitlab_ci_yaml_processor_spec.rb12
-rw-r--r--spec/models/ci/build_spec.rb6
-rw-r--r--spec/models/ci/commit_spec.rb11
-rw-r--r--spec/models/ci/project_services/hip_chat_message_spec.rb6
-rw-r--r--spec/models/ci/project_services/mail_service_spec.rb13
-rw-r--r--spec/models/ci/project_services/slack_message_spec.rb6
-rw-r--r--spec/requests/ci/api/builds_spec.rb8
-rw-r--r--spec/services/ci/create_commit_service_spec.rb47
-rw-r--r--spec/support/stub_gitlab_calls.rb8
11 files changed, 72 insertions, 54 deletions
diff --git a/spec/factories/ci/commits.rb b/spec/factories/ci/commits.rb
index 9226e04a7b3..0c67e579a79 100644
--- a/spec/factories/ci/commits.rb
+++ b/spec/factories/ci/commits.rb
@@ -17,7 +17,7 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
- factory :ci_commit, class: Ci::Commit do
+ factory :ci_empty_commit, class: Ci::Commit do
sha '97de212e80737a608d939f648d959671fb0a0142'
gl_project factory: :empty_project
@@ -40,7 +40,7 @@ FactoryGirl.define do
end
end
- factory :ci_commit_yaml_stub do
+ factory :ci_commit do
after(:build) do |commit|
allow(commit).to receive(:ci_yaml_file) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) }
end
diff --git a/spec/features/ci/commits_spec.rb b/spec/features/ci/commits_spec.rb
index 657a9dabe9e..712a6137260 100644
--- a/spec/features/ci/commits_spec.rb
+++ b/spec/features/ci/commits_spec.rb
@@ -38,10 +38,9 @@ describe "Commits" do
end
it "shows warning" do
- @commit.push_data[:ci_yaml_file] = nil
- @commit.save
+ @commit_no_yaml = FactoryGirl.create :ci_empty_commit
- visit ci_commit_path(@commit)
+ visit ci_commit_path(@commit_no_yaml)
expect(page).to have_content ".gitlab-ci.yml not found in this commit"
end
diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
index 49482ac2b12..93568904d85 100644
--- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
@@ -20,8 +20,8 @@ module Ci
except: nil,
name: :rspec,
only: nil,
- script: "pwd\nrspec",
- tags: [],
+ commands: "pwd\nrspec",
+ tag_list: [],
options: {},
allow_failure: false
})
@@ -117,8 +117,8 @@ module Ci
stage: "test",
name: :rspec,
only: nil,
- script: "pwd\nrspec",
- tags: [],
+ commands: "pwd\nrspec",
+ tag_list: [],
options: {
image: "ruby:2.1",
services: ["mysql"]
@@ -143,8 +143,8 @@ module Ci
stage: "test",
name: :rspec,
only: nil,
- script: "pwd\nrspec",
- tags: [],
+ commands: "pwd\nrspec",
+ tag_list: [],
options: {
image: "ruby:2.5",
services: ["postgresql"]
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index d74063e5782..da56f6e31ae 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -28,7 +28,7 @@ require 'spec_helper'
describe Ci::Build do
let(:project) { FactoryGirl.create :ci_project }
let(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project }
- let(:commit) { FactoryGirl.create :ci_commit_yaml_stub, gl_project: gl_project }
+ let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
let(:build) { FactoryGirl.create :ci_build, commit: commit }
subject { build }
@@ -352,8 +352,8 @@ describe Ci::Build do
end
describe :project_recipients do
- let (:pusher_email) { 'pusher@gitlab.test' }
- let (:user) { User.new(notification_email: pusher_email) }
+ let(:pusher_email) { 'pusher@gitlab.test' }
+ let(:user) { User.new(notification_email: pusher_email) }
subject { build.project_recipients }
before do
diff --git a/spec/models/ci/commit_spec.rb b/spec/models/ci/commit_spec.rb
index 63602e89e37..d18220f119b 100644
--- a/spec/models/ci/commit_spec.rb
+++ b/spec/models/ci/commit_spec.rb
@@ -66,15 +66,6 @@ describe Ci::Commit do
end
describe :short_sha do
- subject { commit.short_before_sha }
-
- it 'has 8 items' do
- expect(subject.size).to eq(8)
- end
- it { expect(commit.before_sha).to start_with(subject) }
- end
-
- describe :short_sha do
subject { commit.short_sha }
it 'has 8 items' do
@@ -87,7 +78,7 @@ describe Ci::Commit do
end
describe :create_builds do
- let(:commit) { FactoryGirl.create :ci_commit_yaml_stub, gl_project: gl_project }
+ let(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
def create_builds(trigger_request = nil)
commit.create_builds('master', false, nil, trigger_request)
diff --git a/spec/models/ci/project_services/hip_chat_message_spec.rb b/spec/models/ci/project_services/hip_chat_message_spec.rb
index 1903c036924..6d257638359 100644
--- a/spec/models/ci/project_services/hip_chat_message_spec.rb
+++ b/spec/models/ci/project_services/hip_chat_message_spec.rb
@@ -7,7 +7,7 @@ describe Ci::HipChatMessage do
let(:commit) { FactoryGirl.create(:ci_commit_with_one_job) }
let(:build) do
- commit.create_builds
+ commit.create_builds('master', false, nil)
commit.builds.first
end
@@ -43,7 +43,7 @@ describe Ci::HipChatMessage do
context 'when all matrix builds succeed' do
it 'returns a successful message' do
- commit.create_builds
+ commit.create_builds('master', false, nil)
commit.builds.update_all(status: "success")
commit.reload
@@ -56,7 +56,7 @@ describe Ci::HipChatMessage do
context 'when at least one matrix build fails' do
it 'returns a failure message' do
- commit.create_builds
+ commit.create_builds('master', false, nil)
first_build = commit.builds.first
second_build = commit.builds.last
first_build.update(status: "success")
diff --git a/spec/models/ci/project_services/mail_service_spec.rb b/spec/models/ci/project_services/mail_service_spec.rb
index 0d9f85959ba..04e870dce7f 100644
--- a/spec/models/ci/project_services/mail_service_spec.rb
+++ b/spec/models/ci/project_services/mail_service_spec.rb
@@ -29,12 +29,13 @@ describe Ci::MailService do
describe 'Sends email for' do
let(:mail) { Ci::MailService.new }
+ let(:user) { User.new(notification_email: 'git@example.com')}
describe 'failed build' do
let(:project) { FactoryGirl.create(:ci_project, email_add_pusher: true) }
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
- let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit) }
+ let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit, user: user) }
before do
allow(mail).to receive_messages(
@@ -57,7 +58,7 @@ describe Ci::MailService do
let(:project) { FactoryGirl.create(:ci_project, email_add_pusher: true, email_only_broken_builds: false) }
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
- let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
+ let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit, user: user) }
before do
allow(mail).to receive_messages(
@@ -85,7 +86,7 @@ describe Ci::MailService do
end
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
- let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
+ let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit, user: user) }
before do
allow(mail).to receive_messages(
@@ -114,7 +115,7 @@ describe Ci::MailService do
end
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
- let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
+ let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit, user: user) }
before do
allow(mail).to receive_messages(
@@ -143,7 +144,7 @@ describe Ci::MailService do
end
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
- let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit) }
+ let(:build) { FactoryGirl.create(:ci_build, status: :success, commit: commit, user: user) }
before do
allow(mail).to receive_messages(
@@ -166,7 +167,7 @@ describe Ci::MailService do
end
let(:gl_project) { FactoryGirl.create(:empty_project, gitlab_ci_project: project) }
let(:commit) { FactoryGirl.create(:ci_commit, gl_project: gl_project) }
- let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit) }
+ let(:build) { FactoryGirl.create(:ci_build, status: :failed, commit: commit, user: user) }
before do
allow(mail).to receive_messages(
diff --git a/spec/models/ci/project_services/slack_message_spec.rb b/spec/models/ci/project_services/slack_message_spec.rb
index 7b541802d7d..0870276c78f 100644
--- a/spec/models/ci/project_services/slack_message_spec.rb
+++ b/spec/models/ci/project_services/slack_message_spec.rb
@@ -7,7 +7,7 @@ describe Ci::SlackMessage do
let(:commit) { FactoryGirl.create(:ci_commit_with_one_job) }
let(:build) do
- commit.create_builds
+ commit.create_builds('master', false, nil)
commit.builds.first
end
@@ -47,7 +47,7 @@ describe Ci::SlackMessage do
let(:color) { 'good' }
it 'returns a message with success' do
- commit.create_builds
+ commit.create_builds('master', false, nil)
commit.builds.update_all(status: "success")
commit.reload
@@ -63,7 +63,7 @@ describe Ci::SlackMessage do
let(:color) { 'danger' }
it 'returns a message with information about failed build' do
- commit.create_builds
+ commit.create_builds('master', false, nil)
first_build = commit.builds.first
second_build = commit.builds.last
first_build.update(status: "success")
diff --git a/spec/requests/ci/api/builds_spec.rb b/spec/requests/ci/api/builds_spec.rb
index bad250fbf48..576b0a11b9e 100644
--- a/spec/requests/ci/api/builds_spec.rb
+++ b/spec/requests/ci/api/builds_spec.rb
@@ -19,7 +19,7 @@ describe Ci::API::API do
describe "POST /builds/register" do
it "should start a build" do
commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
- commit.create_builds
+ commit.create_builds('master', false, nil)
build = commit.builds.first
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
@@ -55,7 +55,7 @@ describe Ci::API::API do
it "returns options" do
commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
- commit.create_builds
+ commit.create_builds('master', false, nil)
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
@@ -65,7 +65,7 @@ describe Ci::API::API do
it "returns variables" do
commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
- commit.create_builds
+ commit.create_builds('master', false, nil)
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
@@ -82,7 +82,7 @@ describe Ci::API::API do
commit = FactoryGirl.create(:ci_commit, gl_project: gl_project)
trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger)
- commit.create_builds(trigger_request)
+ commit.create_builds('master', false, nil, trigger_request)
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
diff --git a/spec/services/ci/create_commit_service_spec.rb b/spec/services/ci/create_commit_service_spec.rb
index 84ab0a615dd..a797f73565e 100644
--- a/spec/services/ci/create_commit_service_spec.rb
+++ b/spec/services/ci/create_commit_service_spec.rb
@@ -4,11 +4,16 @@ module Ci
describe CreateCommitService do
let(:service) { CreateCommitService.new }
let(:project) { FactoryGirl.create(:ci_project) }
+ let(:user) { nil }
+
+ before do
+ stub_ci_commit_to_return_yaml_file
+ end
describe :execute do
context 'valid params' do
let(:commit) do
- service.execute(project,
+ service.execute(project, user,
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
@@ -26,7 +31,7 @@ module Ci
context "skip tag if there is no build for it" do
it "creates commit if there is appropriate job" do
- result = service.execute(project,
+ result = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
@@ -38,8 +43,9 @@ module Ci
it "creates commit if there is no appropriate job but deploy job has right ref setting" do
config = YAML.dump({ deploy: { deploy: "ls", only: ["0_1"] } })
+ stub_ci_commit_yaml_file(config)
- result = service.execute(project,
+ result = service.execute(project, user,
ref: 'refs/heads/0_1',
before: '00000000',
after: '31das312',
@@ -51,11 +57,12 @@ module Ci
end
it 'fails commits without .gitlab-ci.yml' do
- result = service.execute(project,
+ stub_ci_commit_yaml_file(nil)
+ result = service.execute(project, user,
ref: 'refs/heads/0_1',
before: '00000000',
after: '31das312',
- ci_yaml_file: config,
+ ci_yaml_file: nil,
commits: [ { message: 'Message' } ]
)
expect(result).to be_persisted
@@ -64,9 +71,15 @@ module Ci
end
describe :ci_skip? do
+ let (:message) { "some message[ci skip]" }
+
+ before do
+ allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { message }
+ end
+
it "skips builds creation if there is [ci skip] tag in commit message" do
- commits = [{ message: "some message[ci skip]" }]
- commit = service.execute(project,
+ commits = [{ message: message }]
+ commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
@@ -78,9 +91,10 @@ module Ci
end
it "does not skips builds creation if there is no [ci skip] tag in commit message" do
- commits = [{ message: "some message" }]
+ allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { "some message" }
- commit = service.execute(project,
+ commits = [{ message: "some message" }]
+ commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
@@ -92,8 +106,9 @@ module Ci
end
it "skips builds creation if there is [ci skip] tag in commit message and yaml is invalid" do
- commits = [{ message: "some message[ci skip]" }]
- commit = service.execute(project,
+ stub_ci_commit_yaml_file('invalid: file')
+ commits = [{ message: message }]
+ commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
@@ -106,8 +121,10 @@ module Ci
end
it "skips build creation if there are already builds" do
+ allow_any_instance_of(Ci::Commit).to receive(:ci_yaml_file) { gitlab_ci_yaml }
+
commits = [{ message: "message" }]
- commit = service.execute(project,
+ commit = service.execute(project, user,
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
@@ -116,7 +133,7 @@ module Ci
)
expect(commit.builds.count(:all)).to eq(2)
- commit = service.execute(project,
+ commit = service.execute(project, user,
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
@@ -127,9 +144,11 @@ module Ci
end
it "creates commit with failed status if yaml is invalid" do
+ stub_ci_commit_yaml_file('invalid: file')
+
commits = [{ message: "some message" }]
- commit = service.execute(project,
+ commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
diff --git a/spec/support/stub_gitlab_calls.rb b/spec/support/stub_gitlab_calls.rb
index 5e6744afda1..5b3eb1bfc5f 100644
--- a/spec/support/stub_gitlab_calls.rb
+++ b/spec/support/stub_gitlab_calls.rb
@@ -13,6 +13,14 @@ module StubGitlabCalls
allow_any_instance_of(Network).to receive(:projects) { project_hash_array }
end
+ def stub_ci_commit_to_return_yaml_file
+ stub_ci_commit_yaml_file(gitlab_ci_yaml)
+ end
+
+ def stub_ci_commit_yaml_file(ci_yaml)
+ allow_any_instance_of(Ci::Commit).to receive(:ci_yaml_file) { ci_yaml }
+ end
+
private
def gitlab_url