diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-11-19 01:02:49 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-11-19 01:02:49 +0800 |
commit | b6a7a4783435a7fa34f26dbf3b16ab8e7ed21b88 (patch) | |
tree | ea414e11405c902f58089f307e3b40f6ec34398b /spec/models/concerns | |
parent | 100076ecbbdf3eae361a6356ddfb55b1694e4741 (diff) | |
download | gitlab-ce-b6a7a4783435a7fa34f26dbf3b16ab8e7ed21b88.tar.gz |
Add a lot of tests for scopes, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7508#note_18622499
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/has_status_spec.rb | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/spec/models/concerns/has_status_spec.rb b/spec/models/concerns/has_status_spec.rb index 87bffbdc54e..24cd435256e 100644 --- a/spec/models/concerns/has_status_spec.rb +++ b/spec/models/concerns/has_status_spec.rb @@ -123,4 +123,81 @@ describe HasStatus do it_behaves_like 'build status summary' end end + + def self.random_type + %i[ci_build generic_commit_status].sample + end + + context 'for scope with one status' do + shared_examples 'having a job' do |type, status| + context "when it's #{status} #{type} job" do + let!(:job) { create(type, status) } + + describe ".#{status}" do + subject { CommitStatus.public_send(status).all } + + it { is_expected.to contain_exactly(job) } + end + + describe '.relevant' do + subject { CommitStatus.relevant.all } + + it do + case status + when :created + is_expected.to be_empty + else + is_expected.to contain_exactly(job) + end + end + end + end + end + + %i[created running pending success + failed canceled skipped].each do |status| + it_behaves_like 'having a job', random_type, status + end + end + + context 'for scope with more statuses' do + shared_examples 'having a job' do |type, status, excluded_status| + context "when it's #{status} #{type} job" do + let!(:job) { create(type, status) } + + it do + case status + when excluded_status + is_expected.to be_empty + else + is_expected.to contain_exactly(job) + end + end + end + end + + describe '.running_or_pending' do + subject { CommitStatus.running_or_pending } + + %i[running pending created].each do |status| + it_behaves_like 'having a job', random_type, status, :created + end + end + + describe '.finished' do + subject { CommitStatus.finished } + + %i[success failed canceled created].each do |status| + it_behaves_like 'having a job', random_type, status, :created + end + end + + describe '.cancelable' do + subject { CommitStatus.cancelable } + + %i[running pending created failed].each do |status| + it_behaves_like 'having a job', random_type, status, :failed + end + end + end end |