debian-mirror-gitlab/spec/models/import_failure_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
2.3 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe ImportFailure do
2020-04-22 19:07:51 +05:30
describe 'Scopes' do
let_it_be(:project) { create(:project) }
let_it_be(:correlation_id) { 'ABC' }
let_it_be(:hard_failure) { create(:import_failure, :hard_failure, project: project, correlation_id_value: correlation_id) }
let_it_be(:soft_failure) { create(:import_failure, :soft_failure, project: project, correlation_id_value: correlation_id) }
let_it_be(:unrelated_failure) { create(:import_failure, project: project) }
2023-05-27 22:25:52 +05:30
it 'returns failures for the given correlation ID' do
expect(ImportFailure.failures_by_correlation_id(correlation_id)).to match_array([hard_failure, soft_failure])
end
it 'returns hard failures for the given correlation ID' do
2020-04-22 19:07:51 +05:30
expect(ImportFailure.hard_failures_by_correlation_id(correlation_id)).to eq([hard_failure])
end
it 'orders hard failures by newest first' do
older_failure = hard_failure.dup
2021-01-03 14:25:43 +05:30
travel_to(1.day.before(hard_failure.created_at)) do
2020-04-22 19:07:51 +05:30
older_failure.save!
expect(ImportFailure.hard_failures_by_correlation_id(correlation_id)).to eq([hard_failure, older_failure])
end
end
end
describe 'Associations' do
2020-03-13 15:44:24 +05:30
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:group) }
end
describe 'Validations' do
context 'has no group' do
before do
allow(subject).to receive(:group).and_return(nil)
end
it { is_expected.to validate_presence_of(:project) }
end
context 'has no project' do
before do
allow(subject).to receive(:project).and_return(nil)
end
it { is_expected.to validate_presence_of(:group) }
end
2023-05-27 22:25:52 +05:30
describe '#external_identifiers' do
it { is_expected.to allow_value({ note_id: 234, noteable_id: 345, noteable_type: 'MergeRequest' }).for(:external_identifiers) }
it { is_expected.not_to allow_value(nil).for(:external_identifiers) }
it { is_expected.not_to allow_value({ ids: [123] }).for(:external_identifiers) }
it 'allows up to 3 fields' do
2023-06-20 00:43:36 +05:30
is_expected.not_to allow_value({
note_id: 234,
noteable_id: 345,
noteable_type: 'MergeRequest',
object_type: 'pull_request',
extra_attribute: 'abc'
}).for(:external_identifiers)
2023-05-27 22:25:52 +05:30
end
end
2020-03-13 15:44:24 +05:30
end
end