Commit a07c7590 authored by Etienne Baqué's avatar Etienne Baqué

Fixed some tests based on code review comments

Did some refactoring in entities files.
Did some refactoring in the release spec file.
parent a4d9e9f2
......@@ -38,7 +38,7 @@ class ReleasePresenter < Gitlab::View::Presenter::Delegated
end
def evidence_file_path
return unless release_evidence_available?
return unless release.evidence.present?
evidence_project_release_url(project, tag, format: :json)
end
......@@ -60,8 +60,4 @@ class ReleasePresenter < Gitlab::View::Presenter::Delegated
def release_edit_page_available?
::Feature.enabled?(:release_edit_page, project, default_enabled: true)
end
def release_evidence_available?
release.evidence.present?
end
end
......@@ -1315,7 +1315,7 @@ module API
expose :milestones, using: Entities::Milestone, if: -> (release, _) { release.milestones.present? }
expose :commit_path, expose_nil: false
expose :tag_path, expose_nil: false
expose :evidence_sha, if: -> (release, _) { release.evidence.present? }
expose :evidence_sha, expose_nil: false
expose :assets do
expose :assets_count, as: :count do |release, _|
assets_to_exclude = can_download_code? ? [] : [:sources]
......
......@@ -186,15 +186,17 @@ describe Projects::ReleasesController do
it 'returns the correct evidence summary as a json' do
subject
expect(response.body).to eq(release.evidence.summary.to_json)
expect(json_response).to eq(release.evidence.summary)
end
context 'when the release was created before evidence existed' do
it 'returns an empty json' do
release.evidence.destroy
subject
expect(response.body).to eq('{}')
expect(json_response).to eq({})
end
end
end
......
......@@ -17,7 +17,7 @@ FactoryBot.define do
trait :with_evidence do
after(:create) do |release, _|
CreateEvidenceWorker.new.perform(release.id)
create(:evidence, release: release)
end
end
end
......
......@@ -151,36 +151,34 @@ RSpec.describe Release do
end
describe '#evidence_sha' do
let!(:release) { create(:release, :with_evidence) }
subject { release.evidence_sha }
context 'when a release was created before evidence collection existed' do
it 'is nil' do
allow(release).to receive(:evidence).and_return(nil)
let!(:release) { create(:release) }
expect(release.evidence_sha).to be_nil
end
it { is_expected.to be_nil }
end
context 'when a release was created with evidence collection' do
it 'returns the summary sha' do
expect(release.evidence_sha).to eq(release.evidence.summary_sha)
end
let!(:release) { create(:release, :with_evidence) }
it { is_expected.to eq(release.evidence.summary_sha) }
end
end
describe '#evidence_summary' do
let!(:release) { create(:release, :with_evidence) }
subject { release.evidence_summary }
context 'when a release was created before evidence collection existed' do
it 'returns an empty hash' do
allow(release).to receive(:evidence).and_return(nil)
let!(:release) { create(:release) }
expect(release.evidence_summary).to eq({})
end
it { is_expected.to eq({}) }
end
context 'when a release was created with evidence collection' do
it 'returns the summary' do
expect(release.evidence_summary).to eq(release.evidence.summary)
end
let!(:release) { create(:release, :with_evidence) }
it { is_expected.to eq(release.evidence.summary) }
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