Throw an exception if adding a note comment fails

This commit is contained in:
Tom Hughes 2017-03-13 14:49:16 +00:00
parent cd922a99f8
commit 7c9229fbfc
2 changed files with 13 additions and 1 deletions

View file

@ -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?

View file

@ -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