Skip to content

Commit

Permalink
Merge pull request consuldemocracy#103 from democrateam/hide_comments
Browse files Browse the repository at this point in the history
Hide comments when allegations phase is closed
  • Loading branch information
microweb10 committed Jul 22, 2022
2 parents daac8dc + 6203f33 commit 313ac7a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/legislation/annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ def title
def weight
comments_count + comments.sum(:cached_votes_total)
end

def comments_closed?
!draft_version.process.allegations_phase.open?
end
end
41 changes: 41 additions & 0 deletions spec/system/legislation/draft_versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,47 @@
expect(page).to have_content "Comment can't be blank"
end

scenario "Comments are disabled when allegations phase is closed" do
travel_to "01/01/2022".to_date

process = create(:legislation_process, allegations_start_date: "01/01/2022",
allegations_end_date: "31/01/2022")

draft = create(:legislation_draft_version, process: process)

note = create(:legislation_annotation,
draft_version: draft_version, text: "One annotation", quote: "audiam",
ranges: [{ "start" => "/p[3]", "startOffset" => 6, "end" => "/p[3]", "endOffset" => 11 }])

visit legislation_process_draft_version_annotation_path(draft.process, draft, note)

within "#comments" do
expect(page).to have_content "Comments (1)"
fill_in "Leave your comment", with: "My comment on annotation!"
click_button "Publish comment"
end

visit legislation_process_draft_version_annotation_path(draft.process, draft, note)

within "#comments" do
expect(page).to have_content "Comments (2)"
expect(page).to have_content "One annotation"
expect(page).to have_content "My comment on annotation!"
end

travel_to "01/02/2022".to_date

visit legislation_process_draft_version_annotation_path(draft.process, draft, note)

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_content "Publish comment"
end

travel_back
end

scenario "When page is restored from browser cache do not duplicate annotation handlers" do
Setting["org_name"] = "CONSUL"
create(:legislation_annotation, draft_version: draft_version, text: "my annotation")
Expand Down

0 comments on commit 313ac7a

Please sign in to comment.