We were tracking some events with Ahoy, but in an inconsistent way. For example, we were tracking when a debate was created, but (probably accidentally) we were only tracking proposals when they were created from the management section. For budget investments and their supports, we weren't using Ahoy events but checking their database tables instead. And we were only using ahoy events for the charts; for the other stats, we were using the real data. While we could actually fix these issues and start tracking events correctly, existing production data would remain broken because we didn't track a certain event when it happened. And, besides, why should we bother, for instance, to track when a debate is created, when we can instead access that information in the debates table? There are probably some features related to tracking an event and their visits, but we weren't using them, and we were storing more user data than we needed to. So we're removing the track events, allowing us to simplify the code and make it more consistent. We aren't removing the `ahoy_events` table in case existing Consul Democracy installations use it, but we'll remove it after releasing version 2.2.0 and adding a warning in the release notes. This change fixes the proposal created chart, since we were only tracking proposals created in the management section, and opens the possibility to add more charts in the future using data we didn't track with Ahoy. Also note the "Level 2 user Graph" test wasn't testing the graph, so we're changing it in order to test it. We're also moving it next to the other graphs test and, since we were tracking the event when we were confirming the phone, we're renaming to "Level 3 users". Finally, note that, since we were tracking events when something was created, we're including the `with_hidden` scope. This is also consistent with the other stats shown in the admin section as well as the public stats.
165 lines
6.2 KiB
Ruby
165 lines
6.2 KiB
Ruby
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,
|
|
allegations_end_date: Date.current + 2.days)
|
|
end
|
|
let(:draft_version) do
|
|
create(:legislation_draft_version, :published, process: legal_process, title: "Version 1")
|
|
end
|
|
let(:final_version) do
|
|
create(:legislation_draft_version, :published, :final_version,
|
|
process: legal_process, title: "Final version")
|
|
end
|
|
let(:user) { create(:user, :level_two) }
|
|
|
|
it "does not create an annotation if the draft version is a final version" do
|
|
sign_in user
|
|
|
|
post :create, params: {
|
|
process_id: legal_process.id,
|
|
draft_version_id: final_version.id,
|
|
legislation_annotation: {
|
|
"quote" => "ipsum",
|
|
"ranges" => [{
|
|
"start" => "/p[1]",
|
|
"startOffset" => 6,
|
|
"end" => "/p[1]",
|
|
"endOffset" => 11
|
|
}],
|
|
"text" => "una anotacion"
|
|
}
|
|
}
|
|
|
|
expect(response).to have_http_status(:not_found)
|
|
end
|
|
|
|
it "creates an annotation if the process allegations phase is open" do
|
|
sign_in user
|
|
|
|
expect do
|
|
post :create, xhr: true,
|
|
params: {
|
|
process_id: legal_process.id,
|
|
draft_version_id: draft_version.id,
|
|
legislation_annotation: {
|
|
"quote" => "ipsum",
|
|
"ranges" => [{
|
|
"start" => "/p[1]",
|
|
"startOffset" => 6,
|
|
"end" => "/p[1]",
|
|
"endOffset" => 11
|
|
}],
|
|
"text" => "una anotacion"
|
|
}
|
|
}
|
|
end.to change { draft_version.annotations.count }.by(1)
|
|
end
|
|
|
|
it "does not create an annotation if the process allegations phase is not open" do
|
|
sign_in user
|
|
legal_process.update!(allegations_end_date: Date.current - 1.day)
|
|
|
|
expect do
|
|
post :create, xhr: true,
|
|
params: {
|
|
process_id: legal_process.id,
|
|
draft_version_id: draft_version.id,
|
|
legislation_annotation: {
|
|
"quote" => "ipsum",
|
|
"ranges" => [{
|
|
"start" => "/p[1]",
|
|
"startOffset" => 6,
|
|
"end" => "/p[1]",
|
|
"endOffset" => 11
|
|
}],
|
|
"text" => "una anotacion"
|
|
}
|
|
}
|
|
end.not_to change { draft_version.annotations.count }
|
|
end
|
|
|
|
it "creates an annotation by parsing parameters in JSON" do
|
|
sign_in user
|
|
|
|
expect do
|
|
post :create, xhr: true,
|
|
params: {
|
|
process_id: legal_process.id,
|
|
draft_version_id: draft_version.id,
|
|
legislation_annotation: {
|
|
"quote" => "ipsum",
|
|
"ranges" => [{
|
|
"start" => "/p[1]",
|
|
"startOffset" => 6,
|
|
"end" => "/p[1]",
|
|
"endOffset" => 11
|
|
}].to_json,
|
|
"text" => "una anotacion"
|
|
}
|
|
}
|
|
end.to change { draft_version.annotations.count }.by(1)
|
|
end
|
|
|
|
it "creates a new comment on an existing annotation when range is the same" do
|
|
annotation = create(:legislation_annotation, draft_version: draft_version,
|
|
text: "my annotation",
|
|
ranges: [{
|
|
"start" => "/p[1]",
|
|
"startOffset" => 6,
|
|
"end" => "/p[1]",
|
|
"endOffset" => 11
|
|
}],
|
|
range_start: "/p[1]",
|
|
range_start_offset: 6,
|
|
range_end: "/p[1]",
|
|
range_end_offset: 11)
|
|
sign_in user
|
|
|
|
expect do
|
|
post :create, xhr: true,
|
|
params: {
|
|
process_id: legal_process.id,
|
|
draft_version_id: draft_version.id,
|
|
legislation_annotation: {
|
|
"quote" => "ipsum",
|
|
"ranges" => [{
|
|
"start" => "/p[1]",
|
|
"startOffset" => 6,
|
|
"end" => "/p[1]",
|
|
"endOffset" => 11
|
|
}],
|
|
"text" => "una anotacion"
|
|
}
|
|
}
|
|
end.not_to change { draft_version.annotations.count }
|
|
|
|
expect(annotation.reload.comments_count).to eq(2)
|
|
expect(annotation.comments.last.body).to eq("una anotacion")
|
|
end
|
|
end
|
|
end
|