Commit 53a3e898 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'fix-specs-to-support-parent-strategy-in-factories-4' into 'master'

Refactor tests to support Parent Strategy in factories

See merge request gitlab-org/gitlab!41759
parents 94990404 ee61b10a
......@@ -20,7 +20,9 @@ RSpec.describe Ci::JobArtifact do
it_behaves_like 'having unique enum values'
it_behaves_like 'UpdateProjectStatistics' do
subject { build(:ci_job_artifact, :archive, size: 107464) }
let_it_be(:job, reload: true) { create(:ci_build) }
subject { build(:ci_job_artifact, :archive, job: job, size: 107464) }
end
describe '.not_expired' do
......
......@@ -13,7 +13,9 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
it_behaves_like 'having unique enum values'
it_behaves_like 'UpdateProjectStatistics' do
subject { build(:ci_pipeline_artifact) }
let_it_be(:pipeline, reload: true) { create(:ci_pipeline) }
subject { build(:ci_pipeline_artifact, pipeline: pipeline) }
end
describe 'validations' do
......
......@@ -33,15 +33,17 @@ RSpec.describe Packages::PackageFile, type: :model do
end
context 'updating project statistics' do
let_it_be(:package, reload: true) { create(:package) }
context 'when the package file has an explicit size' do
it_behaves_like 'UpdateProjectStatistics' do
subject { build(:package_file, :jar, size: 42) }
subject { build(:package_file, :jar, package: package, size: 42) }
end
end
context 'when the package file does not have a size' do
it_behaves_like 'UpdateProjectStatistics' do
subject { build(:package_file, size: nil) }
subject { build(:package_file, package: package, size: nil) }
end
end
end
......
......@@ -5,6 +5,8 @@ require 'spec_helper'
RSpec.describe TestCaseEntity do
include TestReportsHelper
let_it_be(:job) { create(:ci_build) }
let(:entity) { described_class.new(test_case) }
describe '#as_json' do
......@@ -38,7 +40,7 @@ RSpec.describe TestCaseEntity do
end
context 'when attachment is present' do
let(:test_case) { build(:test_case, :failed_with_attachment) }
let(:test_case) { build(:test_case, :failed_with_attachment, job: job) }
it 'returns the attachment_url' do
expect(subject).to include(:attachment_url)
......@@ -46,7 +48,7 @@ RSpec.describe TestCaseEntity do
end
context 'when attachment is not present' do
let(:test_case) { build(:test_case) }
let(:test_case) { build(:test_case, job: job) }
it 'returns a nil attachment_url' do
expect(subject[:attachment_url]).to be_nil
......@@ -60,7 +62,7 @@ RSpec.describe TestCaseEntity do
end
context 'when attachment is present' do
let(:test_case) { build(:test_case, :failed_with_attachment) }
let(:test_case) { build(:test_case, :failed_with_attachment, job: job) }
it 'returns no attachment_url' do
expect(subject).not_to include(:attachment_url)
......@@ -68,7 +70,7 @@ RSpec.describe TestCaseEntity do
end
context 'when attachment is not present' do
let(:test_case) { build(:test_case) }
let(:test_case) { build(:test_case, job: job) }
it 'returns no attachment_url' do
expect(subject).not_to include(:attachment_url)
......
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