Skip to content

Commit 381152f

Browse files
committed
Cover remaining two lines
1 parent 91482a7 commit 381152f

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

app/controllers/complaints_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def create
3030
if @comment.save
3131
redirect_to safety_center_path # report path
3232
else
33-
@errors = @comment.errors.full_messages + @complaint.errors.full_messages
33+
@errors = @comment.errors.full_messages
3434
render :report, status: :bad_request, layout: 'without_sidebar'
3535
end
3636
else

app/models/complaint_comment.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class ComplaintComment < ApplicationRecord
22
belongs_to :complaint
33
belongs_to :user, required: false
4+
5+
validates :content, presence: true
46
end

test/controllers/complaints_controller_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ class ComplaintsControllerTest < ActionDispatch::IntegrationTest
6363
assert_equal 3, assigns(:errors).size
6464
end
6565

66+
test 'should correct validate missing comment' do
67+
try_create_report report_type: 'illegal', reported_url: 'https://example.com', content_type: 'fraud',
68+
email: 'test@example.com', user_wants_updates: true
69+
assert_response(:bad_request)
70+
assert_not_nil assigns(:complaint)
71+
assert_equal 1, assigns(:errors).size
72+
end
73+
6674
private
6775

6876
def try_create_report(**params)

0 commit comments

Comments
 (0)