Load annotations through the draft version

We were ignoring the draft version param when loading an annotation,
which could result in a strange situation where we load an annotation
and a draft version different than the one it belongs to.

Thanks to this change, we can simplify the code a little bit. IMHO the
`comments` and `new_comment` routes should have been added on member
instead of on collection, which would further simplify the code. I'm
leaving the routes untouched just in case changing the URL has side
effects on existing installations.
This commit is contained in:
Javi Martín
2022-08-05 16:11:24 +02:00
parent f8fdb77a8a
commit 711e6c16eb
2 changed files with 25 additions and 6 deletions

View File

@@ -1,6 +1,27 @@
require "rails_helper"
describe Legislation::AnnotationsController do
describe "GET show" do
it "finds the annotation when it belongs to the draft version" do
version = create(:legislation_draft_version)
annotation = create(:legislation_annotation, draft_version: version)
get :show, params: { process_id: version.process, draft_version_id: version, id: annotation }
expect(response).to be_ok
end
it "returns a 404 when the annotation belongs to a different draft version" do
version = create(:legislation_draft_version)
annotation = create(:legislation_annotation, draft_version: version)
other_version = create(:legislation_draft_version, process: version.process)
expect do
get :show, params: { process_id: version.process, draft_version_id: other_version, id: annotation }
end.to raise_error ActiveRecord::RecordNotFound
end
end
describe "POST create" do
let(:legal_process) do
create(:legislation_process, allegations_start_date: Date.current - 3.days,