From d24c2859c452f70be444108db98cd686ff9a9fa3 Mon Sep 17 00:00:00 2001 From: taitus Date: Mon, 18 Dec 2023 22:25:40 +0100 Subject: [PATCH] Unify paginated comments specs --- .../comments/budget_investments_spec.rb | 18 --------- spec/system/comments/debates_spec.rb | 18 --------- .../comments/legislation_annotations_spec.rb | 18 --------- .../comments/legislation_questions_spec.rb | 18 --------- spec/system/comments/polls_spec.rb | 18 --------- spec/system/comments/proposals_spec.rb | 18 --------- spec/system/comments/topics_spec.rb | 40 ------------------- spec/system/comments_spec.rb | 22 ++++++++++ 8 files changed, 22 insertions(+), 148 deletions(-) diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb index 64c8eff86..06a735d6a 100644 --- a/spec/system/comments/budget_investments_spec.rb +++ b/spec/system/comments/budget_investments_spec.rb @@ -6,24 +6,6 @@ describe "Commenting Budget::Investments" do it_behaves_like "flaggable", :budget_investment_comment - scenario "Paginated comments" do - per_page = 10 - (per_page + 2).times { create(:comment, commentable: investment) } - - visit budget_investment_path(investment.budget, investment) - - expect(page).to have_css(".comment", count: per_page) - within("ul.pagination") do - expect(page).to have_content("1") - expect(page).to have_content("2") - expect(page).not_to have_content("3") - click_link "Next", exact: false - end - - expect(page).to have_css(".comment", count: 2) - expect(page).to have_current_path(/#comments/, url: true) - end - scenario "Create" do login_as(user) visit budget_investment_path(investment.budget, investment) diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index cd0ad42a2..6193dedf5 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -25,24 +25,6 @@ describe "Commenting debates" do end end - scenario "Paginated comments" do - per_page = 10 - (per_page + 2).times { create(:comment, commentable: debate) } - - visit debate_path(debate) - - expect(page).to have_css(".comment", count: per_page) - within("ul.pagination") do - expect(page).to have_content("1") - expect(page).to have_content("2") - expect(page).not_to have_content("3") - click_link "Next", exact: false - end - - expect(page).to have_css(".comment", count: 2) - expect(page).to have_current_path(/#comments/, url: true) - end - scenario "Create" do login_as(user) visit debate_path(debate) diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index 9d294ccea..d128e085b 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -6,24 +6,6 @@ describe "Commenting legislation questions" do it_behaves_like "flaggable", :legislation_annotation_comment - scenario "Paginated comments" do - per_page = 10 - (per_page + 2).times { create(:comment, commentable: annotation) } - - visit polymorphic_path(annotation) - - expect(page).to have_css(".comment", count: per_page) - within("ul.pagination") do - expect(page).to have_content("1") - expect(page).to have_content("2") - expect(page).not_to have_content("3") - click_link "Next", exact: false - end - - expect(page).to have_css(".comment", count: 3) - expect(page).to have_current_path(/#comments/, url: true) - end - scenario "Create" do login_as(user) visit polymorphic_path(annotation) diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index 715aef261..2c225b283 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -10,24 +10,6 @@ describe "Commenting legislation questions" do it_behaves_like "flaggable", :legislation_question_comment end - scenario "Paginated comments" do - per_page = 10 - (per_page + 2).times { create(:comment, commentable: question) } - - visit legislation_process_question_path(question.process, question) - - expect(page).to have_css(".comment", count: per_page) - within("ul.pagination") do - expect(page).to have_content("1") - expect(page).to have_content("2") - expect(page).not_to have_content("3") - click_link "Next", exact: false - end - - expect(page).to have_css(".comment", count: 2) - expect(page).to have_current_path(/#comments/, url: true) - end - scenario "Create" do login_as(user) visit legislation_process_question_path(question.process, question) diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb index dccf205d8..380ea0564 100644 --- a/spec/system/comments/polls_spec.rb +++ b/spec/system/comments/polls_spec.rb @@ -4,24 +4,6 @@ describe "Commenting polls" do let(:user) { create(:user) } let(:poll) { create(:poll, author: create(:user)) } - scenario "Paginated comments" do - per_page = 10 - (per_page + 2).times { create(:comment, commentable: poll) } - - visit poll_path(poll) - - expect(page).to have_css(".comment", count: per_page) - within("ul.pagination") do - expect(page).to have_content("1") - expect(page).to have_content("2") - expect(page).not_to have_content("3") - click_link "Next", exact: false - end - - expect(page).to have_css(".comment", count: 2) - expect(page).to have_current_path(/#comments/, url: true) - end - scenario "Create" do login_as(user) visit poll_path(poll) diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb index 760e3b2a9..702d295dc 100644 --- a/spec/system/comments/proposals_spec.rb +++ b/spec/system/comments/proposals_spec.rb @@ -6,24 +6,6 @@ describe "Commenting proposals" do it_behaves_like "flaggable", :proposal_comment - scenario "Paginated comments" do - per_page = 10 - (per_page + 2).times { create(:comment, commentable: proposal) } - - visit proposal_path(proposal) - - expect(page).to have_css(".comment", count: per_page) - within("ul.pagination") do - expect(page).to have_content("1") - expect(page).to have_content("2") - expect(page).not_to have_content("3") - click_link "Next", exact: false - end - - expect(page).to have_css(".comment", count: 2) - expect(page).to have_current_path(/#comments/, url: true) - end - scenario "Create" do login_as(user) visit proposal_path(proposal) diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb index be8259d02..1d4ba2412 100644 --- a/spec/system/comments/topics_spec.rb +++ b/spec/system/comments/topics_spec.rb @@ -6,26 +6,6 @@ describe "Commenting topics from proposals" do it_behaves_like "flaggable", :topic_with_community_comment - scenario "Paginated comments" do - community = proposal.community - topic = create(:topic, community: community) - per_page = 10 - (per_page + 2).times { create(:comment, commentable: topic) } - - visit community_topic_path(community, topic) - - expect(page).to have_css(".comment", count: per_page) - within("ul.pagination") do - expect(page).to have_content("1") - expect(page).to have_content("2") - expect(page).not_to have_content("3") - click_link "Next", exact: false - end - - expect(page).to have_css(".comment", count: 2) - expect(page).to have_current_path(/#comments/, url: true) - end - scenario "Create" do community = proposal.community topic = create(:topic, community: community) @@ -373,26 +353,6 @@ describe "Commenting topics from budget investments" do let(:user) { create(:user) } let(:investment) { create(:budget_investment) } - scenario "Paginated comments" do - community = investment.community - topic = create(:topic, community: community) - per_page = 10 - (per_page + 2).times { create(:comment, commentable: topic) } - - visit community_topic_path(community, topic) - - expect(page).to have_css(".comment", count: per_page) - within("ul.pagination") do - expect(page).to have_content("1") - expect(page).to have_content("2") - expect(page).not_to have_content("3") - click_link "Next", exact: false - end - - expect(page).to have_css(".comment", count: 2) - expect(page).to have_current_path(/#comments/, url: true) - end - scenario "Create" do community = investment.community topic = create(:topic, community: community) diff --git a/spec/system/comments_spec.rb b/spec/system/comments_spec.rb index 31e000214..6097d4a81 100644 --- a/spec/system/comments_spec.rb +++ b/spec/system/comments_spec.rb @@ -258,6 +258,28 @@ describe "Comments" do end end + scenario "Paginated comments" do + per_page = 10 + (per_page + 2).times { create(:comment, commentable: resource) } + + visit polymorphic_path(resource) + + expect(page).to have_css(".comment", count: per_page) + within("ul.pagination") do + expect(page).to have_content("1") + expect(page).to have_content("2") + expect(page).not_to have_content("3") + click_link "Next", exact: false + end + + if factory == :legislation_annotation + expect(page).to have_css(".comment", count: 3) + else + expect(page).to have_css(".comment", count: 2) + end + expect(page).to have_current_path(/#comments/, url: true) + end + scenario "Errors on create" do login_as(user) visit polymorphic_path(resource)