Commit 176be8c0 authored by Daniel Paul Searles's avatar Daniel Paul Searles

Remove rubocop ignore

parent 94afc015
...@@ -11,24 +11,22 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle ...@@ -11,24 +11,22 @@ class Projects::VulnerabilityFeedbackController < Projects::ApplicationControlle
respond_to :json respond_to :json
# rubocop: disable CodeReuse/ActiveRecord
def index def index
# TODO: Move to finder or list service # TODO: Move to finder or list service
@vulnerability_feedback = @project.vulnerability_feedback.with_associations @vulnerability_feedback = @project.vulnerability_feedback.with_associations
if params[:category].present? if params[:category].present?
@vulnerability_feedback = @vulnerability_feedback @vulnerability_feedback = @vulnerability_feedback
.where(category: Vulnerabilities::Feedback.categories[params[:category]]) .with_category(params[:category])
end end
if params[:feedback_type].present? if params[:feedback_type].present?
@vulnerability_feedback = @vulnerability_feedback @vulnerability_feedback = @vulnerability_feedback
.where(feedback_type: Vulnerabilities::Feedback.feedback_types[params[:feedback_type]]) .with_feedback_type(params[:feedback_type])
end end
render json: serializer.represent(@vulnerability_feedback) render json: serializer.represent(@vulnerability_feedback)
end end
# rubocop: enable CodeReuse/ActiveRecord
def create def create
service = VulnerabilityFeedback::CreateService.new(project, current_user, vulnerability_feedback_params) service = VulnerabilityFeedback::CreateService.new(project, current_user, vulnerability_feedback_params)
......
...@@ -54,6 +54,14 @@ module Vulnerabilities ...@@ -54,6 +54,14 @@ module Vulnerabilities
end end
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 # A hard delete of the comment_author will cause the comment_author to be nil, but the comment
# will still exist. # will still exist.
def has_comment? def has_comment?
......
...@@ -41,6 +41,36 @@ describe Vulnerabilities::Feedback do ...@@ -41,6 +41,36 @@ describe Vulnerabilities::Feedback do
end end
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 describe '#has_comment?' do
let(:feedback) { build(:vulnerability_feedback, comment: comment, comment_author: comment_author) } let(:feedback) { build(:vulnerability_feedback, comment: comment, comment_author: comment_author) }
let(:comment) { 'a comment' } 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