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