Unify index comments specs

This commit is contained in:
taitus
2023-12-14 10:28:25 +01:00
parent a5e4fb13b4
commit ab79d1e30e
8 changed files with 47 additions and 127 deletions

View File

@@ -6,24 +6,6 @@ describe "Commenting Budget::Investments" do
it_behaves_like "flaggable", :budget_investment_comment it_behaves_like "flaggable", :budget_investment_comment
scenario "Index" do
not_valuations = 3.times.map { create(:comment, commentable: investment) }
create(:comment, :valuation, commentable: investment, subject: "Not viable")
visit budget_investment_path(investment.budget, investment)
expect(page).to have_css(".comment", count: 3)
expect(page).not_to have_content("Not viable")
within("#comments") do
not_valuations.each do |comment|
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body
end
end
end
scenario "Show" do scenario "Show" do
parent_comment = create(:comment, commentable: investment, body: "Parent") parent_comment = create(:comment, commentable: investment, body: "Parent")
create(:comment, commentable: investment, parent: parent_comment, body: "First subcomment") create(:comment, commentable: investment, parent: parent_comment, body: "First subcomment")

View File

@@ -6,21 +6,6 @@ describe "Commenting debates" do
it_behaves_like "flaggable", :debate_comment it_behaves_like "flaggable", :debate_comment
scenario "Index" do
3.times { create(:comment, commentable: debate) }
comment = Comment.includes(:user).last
visit debate_path(debate)
expect(page).to have_css(".comment", count: 3)
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body
end
end
scenario "Show" do scenario "Show" do
parent_comment = create(:comment, commentable: debate, body: "Parent") parent_comment = create(:comment, commentable: debate, body: "Parent")
create(:comment, commentable: debate, parent: parent_comment, body: "First subcomment") create(:comment, commentable: debate, parent: parent_comment, body: "First subcomment")

View File

@@ -6,21 +6,6 @@ describe "Commenting legislation questions" do
it_behaves_like "flaggable", :legislation_annotation_comment it_behaves_like "flaggable", :legislation_annotation_comment
scenario "Index" do
3.times { create(:comment, commentable: annotation) }
comment = Comment.includes(:user).last
visit polymorphic_path(annotation)
expect(page).to have_css(".comment", count: 4)
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body
end
end
scenario "Show" do scenario "Show" do
href = polymorphic_path(annotation) href = polymorphic_path(annotation)
parent_comment = create(:comment, commentable: annotation, body: "Parent") parent_comment = create(:comment, commentable: annotation, body: "Parent")

View File

@@ -10,21 +10,6 @@ describe "Commenting legislation questions" do
it_behaves_like "flaggable", :legislation_question_comment it_behaves_like "flaggable", :legislation_question_comment
end end
scenario "Index" do
3.times { create(:comment, commentable: question) }
comment = Comment.includes(:user).last
visit legislation_process_question_path(question.process, question)
expect(page).to have_css(".comment", count: 3)
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body
end
end
scenario "Show" do scenario "Show" do
href = legislation_process_question_path(question.process, question) href = legislation_process_question_path(question.process, question)
parent_comment = create(:comment, commentable: question, body: "Parent") parent_comment = create(:comment, commentable: question, body: "Parent")

View File

@@ -4,21 +4,6 @@ describe "Commenting polls" do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:poll) { create(:poll, author: create(:user)) } let(:poll) { create(:poll, author: create(:user)) }
scenario "Index" do
3.times { create(:comment, commentable: poll) }
comment = Comment.includes(:user).last
visit poll_path(poll)
expect(page).to have_css(".comment", count: 3)
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body
end
end
scenario "Show" do scenario "Show" do
parent_comment = create(:comment, commentable: poll, body: "Parent") parent_comment = create(:comment, commentable: poll, body: "Parent")
create(:comment, commentable: poll, parent: parent_comment, body: "First subcomment") create(:comment, commentable: poll, parent: parent_comment, body: "First subcomment")

View File

@@ -6,21 +6,6 @@ describe "Commenting proposals" do
it_behaves_like "flaggable", :proposal_comment it_behaves_like "flaggable", :proposal_comment
scenario "Index" do
3.times { create(:comment, commentable: proposal) }
comment = Comment.includes(:user).last
visit proposal_path(proposal)
expect(page).to have_css(".comment", count: 3)
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body
end
end
scenario "Show" do scenario "Show" do
parent_comment = create(:comment, commentable: proposal, body: "Parent") parent_comment = create(:comment, commentable: proposal, body: "Parent")
create(:comment, commentable: proposal, parent: parent_comment, body: "First subcomment") create(:comment, commentable: proposal, parent: parent_comment, body: "First subcomment")

View File

@@ -6,23 +6,6 @@ describe "Commenting topics from proposals" do
it_behaves_like "flaggable", :topic_with_community_comment it_behaves_like "flaggable", :topic_with_community_comment
scenario "Index" do
community = proposal.community
topic = create(:topic, community: community)
create_list(:comment, 3, commentable: topic)
comment = Comment.includes(:user).last
visit community_topic_path(community, topic)
expect(page).to have_css(".comment", count: 3)
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body
end
end
scenario "Show" do scenario "Show" do
community = proposal.community community = proposal.community
topic = create(:topic, community: community) topic = create(:topic, community: community)
@@ -549,23 +532,6 @@ describe "Commenting topics from budget investments" do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:investment) { create(:budget_investment) } let(:investment) { create(:budget_investment) }
scenario "Index" do
community = investment.community
topic = create(:topic, community: community)
create_list(:comment, 3, commentable: topic)
comment = Comment.includes(:user).last
visit community_topic_path(community, topic)
expect(page).to have_css(".comment", count: 3)
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body
end
end
scenario "Show" do scenario "Show" do
community = investment.community community = investment.community
topic = create(:topic, community: community) topic = create(:topic, community: community)

View File

@@ -36,6 +36,53 @@ describe "Comments" do
end end
end end
describe "Index" do
context "Budget Investments" do
let(:investment) { create(:budget_investment) }
scenario "render comments" do
not_valuations = 3.times.map { create(:comment, commentable: investment) }
create(:comment, :valuation, commentable: investment, subject: "Not viable")
visit budget_investment_path(investment.budget, investment)
expect(page).to have_css(".comment", count: 3)
expect(page).not_to have_content("Not viable")
within("#comments") do
not_valuations.each do |comment|
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body
end
end
end
end
context "Debates, annotations, question, Polls, Proposals and Topics" do
let(:factory) { (factories - [:budget_investment]).sample }
scenario "render comments" do
3.times { create(:comment, commentable: resource) }
comment = Comment.includes(:user).last
visit polymorphic_path(resource)
if factory == :legislation_annotation
expect(page).to have_css(".comment", count: 4)
else
expect(page).to have_css(".comment", count: 3)
end
within first(".comment") do
expect(page).to have_content comment.user.name
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
expect(page).to have_content comment.body
end
end
end
end
describe "Not logged user" do describe "Not logged user" do
scenario "can not see comments forms" do scenario "can not see comments forms" do
create(:comment, commentable: resource) create(:comment, commentable: resource)