Commit c45e4d12 authored by Vladimir Shushlin's avatar Vladimir Shushlin

Don't generate evidence summary in the factorybot

Asked on review

Also fixed evidences_controller_spec: some of examples
were contradicting the permissions logic and only worked
because of using let_it_be and caching permissions from
previous_examples
parent 8da43dea
...@@ -31,8 +31,8 @@ describe Projects::Releases::EvidencesController do ...@@ -31,8 +31,8 @@ describe Projects::Releases::EvidencesController do
end end
describe 'GET #show' do describe 'GET #show' do
let_it_be(:tag_name) { "v1.1.0-evidence" } let(:tag_name) { "v1.1.0-evidence" }
let!(:release) { create(:release, :with_evidence, project: project, tag: tag_name) } let!(:release) { create(:release, project: project, tag: tag_name) }
let(:evidence) { release.evidences.first } let(:evidence) { release.evidences.first }
let(:tag) { CGI.escape(release.tag) } let(:tag) { CGI.escape(release.tag) }
let(:format) { :json } let(:format) { :json }
...@@ -48,6 +48,8 @@ describe Projects::Releases::EvidencesController do ...@@ -48,6 +48,8 @@ describe Projects::Releases::EvidencesController do
end end
before do before do
::Releases::CreateEvidenceService.new(release).execute
sign_in(user) sign_in(user)
end end
...@@ -84,10 +86,9 @@ describe Projects::Releases::EvidencesController do ...@@ -84,10 +86,9 @@ describe Projects::Releases::EvidencesController do
end end
context 'when release is associated to a milestone which includes an issue' do context 'when release is associated to a milestone which includes an issue' do
let_it_be(:project) { create(:project, :repository, :public) } let(:issue) { create(:issue, project: project) }
let_it_be(:issue) { create(:issue, project: project) } let(:milestone) { create(:milestone, project: project, issues: [issue]) }
let_it_be(:milestone) { create(:milestone, project: project, issues: [issue]) } let(:release) { create(:release, project: project, tag: tag_name, milestones: [milestone]) }
let_it_be(:release) { create(:release, :with_evidence, project: project, tag: tag_name, milestones: [milestone]) }
shared_examples_for 'does not show the issue in evidence' do shared_examples_for 'does not show the issue in evidence' do
it do it do
...@@ -107,7 +108,9 @@ describe Projects::Releases::EvidencesController do ...@@ -107,7 +108,9 @@ describe Projects::Releases::EvidencesController do
end end
end end
shared_examples_for 'safely expose evidence' do context 'when user is non-project member' do
let(:user) { create(:user) }
it_behaves_like 'does not show the issue in evidence' it_behaves_like 'does not show the issue in evidence'
context 'when the issue is confidential' do context 'when the issue is confidential' do
...@@ -123,28 +126,50 @@ describe Projects::Releases::EvidencesController do ...@@ -123,28 +126,50 @@ describe Projects::Releases::EvidencesController do
end end
context 'when project is private' do context 'when project is private' do
let!(:project) { create(:project, :repository, :private) } let(:project) { create(:project, :repository, :private) }
it_behaves_like 'evidence not found' it_behaves_like 'evidence not found'
end end
context 'when project restricts the visibility of issues to project members only' do context 'when project restricts the visibility of issues to project members only' do
let!(:project) { create(:project, :repository, :issues_private) } let(:project) { create(:project, :repository, :issues_private) }
it_behaves_like 'evidence not found' it_behaves_like 'evidence not found'
end end
end end
context 'when user is non-project member' do context 'when user is auditor', if: Gitlab.ee? do
let(:user) { create(:user) } let(:user) { create(:user, :auditor) }
it_behaves_like 'safely expose evidence' it_behaves_like 'does not show the issue in evidence'
context 'when the issue is confidential' do
let(:issue) { create(:issue, :confidential, project: project) }
it_behaves_like 'does not show the issue in evidence'
end end
context 'when user is auditor', if: Gitlab.ee? do context 'when the user is the author of the confidential issue' do
let(:user) { create(:user, :auditor) } let(:issue) { create(:issue, :confidential, project: project, author: user) }
it_behaves_like 'does not show the issue in evidence'
end
context 'when project is private' do
let(:project) { create(:project, :repository, :private) }
it 'returns evidence ' do
subject
it_behaves_like 'safely expose evidence' expect(json_response).to eq(evidence.summary)
end
end
context 'when project restricts the visibility of issues to project members only' do
let(:project) { create(:project, :repository, :issues_private) }
it_behaves_like 'evidence not found'
end
end end
context 'when external authorization control is enabled' do context 'when external authorization control is enabled' do
......
...@@ -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, _|
::Releases::CreateEvidenceService.new(release).execute create(:evidence, release: release)
end end
end end
......
...@@ -80,7 +80,7 @@ describe 'User views releases', :js do ...@@ -80,7 +80,7 @@ describe 'User views releases', :js do
context 'with a tag containing a slash' do context 'with a tag containing a slash' do
it 'sees the release' do it 'sees the release' do
release = create :release, :with_evidence, project: project, tag: 'debian/2.4.0-1' release = create :release, project: project, tag: 'debian/2.4.0-1'
visit project_releases_path(project) visit project_releases_path(project)
expect(page).to have_content(release.name) expect(page).to have_content(release.name)
......
...@@ -4,11 +4,15 @@ require 'spec_helper' ...@@ -4,11 +4,15 @@ require 'spec_helper'
describe API::Entities::Release do describe API::Entities::Release do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:release) { create(:release, :with_evidence, project: project) } let(:release) { create(:release, project: project) }
let(:evidence) { release.evidences.first } let(:evidence) { release.evidences.first }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:entity) { described_class.new(release, current_user: user).as_json } let(:entity) { described_class.new(release, current_user: user).as_json }
before do
::Releases::CreateEvidenceService.new(release).execute
end
describe 'evidences' do describe 'evidences' do
context 'when the current user can download code' do context 'when the current user can download code' do
let(:entity_evidence) { entity[:evidences].first } let(:entity_evidence) { entity[:evidences].first }
......
...@@ -94,14 +94,6 @@ RSpec.describe Release do ...@@ -94,14 +94,6 @@ RSpec.describe Release do
describe 'evidence' do describe 'evidence' do
let(:release_with_evidence) { create(:release, :with_evidence, project: project) } let(:release_with_evidence) { create(:release, :with_evidence, project: project) }
describe '#create_evidence!' do
context 'when a release is created' do
it 'creates one Evidence object too' do
expect { release_with_evidence }.to change(Releases::Evidence, :count).by(1)
end
end
end
context 'when a release is deleted' do context 'when a release is deleted' do
it 'also deletes the associated evidence' do it 'also deletes the associated evidence' do
release_with_evidence release_with_evidence
......
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