Commit 1edb1746 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Prefer a description for it and split the case:

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7508#note_18730091
parent ca639c9b
...@@ -403,15 +403,15 @@ describe Ci::Pipeline, models: true do ...@@ -403,15 +403,15 @@ describe Ci::Pipeline, models: true do
end end
describe '#cancelable?' do describe '#cancelable?' do
subject { pipeline.cancelable? }
%i[created running pending].each do |status| %i[created running pending].each do |status|
context "when there is a build #{status}" do context "when there is a build #{status}" do
before do before do
create(:ci_build, status, pipeline: pipeline) create(:ci_build, status, pipeline: pipeline)
end end
it { is_expected.to be_truthy } it 'is cancelable' do
expect(pipeline.cancelable?).to be_truthy
end
end end
context "when there is an external job #{status}" do context "when there is an external job #{status}" do
...@@ -419,7 +419,9 @@ describe Ci::Pipeline, models: true do ...@@ -419,7 +419,9 @@ describe Ci::Pipeline, models: true do
create(:generic_commit_status, status, pipeline: pipeline) create(:generic_commit_status, status, pipeline: pipeline)
end end
it { is_expected.to be_truthy } it 'is cancelable' do
expect(pipeline.cancelable?).to be_truthy
end
end end
%i[success failed canceled].each do |status2| %i[success failed canceled].each do |status2|
...@@ -430,7 +432,9 @@ describe Ci::Pipeline, models: true do ...@@ -430,7 +432,9 @@ describe Ci::Pipeline, models: true do
create(build.sample, status2, pipeline: pipeline) create(build.sample, status2, pipeline: pipeline)
end end
it { is_expected.to be_truthy } it 'is cancelable' do
expect(pipeline.cancelable?).to be_truthy
end
end end
end end
end end
...@@ -441,7 +445,9 @@ describe Ci::Pipeline, models: true do ...@@ -441,7 +445,9 @@ describe Ci::Pipeline, models: true do
create(:ci_build, status, pipeline: pipeline) create(:ci_build, status, pipeline: pipeline)
end end
it { is_expected.to be_falsey } it 'is not cancelable' do
expect(pipeline.cancelable?).to be_falsey
end
end end
context "when there is an external job #{status}" do context "when there is an external job #{status}" do
...@@ -449,7 +455,9 @@ describe Ci::Pipeline, models: true do ...@@ -449,7 +455,9 @@ describe Ci::Pipeline, models: true do
create(:generic_commit_status, status, pipeline: pipeline) create(:generic_commit_status, status, pipeline: pipeline)
end end
it { is_expected.to be_falsey } it 'is not cancelable' do
expect(pipeline.cancelable?).to be_falsey
end
end end
end end
end end
......
...@@ -134,20 +134,20 @@ describe HasStatus do ...@@ -134,20 +134,20 @@ describe HasStatus do
let!(:job) { create(type, status) } let!(:job) { create(type, status) }
describe ".#{status}" do describe ".#{status}" do
subject { CommitStatus.public_send(status).all } it 'contains the job' do
expect(CommitStatus.public_send(status).all).
it { is_expected.to contain_exactly(job) } to contain_exactly(job)
end
end end
describe '.relevant' do describe '.relevant' do
subject { CommitStatus.relevant.all } if status == :created
it 'contains nothing' do
it do expect(CommitStatus.relevant.all).to be_empty
case status end
when :created
is_expected.to be_empty
else else
is_expected.to contain_exactly(job) it 'contains the job' do
expect(CommitStatus.relevant.all).to contain_exactly(job)
end end
end end
end end
...@@ -161,43 +161,54 @@ describe HasStatus do ...@@ -161,43 +161,54 @@ describe HasStatus do
end end
context 'for scope with more statuses' do context 'for scope with more statuses' do
shared_examples 'having a job' do |type, status, excluded_status| shared_examples 'containing the job' do |type, status|
context "when it's #{status} #{type} job" do context "when it's #{status} #{type} job" do
let!(:job) { create(type, status) } let!(:job) { create(type, status) }
it do it 'contains the job' do
case status
when excluded_status
is_expected.to be_empty
else
is_expected.to contain_exactly(job) is_expected.to contain_exactly(job)
end end
end end
end end
shared_examples 'not containing the job' do |type, status|
context "when it's #{status} #{type} job" do
let!(:job) { create(type, status) }
it 'contains nothing' do
is_expected.to be_empty
end
end
end end
describe '.running_or_pending' do describe '.running_or_pending' do
subject { CommitStatus.running_or_pending } subject { CommitStatus.running_or_pending }
%i[running pending created].each do |status| %i[running pending].each do |status|
it_behaves_like 'having a job', random_type, status, :created it_behaves_like 'containing the job', random_type, status
end end
it_behaves_like 'not containing the job', random_type, :created
end end
describe '.finished' do describe '.finished' do
subject { CommitStatus.finished } subject { CommitStatus.finished }
%i[success failed canceled created].each do |status| %i[success failed canceled].each do |status|
it_behaves_like 'having a job', random_type, status, :created it_behaves_like 'containing the job', random_type, status
end end
it_behaves_like 'not containing the job', random_type, :created
end end
describe '.cancelable' do describe '.cancelable' do
subject { CommitStatus.cancelable } subject { CommitStatus.cancelable }
%i[running pending created failed].each do |status| %i[running pending created].each do |status|
it_behaves_like 'having a job', random_type, status, :failed it_behaves_like 'containing the job', random_type, status
end end
it_behaves_like 'not containing the job', random_type, :failed
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment