Commit d09d6ad0 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Test against all types and more status:

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7508#note_18748231
parent 9b124078
...@@ -124,30 +124,28 @@ describe HasStatus do ...@@ -124,30 +124,28 @@ describe HasStatus do
end end
end end
def self.random_type
%i[ci_build generic_commit_status].sample
end
context 'for scope with one status' do context 'for scope with one status' do
shared_examples 'having a job' do |type, status| shared_examples 'having a job' do |status|
context "when it's #{status} #{type} job" do %i[ci_build generic_commit_status].each do |type|
let!(:job) { create(type, status) } context "when it's #{status} #{type} job" do
let!(:job) { create(type, status) }
describe ".#{status}" do describe ".#{status}" do
it 'contains the job' do it 'contains the job' do
expect(CommitStatus.public_send(status).all). expect(CommitStatus.public_send(status).all).
to contain_exactly(job) to contain_exactly(job)
end
end end
end
describe '.relevant' do describe '.relevant' do
if status == :created if status == :created
it 'contains nothing' do it 'contains nothing' do
expect(CommitStatus.relevant.all).to be_empty expect(CommitStatus.relevant.all).to be_empty
end end
else else
it 'contains the job' do it 'contains the job' do
expect(CommitStatus.relevant.all).to contain_exactly(job) expect(CommitStatus.relevant.all).to contain_exactly(job)
end
end end
end end
end end
...@@ -156,27 +154,31 @@ describe HasStatus do ...@@ -156,27 +154,31 @@ describe HasStatus do
%i[created running pending success %i[created running pending success
failed canceled skipped].each do |status| failed canceled skipped].each do |status|
it_behaves_like 'having a job', random_type, status it_behaves_like 'having a job', status
end end
end end
context 'for scope with more statuses' do context 'for scope with more statuses' do
shared_examples 'containing the job' do |type, status| shared_examples 'containing the job' do |status|
context "when it's #{status} #{type} job" do %i[ci_build generic_commit_status].each do |type|
let!(:job) { create(type, status) } context "when it's #{status} #{type} job" do
let!(:job) { create(type, status) }
it 'contains the job' do it 'contains the job' do
is_expected.to contain_exactly(job) is_expected.to contain_exactly(job)
end
end end
end end
end end
shared_examples 'not containing the job' do |type, status| shared_examples 'not containing the job' do |status|
context "when it's #{status} #{type} job" do %i[ci_build generic_commit_status].each do |type|
let!(:job) { create(type, status) } context "when it's #{status} #{type} job" do
let!(:job) { create(type, status) }
it 'contains nothing' do it 'contains nothing' do
is_expected.to be_empty is_expected.to be_empty
end
end end
end end
end end
...@@ -185,30 +187,36 @@ describe HasStatus do ...@@ -185,30 +187,36 @@ describe HasStatus do
subject { CommitStatus.running_or_pending } subject { CommitStatus.running_or_pending }
%i[running pending].each do |status| %i[running pending].each do |status|
it_behaves_like 'containing the job', random_type, status it_behaves_like 'containing the job', status
end end
it_behaves_like 'not containing the job', random_type, :created %i[created failed success].each do |status|
it_behaves_like 'not containing the job', status
end
end end
describe '.finished' do describe '.finished' do
subject { CommitStatus.finished } subject { CommitStatus.finished }
%i[success failed canceled].each do |status| %i[success failed canceled].each do |status|
it_behaves_like 'containing the job', random_type, status it_behaves_like 'containing the job', status
end end
it_behaves_like 'not containing the job', random_type, :created %i[created running pending].each do |status|
it_behaves_like 'not containing the job', status
end
end end
describe '.cancelable' do describe '.cancelable' do
subject { CommitStatus.cancelable } subject { CommitStatus.cancelable }
%i[running pending created].each do |status| %i[running pending created].each do |status|
it_behaves_like 'containing the job', random_type, status it_behaves_like 'containing the job', status
end end
it_behaves_like 'not containing the job', random_type, :failed %i[failed success skipped canceled].each do |status|
it_behaves_like 'not containing the job', status
end
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