Hide comments when allegations phase is closed
Co-Authored-By: Julian Nicolas Herrero <microweb10@gmail.com> Co-Authored-By: Javi Martín <javim@elretirao.net>
This commit is contained in:
@@ -55,4 +55,8 @@ class Legislation::Annotation < ApplicationRecord
|
|||||||
def weight
|
def weight
|
||||||
comments_count + comments.sum(:cached_votes_total)
|
comments_count + comments.sum(:cached_votes_total)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def comments_closed?
|
||||||
|
!draft_version.process.allegations_phase.open?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,6 +41,28 @@ describe CommentsController do
|
|||||||
end.not_to change { question.reload.comments_count }
|
end.not_to change { question.reload.comments_count }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not create an annotation comment if the allegations phase is closed" do
|
||||||
|
process = create(:legislation_process,
|
||||||
|
allegations_start_date: 2.days.from_now,
|
||||||
|
allegations_end_date: 1.month.from_now)
|
||||||
|
|
||||||
|
version = create(:legislation_draft_version, process: process)
|
||||||
|
annotation = create(:legislation_annotation, draft_version: version, text: "One annotation")
|
||||||
|
|
||||||
|
sign_in user
|
||||||
|
|
||||||
|
expect do
|
||||||
|
post :create, xhr: true,
|
||||||
|
params: {
|
||||||
|
comment: {
|
||||||
|
commentable_id: annotation.id,
|
||||||
|
commentable_type: "Legislation::Annotation",
|
||||||
|
body: "a comment"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end.not_to change { annotation.reload.comments_count }
|
||||||
|
end
|
||||||
|
|
||||||
it "does not create a comment for unverified users when the commentable requires it" do
|
it "does not create a comment for unverified users when the commentable requires it" do
|
||||||
sign_in unverified_user
|
sign_in unverified_user
|
||||||
|
|
||||||
|
|||||||
@@ -254,6 +254,25 @@ describe "Commenting legislation questions" do
|
|||||||
expect(page).to have_content "Can't be blank"
|
expect(page).to have_content "Can't be blank"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Comments are disabled when the allegations phase is closed" do
|
||||||
|
process = create(:legislation_process,
|
||||||
|
allegations_start_date: 1.month.ago,
|
||||||
|
allegations_end_date: Date.yesterday)
|
||||||
|
|
||||||
|
version = create(:legislation_draft_version, process: process)
|
||||||
|
annotation = create(:legislation_annotation, draft_version: version, text: "One annotation")
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
|
||||||
|
visit legislation_process_draft_version_annotation_path(version.process, version, annotation)
|
||||||
|
|
||||||
|
within "#comments" do
|
||||||
|
expect(page).to have_content "Comments are closed"
|
||||||
|
expect(page).not_to have_content "Leave your comment"
|
||||||
|
expect(page).not_to have_button "Publish comment"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Reply" do
|
scenario "Reply" do
|
||||||
citizen = create(:user, username: "Ana")
|
citizen = create(:user, username: "Ana")
|
||||||
manuela = create(:user, username: "Manuela")
|
manuela = create(:user, username: "Manuela")
|
||||||
|
|||||||
Reference in New Issue
Block a user