Commit b5057a4a authored by Robert Speicher's avatar Robert Speicher

Merge branch 'remove-rubocop-ignore' into 'master'

Remove rubocop ignore

See merge request gitlab-org/gitlab!24660
parents 1633a252 176be8c0
......@@ -11,24 +11,22 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle
respond_to :json
# rubocop: disable CodeReuse/ActiveRecord
def index
# TODO: Move to finder or list service
@vulnerability_feedback = @project.vulnerability_feedback.with_associations
if params[:category].present?
@vulnerability_feedback = @vulnerability_feedback
.where(category: Vulnerabilities::Feedback.categories[params[:category]])
.with_category(params[:category])
end
if params[:feedback_type].present?
@vulnerability_feedback = @vulnerability_feedback
.where(feedback_type: Vulnerabilities::Feedback.feedback_types[params[:feedback_type]])
.with_feedback_type(params[:feedback_type])
end
render json: serializer.represent(@vulnerability_feedback)
end
# rubocop: enable CodeReuse/ActiveRecord
def create
service = VulnerabilityFeedback::CreateService.new(project, current_user, vulnerability_feedback_params)
......
......@@ -54,6 +54,14 @@ module Vulnerabilities
end
end
def self.with_category(category)
where(category: category)
end
def self.with_feedback_type(feedback_type)
where(feedback_type: feedback_type)
end
# A hard delete of the comment_author will cause the comment_author to be nil, but the comment
# will still exist.
def has_comment?
......
......@@ -41,6 +41,36 @@ describe Vulnerabilities::Feedback do
end
end
describe '.with_category' do
it 'filters by category' do
described_class.categories.each do |category, _|
create(:vulnerability_feedback, category: category)
end
expect(described_class.count).to eq described_class.categories.length
expected, _ = described_class.categories.first
feedback = described_class.with_category(expected)
expect(feedback.length).to eq 1
expect(feedback.first.category).to eq expected
end
end
describe '.with_feedback_type' do
it 'filters by feedback_type' do
create(:vulnerability_feedback, :dismissal)
create(:vulnerability_feedback, :issue)
create(:vulnerability_feedback, :merge_request)
feedback = described_class.with_feedback_type('issue')
expect(feedback.length).to eq 1
expect(feedback.first.feedback_type).to eq 'issue'
end
end
describe '#has_comment?' do
let(:feedback) { build(:vulnerability_feedback, comment: comment, comment_author: comment_author) }
let(:comment) { 'a comment' }
......
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