Commit e93aabe1 authored by Peter Leitzen's avatar Peter Leitzen

Refactor specs for Vulnerabilities::Feedback to use `build_stubbed`

This commit not only speeds up specs (instead of `create`) but makes
it easier to unset issue/merge_request association.
parent accc6535
......@@ -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