From 98aea85eaa6a8cdcb9f59abaec24511548bd8093 Mon Sep 17 00:00:00 2001 From: taitus Date: Mon, 18 Dec 2023 21:13:56 +0100 Subject: [PATCH] Unify comment order specs --- .../comments/budget_investments_spec.rb | 28 --------- spec/system/comments/debates_spec.rb | 28 --------- .../comments/legislation_annotations_spec.rb | 28 --------- .../comments/legislation_questions_spec.rb | 28 --------- spec/system/comments/polls_spec.rb | 28 --------- spec/system/comments/proposals_spec.rb | 28 --------- spec/system/comments/topics_spec.rb | 60 ------------------- spec/system/comments_spec.rb | 28 +++++++++ 8 files changed, 28 insertions(+), 228 deletions(-) diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb index aefa7c36e..e3acb15e8 100644 --- a/spec/system/comments/budget_investments_spec.rb +++ b/spec/system/comments/budget_investments_spec.rb @@ -6,34 +6,6 @@ describe "Commenting Budget::Investments" do it_behaves_like "flaggable", :budget_investment_comment - scenario "Comment order" do - c1 = create(:comment, :with_confidence_score, commentable: investment, cached_votes_up: 100, - cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: investment, cached_votes_up: 10, - cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: investment, cached_votes_up: 1, - cached_votes_total: 2, created_at: Time.current) - - visit budget_investment_path(investment.budget, investment, order: :most_voted) - - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - - click_link "Newest first" - - expect(page).to have_link "Newest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c3.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c1.body) - - click_link "Oldest first" - - expect(page).to have_link "Oldest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - end - scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: investment, created_at: Time.current - 10) new_root = create(:comment, commentable: investment, created_at: Time.current) diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments/debates_spec.rb index 0caf6a848..20ed63932 100644 --- a/spec/system/comments/debates_spec.rb +++ b/spec/system/comments/debates_spec.rb @@ -25,34 +25,6 @@ describe "Commenting debates" do end end - scenario "Comment order" do - c1 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 100, - cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 10, - cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 1, - cached_votes_total: 2, created_at: Time.current) - - visit debate_path(debate, order: :most_voted) - - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - - click_link "Newest first" - - expect(page).to have_link "Newest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c3.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c1.body) - - click_link "Oldest first" - - expect(page).to have_link "Oldest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - end - scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: debate, created_at: Time.current - 10) new_root = create(:comment, commentable: debate, created_at: Time.current) diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb index 3c2c76bc1..d9b8ee291 100644 --- a/spec/system/comments/legislation_annotations_spec.rb +++ b/spec/system/comments/legislation_annotations_spec.rb @@ -6,34 +6,6 @@ describe "Commenting legislation questions" do it_behaves_like "flaggable", :legislation_annotation_comment - scenario "Comment order" do - c1 = create(:comment, :with_confidence_score, commentable: annotation, cached_votes_up: 100, - cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: annotation, cached_votes_up: 10, - cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: annotation, cached_votes_up: 1, - cached_votes_total: 2, created_at: Time.current) - - visit polymorphic_path(annotation, order: :most_voted) - - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - - click_link "Newest first" - - expect(page).to have_link "Newest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c3.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c1.body) - - click_link "Oldest first" - - expect(page).to have_link "Oldest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - end - scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: annotation, created_at: Time.current - 10) new_root = create(:comment, commentable: annotation, created_at: Time.current) diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb index 9db19ee41..0cf4e2092 100644 --- a/spec/system/comments/legislation_questions_spec.rb +++ b/spec/system/comments/legislation_questions_spec.rb @@ -10,34 +10,6 @@ describe "Commenting legislation questions" do it_behaves_like "flaggable", :legislation_question_comment end - scenario "Comment order" do - c1 = create(:comment, :with_confidence_score, commentable: question, cached_votes_up: 100, - cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: question, cached_votes_up: 10, - cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: question, cached_votes_up: 1, - cached_votes_total: 2, created_at: Time.current) - - visit legislation_process_question_path(question.process, question, order: :most_voted) - - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - - click_link "Newest first" - - expect(page).to have_link "Newest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c3.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c1.body) - - click_link "Oldest first" - - expect(page).to have_link "Oldest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - end - scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: question, created_at: Time.current - 10) new_root = create(:comment, commentable: question, created_at: Time.current) diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb index 17b38d00a..eba39ac94 100644 --- a/spec/system/comments/polls_spec.rb +++ b/spec/system/comments/polls_spec.rb @@ -4,34 +4,6 @@ describe "Commenting polls" do let(:user) { create(:user) } let(:poll) { create(:poll, author: create(:user)) } - scenario "Comment order" do - c1 = create(:comment, :with_confidence_score, commentable: poll, cached_votes_up: 100, - cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: poll, cached_votes_up: 10, - cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: poll, cached_votes_up: 1, - cached_votes_total: 2, created_at: Time.current) - - visit poll_path(poll, order: :most_voted) - - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - - click_link "Newest first" - - expect(page).to have_link "Newest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c3.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c1.body) - - click_link "Oldest first" - - expect(page).to have_link "Oldest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - end - scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: poll, created_at: Time.current - 10) new_root = create(:comment, commentable: poll, created_at: Time.current) diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb index 070090742..adf1e6577 100644 --- a/spec/system/comments/proposals_spec.rb +++ b/spec/system/comments/proposals_spec.rb @@ -6,34 +6,6 @@ describe "Commenting proposals" do it_behaves_like "flaggable", :proposal_comment - scenario "Comment order" do - c1 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 100, - cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 10, - cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: proposal, cached_votes_up: 1, - cached_votes_total: 2, created_at: Time.current) - - visit proposal_path(proposal, order: :most_voted) - - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - - click_link "Newest first" - - expect(page).to have_link "Newest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c3.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c1.body) - - click_link "Oldest first" - - expect(page).to have_link "Oldest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - end - scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do old_root = create(:comment, commentable: proposal, created_at: Time.current - 10) new_root = create(:comment, commentable: proposal, created_at: Time.current) diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb index ccdd3e7e9..0da477807 100644 --- a/spec/system/comments/topics_spec.rb +++ b/spec/system/comments/topics_spec.rb @@ -6,36 +6,6 @@ describe "Commenting topics from proposals" do it_behaves_like "flaggable", :topic_with_community_comment - scenario "Comment order" do - community = proposal.community - topic = create(:topic, community: community) - c1 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 100, - cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 10, - cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 1, - cached_votes_total: 2, created_at: Time.current) - - visit community_topic_path(community, topic, order: :most_voted) - - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - - click_link "Newest first" - - expect(page).to have_link "Newest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c3.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c1.body) - - click_link "Oldest first" - - expect(page).to have_link "Oldest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - end - scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do community = proposal.community topic = create(:topic, community: community) @@ -459,36 +429,6 @@ describe "Commenting topics from budget investments" do let(:user) { create(:user) } let(:investment) { create(:budget_investment) } - scenario "Comment order" do - community = investment.community - topic = create(:topic, community: community) - c1 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 100, - cached_votes_total: 120, created_at: Time.current - 2) - c2 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 10, - cached_votes_total: 12, created_at: Time.current - 1) - c3 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 1, - cached_votes_total: 2, created_at: Time.current) - - visit community_topic_path(community, topic, order: :most_voted) - - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - - click_link "Newest first" - - expect(page).to have_link "Newest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c3.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c1.body) - - click_link "Oldest first" - - expect(page).to have_link "Oldest first", class: "is-active" - expect(page).to have_current_path(/#comments/, url: true) - expect(c1.body).to appear_before(c2.body) - expect(c2.body).to appear_before(c3.body) - end - scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do community = investment.community topic = create(:topic, community: community) diff --git a/spec/system/comments_spec.rb b/spec/system/comments_spec.rb index a2b25cd20..79d0775e0 100644 --- a/spec/system/comments_spec.rb +++ b/spec/system/comments_spec.rb @@ -177,6 +177,34 @@ describe "Comments" do end end + scenario "Comment order" do + c1 = create(:comment, :with_confidence_score, commentable: resource, cached_votes_up: 100, + cached_votes_total: 120, created_at: Time.current - 2) + c2 = create(:comment, :with_confidence_score, commentable: resource, cached_votes_up: 10, + cached_votes_total: 12, created_at: Time.current - 1) + c3 = create(:comment, :with_confidence_score, commentable: resource, cached_votes_up: 1, + cached_votes_total: 2, created_at: Time.current) + + visit polymorphic_path(resource, order: :most_voted) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) + + click_link "Newest first" + + expect(page).to have_link "Newest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) + expect(c3.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c1.body) + + click_link "Oldest first" + + expect(page).to have_link "Oldest first", class: "is-active" + expect(page).to have_current_path(/#comments/, url: true) + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) + end + scenario "Errors on create" do login_as(user) visit polymorphic_path(resource)