Commit 752a4cce authored by Lin Jen-Shin's avatar Lin Jen-Shin

Add test for CommitStatus.exclude_ignored

parent 9c230600
...@@ -38,7 +38,6 @@ class CommitStatus < ActiveRecord::Base ...@@ -38,7 +38,6 @@ class CommitStatus < ActiveRecord::Base
where("#{quoted_when} <> ? OR status <> ?", 'manual', 'skipped'). where("#{quoted_when} <> ? OR status <> ?", 'manual', 'skipped').
# We want to ignore skipped on_failure # We want to ignore skipped on_failure
where("#{quoted_when} <> ? OR status <> ?", 'on_failure', 'skipped') where("#{quoted_when} <> ? OR status <> ?", 'on_failure', 'skipped')
end end
scope :latest_ci_stages, -> { latest.ordered.includes(project: :namespace) } scope :latest_ci_stages, -> { latest.ordered.includes(project: :namespace) }
......
...@@ -7,7 +7,11 @@ describe CommitStatus, models: true do ...@@ -7,7 +7,11 @@ describe CommitStatus, models: true do
create(:ci_pipeline, project: project, sha: project.commit.id) create(:ci_pipeline, project: project, sha: project.commit.id)
end end
let(:commit_status) { create(:commit_status, pipeline: pipeline) } let(:commit_status) { create_status }
def create_status(args = {})
create(:commit_status, args.merge(pipeline: pipeline))
end
it { is_expected.to belong_to(:pipeline) } it { is_expected.to belong_to(:pipeline) }
it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:user) }
...@@ -125,32 +129,53 @@ describe CommitStatus, models: true do ...@@ -125,32 +129,53 @@ describe CommitStatus, models: true do
describe '.latest' do describe '.latest' do
subject { CommitStatus.latest.order(:id) } subject { CommitStatus.latest.order(:id) }
before do let(:statuses) do
@commit1 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: 'bb', status: 'running' [create_status(name: 'aa', ref: 'bb', status: 'running'),
@commit2 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'cc', ref: 'cc', status: 'pending' create_status(name: 'cc', ref: 'cc', status: 'pending'),
@commit3 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: 'cc', status: 'success' create_status(name: 'aa', ref: 'cc', status: 'success'),
@commit4 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'cc', ref: 'bb', status: 'success' create_status(name: 'cc', ref: 'bb', status: 'success'),
@commit5 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: 'bb', status: 'success' create_status(name: 'aa', ref: 'bb', status: 'success')]
end end
it 'returns unique statuses' do it 'returns unique statuses' do
is_expected.to eq([@commit4, @commit5]) is_expected.to eq(statuses.values_at(3, 4))
end end
end end
describe '.running_or_pending' do describe '.running_or_pending' do
subject { CommitStatus.running_or_pending.order(:id) } subject { CommitStatus.running_or_pending.order(:id) }
before do let(:statuses) do
@commit1 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: 'bb', status: 'running' [create_status(name: 'aa', ref: 'bb', status: 'running'),
@commit2 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'cc', ref: 'cc', status: 'pending' create_status(name: 'cc', ref: 'cc', status: 'pending'),
@commit3 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'aa', ref: nil, status: 'success' create_status(name: 'aa', ref: nil, status: 'success'),
@commit4 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'dd', ref: nil, status: 'failed' create_status(name: 'dd', ref: nil, status: 'failed'),
@commit5 = FactoryGirl.create :commit_status, pipeline: pipeline, name: 'ee', ref: nil, status: 'canceled' create_status(name: 'ee', ref: nil, status: 'canceled')]
end end
it 'returns statuses that are running or pending' do it 'returns statuses that are running or pending' do
is_expected.to eq([@commit1, @commit2]) is_expected.to eq(statuses.values_at(0, 1))
end
end
describe '.exclude_ignored' do
subject { CommitStatus.exclude_ignored.order(:id) }
let(:statuses) do
[create_status(when: 'manual', status: 'skipped'),
create_status(when: 'manual', status: 'success'),
create_status(when: 'manual', status: 'failed'),
create_status(when: 'on_failure', status: 'skipped'),
create_status(when: 'on_failure', status: 'success'),
create_status(when: 'on_failure', status: 'failed'),
create_status(allow_failure: true, status: 'success'),
create_status(allow_failure: true, status: 'failed'),
create_status(allow_failure: false, status: 'success'),
create_status(allow_failure: false, status: 'failed')]
end
it 'returns statuses without what we want to ignore' do
is_expected.to eq(statuses.values_at(1, 2, 4, 5, 6, 8, 9))
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