From: Tom Hughes Date: Mon, 13 Mar 2017 14:49:16 +0000 (+0000) Subject: Throw an exception if adding a note comment fails X-Git-Tag: live~4097 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/7c9229fbfca70f65cc587129b18f1de4d993f9e2 Throw an exception if adding a note comment fails --- diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index fde27e8b2..13e930ca5 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -345,7 +345,7 @@ class NotesController < ApplicationController attributes[:author_ip] = request.remote_ip end - comment = note.comments.create(attributes) + comment = note.comments.create!(attributes) note.comments.map(&:author).uniq.each do |user| if notify && user && user != @user && user.visible? diff --git a/test/controllers/notes_controller_test.rb b/test/controllers/notes_controller_test.rb index a16ff3477..3ee283f4a 100644 --- a/test/controllers/notes_controller_test.rb +++ b/test/controllers/notes_controller_test.rb @@ -215,6 +215,13 @@ class NotesControllerTest < ActionController::TestCase end end assert_response :bad_request + + assert_no_difference "Note.count" do + assert_no_difference "NoteComment.count" do + post :create, :lat => -1.0, :lon => -1.0, :text => "x\u0000y" + end + end + assert_response :bad_request end def test_comment_success @@ -376,6 +383,11 @@ class NotesControllerTest < ActionController::TestCase post :comment, :id => closed_note_with_comment.id, :text => "This is an additional comment" end assert_response :conflict + + assert_no_difference "NoteComment.count" do + post :comment, :id => open_note_with_comment.id, :text => "x\u0000y" + end + assert_response :bad_request end def test_close_success