fix part of specs
This commit is contained in:
parent
4c53cc0eba
commit
2c4daf1a68
3 changed files with 105 additions and 103 deletions
|
@ -9,7 +9,7 @@ describe "Builds" do
|
|||
|
||||
describe "GET /:project/builds/:id/status.json" do
|
||||
before do
|
||||
get status_project_build_path(@project, @build), format: :json
|
||||
get status_ci_project_build_path(@project, @build), format: :json
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq(200) }
|
||||
|
|
|
@ -8,7 +8,7 @@ describe "Commits" do
|
|||
|
||||
describe "GET /:project/refs/:ref_name/commits/:id/status.json" do
|
||||
before do
|
||||
get status_project_ref_commit_path(@project, @commit.ref, @commit.sha), format: :json
|
||||
get status_ci_project_ref_commits_path(@project, @commit.ref, @commit.sha), format: :json
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq(200) }
|
||||
|
|
|
@ -1,84 +1,121 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Ci::CreateCommitService do
|
||||
let(:service) { CreateCommitService.new }
|
||||
let(:project) { FactoryGirl.create(:project) }
|
||||
module Ci
|
||||
describe CreateCommitService do
|
||||
let(:service) { CreateCommitService.new }
|
||||
let(:project) { FactoryGirl.create(:ci_project) }
|
||||
|
||||
describe :execute do
|
||||
context 'valid params' do
|
||||
let(:commit) do
|
||||
service.execute(project,
|
||||
describe :execute do
|
||||
context 'valid params' do
|
||||
let(:commit) do
|
||||
service.execute(project,
|
||||
ref: 'refs/heads/master',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
ci_yaml_file: gitlab_ci_yaml,
|
||||
commits: [ { message: "Message" } ]
|
||||
)
|
||||
end
|
||||
|
||||
it { expect(commit).to be_kind_of(Commit) }
|
||||
it { expect(commit).to be_valid }
|
||||
it { expect(commit).to be_persisted }
|
||||
it { expect(commit).to eq(project.commits.last) }
|
||||
it { expect(commit.builds.first).to be_kind_of(Build) }
|
||||
end
|
||||
|
||||
context "skip tag if there is no build for it" do
|
||||
it "creates commit if there is appropriate job" do
|
||||
result = service.execute(project,
|
||||
ref: 'refs/tags/0_1',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
ci_yaml_file: gitlab_ci_yaml,
|
||||
commits: [ { message: "Message" } ]
|
||||
)
|
||||
expect(result).to be_persisted
|
||||
end
|
||||
|
||||
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"] } })
|
||||
|
||||
result = service.execute(project,
|
||||
ref: 'refs/heads/0_1',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
ci_yaml_file: config,
|
||||
commits: [ { message: "Message" } ]
|
||||
)
|
||||
expect(result).to be_persisted
|
||||
end
|
||||
end
|
||||
|
||||
describe :ci_skip? do
|
||||
it "skips builds creation if there is [ci skip] tag in commit message" do
|
||||
commits = [{ message: "some message[ci skip]" }]
|
||||
commit = service.execute(project,
|
||||
ref: 'refs/tags/0_1',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
commits: commits,
|
||||
ci_yaml_file: gitlab_ci_yaml
|
||||
)
|
||||
expect(commit.builds.any?).to be false
|
||||
expect(commit.status).to eq("skipped")
|
||||
end
|
||||
|
||||
it "does not skips builds creation if there is no [ci skip] tag in commit message" do
|
||||
commits = [{ message: "some message" }]
|
||||
|
||||
commit = service.execute(project,
|
||||
ref: 'refs/tags/0_1',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
commits: commits,
|
||||
ci_yaml_file: gitlab_ci_yaml
|
||||
)
|
||||
|
||||
expect(commit.builds.first.name).to eq("staging")
|
||||
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,
|
||||
ref: 'refs/tags/0_1',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
commits: commits,
|
||||
ci_yaml_file: "invalid: file"
|
||||
)
|
||||
expect(commit.builds.any?).to be false
|
||||
expect(commit.status).to eq("skipped")
|
||||
end
|
||||
end
|
||||
|
||||
it "skips build creation if there are already builds" do
|
||||
commits = [{ message: "message" }]
|
||||
commit = service.execute(project,
|
||||
ref: 'refs/heads/master',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
ci_yaml_file: gitlab_ci_yaml,
|
||||
commits: [ { message: "Message" } ]
|
||||
commits: commits,
|
||||
ci_yaml_file: gitlab_ci_yaml
|
||||
)
|
||||
end
|
||||
expect(commit.builds.count(:all)).to eq(2)
|
||||
|
||||
it { commit.should be_kind_of(Commit) }
|
||||
it { commit.should be_valid }
|
||||
it { commit.should be_persisted }
|
||||
it { commit.should == project.commits.last }
|
||||
it { commit.builds.first.should be_kind_of(Build) }
|
||||
end
|
||||
|
||||
context "skip tag if there is no build for it" do
|
||||
it "creates commit if there is appropriate job" do
|
||||
result = service.execute(project,
|
||||
ref: 'refs/tags/0_1',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
ci_yaml_file: gitlab_ci_yaml,
|
||||
commits: [ { message: "Message" } ]
|
||||
)
|
||||
result.should be_persisted
|
||||
end
|
||||
|
||||
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"] } })
|
||||
|
||||
result = service.execute(project,
|
||||
ref: 'refs/heads/0_1',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
ci_yaml_file: config,
|
||||
commits: [ { message: "Message" } ]
|
||||
)
|
||||
result.should be_persisted
|
||||
end
|
||||
end
|
||||
|
||||
describe :ci_skip? do
|
||||
it "skips builds creation if there is [ci skip] tag in commit message" do
|
||||
commits = [{ message: "some message[ci skip]" }]
|
||||
commit = service.execute(project,
|
||||
ref: 'refs/tags/0_1',
|
||||
ref: 'refs/heads/master',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
commits: commits,
|
||||
ci_yaml_file: gitlab_ci_yaml
|
||||
)
|
||||
commit.builds.any?.should be_false
|
||||
commit.status.should == "skipped"
|
||||
expect(commit.builds.count(:all)).to eq(2)
|
||||
end
|
||||
|
||||
it "does not skips builds creation if there is no [ci skip] tag in commit message" do
|
||||
it "creates commit with failed status if yaml is invalid" do
|
||||
commits = [{ message: "some message" }]
|
||||
|
||||
commit = service.execute(project,
|
||||
ref: 'refs/tags/0_1',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
commits: commits,
|
||||
ci_yaml_file: gitlab_ci_yaml
|
||||
)
|
||||
|
||||
commit.builds.first.name.should == "staging"
|
||||
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,
|
||||
ref: 'refs/tags/0_1',
|
||||
before: '00000000',
|
||||
|
@ -86,45 +123,10 @@ describe Ci::CreateCommitService do
|
|||
commits: commits,
|
||||
ci_yaml_file: "invalid: file"
|
||||
)
|
||||
commit.builds.any?.should be_false
|
||||
commit.status.should == "skipped"
|
||||
|
||||
expect(commit.status).to eq("failed")
|
||||
expect(commit.builds.any?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
it "skips build creation if there are already builds" do
|
||||
commits = [{ message: "message" }]
|
||||
commit = service.execute(project,
|
||||
ref: 'refs/heads/master',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
commits: commits,
|
||||
ci_yaml_file: gitlab_ci_yaml
|
||||
)
|
||||
commit.builds.count(:all).should == 2
|
||||
|
||||
commit = service.execute(project,
|
||||
ref: 'refs/heads/master',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
commits: commits,
|
||||
ci_yaml_file: gitlab_ci_yaml
|
||||
)
|
||||
commit.builds.count(:all).should == 2
|
||||
end
|
||||
|
||||
it "creates commit with failed status if yaml is invalid" do
|
||||
commits = [{ message: "some message" }]
|
||||
|
||||
commit = service.execute(project,
|
||||
ref: 'refs/tags/0_1',
|
||||
before: '00000000',
|
||||
after: '31das312',
|
||||
commits: commits,
|
||||
ci_yaml_file: "invalid: file"
|
||||
)
|
||||
|
||||
commit.status.should == "failed"
|
||||
commit.builds.any?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue