]> git.openstreetmap.org Git - rails.git/commitdiff
Throw an exception if adding a note comment fails
authorTom Hughes <tom@compton.nu>
Mon, 13 Mar 2017 14:49:16 +0000 (14:49 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 13 Mar 2017 14:49:16 +0000 (14:49 +0000)
app/controllers/notes_controller.rb
test/controllers/notes_controller_test.rb

index fde27e8b29e05dd1a512a5e15989bb1c0dcb0127..13e930ca53abc997f3178a679c691ecbb6dc0d88 100644 (file)
@@ -345,7 +345,7 @@ class NotesController < ApplicationController
       attributes[:author_ip] = request.remote_ip
     end
 
       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?
 
     note.comments.map(&:author).uniq.each do |user|
       if notify && user && user != @user && user.visible?
index a16ff34772e8fdfc2be374ef5f2bb255c1339af4..3ee283f4a7e7a656b7710963594dac05c46aca03 100644 (file)
@@ -215,6 +215,13 @@ class NotesControllerTest < ActionController::TestCase
       end
     end
     assert_response :bad_request
       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
   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
       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
   end
 
   def test_close_success