Fix adding blank comments to existing annotations

We were using the `present?` method, which will always return true for a
comment object.
This commit is contained in:
Javi Martín
2019-10-23 04:26:06 +02:00
parent 7a9fefb933
commit 35bbd87093
2 changed files with 13 additions and 2 deletions

View File

@@ -39,8 +39,8 @@ class Legislation::AnnotationsController < Legislation::BaseController
@annotation = existing_annotation @annotation = existing_annotation
if @annotation.present? if @annotation.present?
comment = @annotation.comments.create(body: annotation_params[:text], user: current_user) comment = @annotation.comments.build(body: annotation_params[:text], user: current_user)
if comment.present? if comment.save
render json: @annotation.to_json render json: @annotation.to_json
else else
render json: comment.errors.full_messages, status: :unprocessable_entity render json: comment.errors.full_messages, status: :unprocessable_entity

View File

@@ -226,6 +226,17 @@ describe "Legislation Draft Versions" do
click_button "Publish comment" click_button "Publish comment"
expect(page).to have_content "My interesting comment" expect(page).to have_content "My interesting comment"
end end
scenario "Publish new comment with errors for an existing annotation" do
create(:legislation_annotation, draft_version: draft_version)
visit legislation_process_draft_version_path(draft_version.process, draft_version)
find(:css, ".annotator-hl").double_click
find(:css, ".annotator-adder button").click
click_button "Publish Comment"
expect(page).to have_content "Comment can't be blank"
end
end end
context "Merged annotations", :js do context "Merged annotations", :js do