Commit 9f6157d6 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'pl-rubocop-inline-association-ee' into 'master'

Fix remaining EE offenses for FactoryBot/InlineAssociation [RUN ALL RSPEC]

See merge request gitlab-org/gitlab!56241
parents 8307ecca 7d54eebc
......@@ -44,15 +44,10 @@ Graphql/Descriptions:
# WIP See https://gitlab.com/gitlab-org/gitlab/-/issues/267606
FactoryBot/InlineAssociation:
Exclude:
- 'ee/spec/factories/merge_request_blocks.rb'
- 'ee/spec/factories/vulnerabilities/feedback.rb'
- 'spec/factories/atlassian_identities.rb'
- 'spec/factories/events.rb'
- 'spec/factories/git_wiki_commit_details.rb'
- 'spec/factories/gitaly/commit.rb'
- 'spec/factories/go_module_commits.rb'
- 'spec/factories/go_module_versions.rb'
- 'spec/factories/go_modules.rb'
- 'spec/factories/group_group_links.rb'
- 'spec/factories/import_export_uploads.rb'
......
......@@ -2,7 +2,7 @@
FactoryBot.define do
factory :merge_request_block do
blocking_merge_request { create(:merge_request) }
blocked_merge_request { create(:merge_request) }
blocking_merge_request { association(:merge_request) }
blocked_merge_request { association(:merge_request) }
end
end
......@@ -12,7 +12,7 @@ FactoryBot.define do
author
issue { nil }
merge_request { nil }
pipeline { create(:ci_pipeline, project: project) }
pipeline { association(:ci_pipeline, project: project) }
feedback_type { 'dismissal' }
category { 'sast' }
project_fingerprint { generate(:project_fingerprint) }
......@@ -30,12 +30,12 @@ FactoryBot.define do
trait :issue do
feedback_type { 'issue' }
issue { create(:issue, project: project) }
issue { association(:issue, project: project) }
end
trait :merge_request do
feedback_type { 'merge_request' }
merge_request { create(:merge_request, source_project: project) }
merge_request { association(:merge_request, source_project: project) }
end
trait :sast do
......
......@@ -15,13 +15,11 @@ RSpec.describe Vulnerabilities::FeedbackEntity do
end
describe '#as_json' do
let(:feedback) { build(:vulnerability_feedback, :issue, project: project) }
let(:feedback) { build_stubbed(:vulnerability_feedback, :issue, project: project) }
it { is_expected.to include(:created_at, :project_id, :author, :category, :feedback_type) }
context 'feedback type is issue' do
let(:feedback) { build(:vulnerability_feedback, :issue, project: project) }
context 'when feedback type is issue' do
context 'when issue is present' do
it 'exposes the issue iid' do
is_expected.to include(:issue_iid)
......@@ -45,15 +43,11 @@ RSpec.describe Vulnerabilities::FeedbackEntity do
end
context 'when there is no current user' do
let(:entity) { described_class.represent(feedback, request: request) }
before do
allow(request).to receive(:current_user).and_return(nil)
allow(feedback).to receive(:author).and_return(nil)
end
subject { entity.as_json }
it 'does not include fields related to current user' do
is_expected.not_to include(:issue_url)
is_expected.not_to include(:destroy_vulnerability_feedback_dismissal_path)
......@@ -62,9 +56,9 @@ RSpec.describe Vulnerabilities::FeedbackEntity do
end
context 'when issue is not present' do
let(:feedback) { build(:vulnerability_feedback, feedback_type: :issue, project: project, issue: nil) }
it 'does not expose issue information' do
feedback.issue = nil
is_expected.not_to include(:issue_iid)
is_expected.not_to include(:issue_url)
end
......@@ -81,8 +75,8 @@ RSpec.describe Vulnerabilities::FeedbackEntity do
end
end
context 'feedback type is merge_request' do
let(:feedback) { build(:vulnerability_feedback, :merge_request, project: project) }
context 'when feedback type is merge_request' do
let(:feedback) { build_stubbed(:vulnerability_feedback, :merge_request, project: project) }
context 'when merge request is present' do
it 'exposes the merge request iid' do
......@@ -107,9 +101,9 @@ RSpec.describe Vulnerabilities::FeedbackEntity do
end
context 'when merge request is not present' do
let(:feedback) { build(:vulnerability_feedback, :merge_request, project: project, merge_request: nil) }
it 'does not expose merge request information' do
feedback.merge_request = nil
is_expected.not_to include(:merge_request_iid)
is_expected.not_to include(:merge_request_path)
end
......@@ -126,8 +120,8 @@ RSpec.describe Vulnerabilities::FeedbackEntity do
end
end
context 'feedback type is dismissal' do
let(:feedback) { create(:vulnerability_feedback, :dismissal, project: project) }
context 'when feedback type is dismissal' do
let(:feedback) { build_stubbed(:vulnerability_feedback, :dismissal, project: project) }
context 'when not allowed to destroy vulnerability feedback' do
before do
......@@ -152,13 +146,13 @@ RSpec.describe Vulnerabilities::FeedbackEntity do
end
context 'when comment is not present' do
let(:feedback) { build(:vulnerability_feedback, :dismissal, project: project) }
let(:feedback) { build_stubbed(:vulnerability_feedback, :dismissal, project: project) }
it { is_expected.not_to include(:comment_details) }
end
context 'when comment is present' do
let(:feedback) { build(:vulnerability_feedback, :comment, project: project) }
let(:feedback) { build_stubbed(:vulnerability_feedback, :comment, project: project) }
it 'exposes comment information' do
expect(subject).to include(:comment_details)
......@@ -169,7 +163,7 @@ RSpec.describe Vulnerabilities::FeedbackEntity do
end
context 'when finding_uuid is not present' do
let(:feedback) { build(:vulnerability_feedback, :issue, project: project) }
let(:feedback) { build_stubbed(:vulnerability_feedback, :issue, project: project) }
it 'has a nil finding_uuid' do
expect(subject[:finding_uuid]).to be_nil
......@@ -177,8 +171,8 @@ RSpec.describe Vulnerabilities::FeedbackEntity do
end
context 'when finding_uuid is present' do
let_it_be(:finding) { create(:vulnerabilities_finding) }
let(:feedback) { create(:vulnerability_feedback, finding_uuid: finding.uuid, project: project) }
let(:finding) { build_stubbed(:vulnerabilities_finding) }
let(:feedback) { build_stubbed(:vulnerability_feedback, finding_uuid: finding.uuid, project: project) }
it 'exposes finding_uuid' do
expect(subject[:finding_uuid]).to eq(finding.uuid)
......
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