Use shared specs to flag comments

This commit is contained in:
Javi Martín
2020-03-20 19:03:57 +01:00
parent 3c27df592e
commit 014ccd8374
8 changed files with 51 additions and 376 deletions

View File

@@ -4,6 +4,12 @@ FactoryBot.define do
user
sequence(:body) { |n| "Comment body #{n}" }
%i[budget_investment debate legislation_annotation legislation_question proposal topic_with_community].each do |model|
factory :"#{model}_comment" do
association :commentable, factory: model
end
end
trait :hidden do
hidden_at { Time.current }
end

View File

@@ -1,13 +1,22 @@
shared_examples "flaggable" do |factory_name|
let(:user) { create(:user) }
include ActionView::RecordIdentifier
let(:user) { create(:user, :level_two) }
let(:flaggable) { create(factory_name) }
let(:path) { polymorphic_path(flaggable) }
let(:path) do
if flaggable.is_a?(Comment)
polymorphic_path(flaggable.commentable)
else
polymorphic_path(flaggable)
end
end
scenario "Flagging as inappropriate", :js do
login_as(user)
visit path
within ".flag-content" do
within "##{dom_id(flaggable)} .flag-content" do
find(".icon-flag").click
click_link "Flag as inappropriate"
@@ -24,7 +33,7 @@ shared_examples "flaggable" do |factory_name|
login_as(user)
visit path
within ".flag-content" do
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_css ".flag-active"
find(".icon-flag").click
@@ -41,7 +50,7 @@ shared_examples "flaggable" do |factory_name|
login_as(user)
visit path
within ".flag-content" do
within "##{dom_id(flaggable)} .flag-content" do
find(".icon-flag").click
click_link "Flag as inappropriate"
@@ -56,4 +65,24 @@ shared_examples "flaggable" do |factory_name|
expect(Flag.flagged?(user, flaggable)).not_to be
end
scenario "Flagging a comment with a child does not update its children", :js do
skip "Only for comments" unless flaggable.is_a?(Comment)
child_comment = create(:comment, commentable: flaggable.commentable, parent: flaggable)
login_as(user)
visit path
within "##{dom_id(flaggable)} > .comment-body .flag-content" do
find(".icon-flag").click
click_link "Flag as inappropriate"
expect(page).to have_css ".flag-active"
end
within "##{dom_id(child_comment)} .flag-content" do
expect(page).not_to have_css ".flag-active"
end
end
end

View File

@@ -4,6 +4,8 @@ describe "Commenting Budget::Investments" do
let(:user) { create :user }
let(:investment) { create :budget_investment }
it_behaves_like "flaggable", :budget_investment_comment
scenario "Index" do
3.times { create(:comment, commentable: investment) }
create(:comment, :valuation, commentable: investment, subject: "Not viable")
@@ -300,53 +302,6 @@ describe "Commenting Budget::Investments" do
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
end
scenario "Flagging as inappropriate", :js do
comment = create(:comment, commentable: investment)
login_as(user)
visit budget_investment_path(investment.budget, investment)
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
page.find("#flag-comment-#{comment.id}").click
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).to be
end
scenario "Undoing flagging as inappropriate", :js do
comment = create(:comment, commentable: investment)
Flag.flag(user, comment)
login_as(user)
visit budget_investment_path(investment.budget, investment)
within "#comment_#{comment.id}" do
page.find("#unflag-expand-comment-#{comment.id}").click
page.find("#unflag-comment-#{comment.id}").click
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).not_to be
end
scenario "Flagging turbolinks sanity check", :js do
investment = create(:budget_investment, title: "Should we change the world?")
comment = create(:comment, commentable: investment)
login_as(user)
visit budget_investments_path(investment.budget)
click_link "Should we change the world?"
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
expect(page).to have_selector("#flag-comment-#{comment.id}")
end
end
scenario "Erasing a comment's author" do
investment = create(:budget_investment)
comment = create(:comment, commentable: investment, body: "this should be visible")

View File

@@ -4,6 +4,8 @@ describe "Commenting debates" do
let(:user) { create :user }
let(:debate) { create :debate }
it_behaves_like "flaggable", :debate_comment
scenario "Index" do
3.times { create(:comment, commentable: debate) }
@@ -338,80 +340,6 @@ describe "Commenting debates" do
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
end
scenario "Flagging as inappropriate", :js do
comment = create(:comment, commentable: debate)
login_as(user)
visit debate_path(debate)
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
page.find("#flag-comment-#{comment.id}").click
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).to be
end
scenario "Undoing flagging as inappropriate", :js do
comment = create(:comment, commentable: debate)
Flag.flag(user, comment)
login_as(user)
visit debate_path(debate)
within "#comment_#{comment.id}" do
page.find("#unflag-expand-comment-#{comment.id}").click
page.find("#unflag-comment-#{comment.id}").click
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).not_to be
end
scenario "Flagging turbolinks sanity check", :js do
debate = create(:debate, title: "Should we change the world?")
comment = create(:comment, commentable: debate)
login_as(user)
visit debates_path
click_link "Should we change the world?"
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
page.find("#flag-comment-#{comment.id}").click
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
expect(Flag.flagged?(user, comment)).to be
page.find("#unflag-expand-comment-#{comment.id}").click
page.find("#unflag-comment-#{comment.id}").click
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).not_to be
end
scenario "Flagging a comment with a child does not update its children", :js do
debate = create(:debate, title: "Should we change the world?")
parent_comment = create(:comment, commentable: debate, body: "Main comment")
child_comment = create(:comment, body: "First subcomment", commentable: debate, parent: parent_comment)
login_as(user)
visit debate_path(debate)
within "#comment_#{parent_comment.id}" do
page.find("#flag-expand-comment-#{parent_comment.id}").click
page.find("#flag-comment-#{parent_comment.id}").click
expect(page).to have_css("#unflag-expand-comment-#{parent_comment.id}")
expect(page).to have_css("#flag-expand-comment-#{child_comment.id}")
end
end
scenario "Erasing a comment's author" do
debate = create(:debate)
comment = create(:comment, commentable: debate, body: "this should be visible")

View File

@@ -4,6 +4,8 @@ describe "Commenting legislation questions" do
let(:user) { create :user }
let(:legislation_annotation) { create :legislation_annotation, author: user }
it_behaves_like "flaggable", :legislation_annotation_comment
scenario "Index" do
3.times { create(:comment, commentable: legislation_annotation) }
@@ -349,58 +351,6 @@ describe "Commenting legislation questions" do
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
end
scenario "Flagging as inappropriate", :js do
comment = create(:comment, commentable: legislation_annotation)
login_as(user)
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process,
legislation_annotation.draft_version,
legislation_annotation)
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
page.find("#flag-comment-#{comment.id}").click
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).to be
end
scenario "Undoing flagging as inappropriate", :js do
comment = create(:comment, commentable: legislation_annotation)
Flag.flag(user, comment)
login_as(user)
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process,
legislation_annotation.draft_version,
legislation_annotation)
within "#comment_#{comment.id}" do
page.find("#unflag-expand-comment-#{comment.id}").click
page.find("#unflag-comment-#{comment.id}").click
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).not_to be
end
scenario "Flagging turbolinks sanity check", :js do
legislation_annotation = create(:legislation_annotation, text: "Should we change the world?")
comment = create(:comment, commentable: legislation_annotation)
login_as(user)
visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process,
legislation_annotation.draft_version,
legislation_annotation)
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
expect(page).to have_selector("#flag-comment-#{comment.id}")
end
end
scenario "Erasing a comment's author" do
legislation_annotation = create(:legislation_annotation)
comment = create(:comment, commentable: legislation_annotation, body: "this should be visible")

View File

@@ -7,6 +7,7 @@ describe "Commenting legislation questions" do
context "Concerns" do
it_behaves_like "notifiable in-app", :legislation_question
it_behaves_like "flaggable", :legislation_question_comment
end
scenario "Index" do
@@ -320,53 +321,6 @@ describe "Commenting legislation questions" do
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
end
scenario "Flagging as inappropriate", :js do
comment = create(:comment, commentable: legislation_question)
login_as(user)
visit legislation_process_question_path(legislation_question.process, legislation_question)
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
page.find("#flag-comment-#{comment.id}").click
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).to be
end
scenario "Undoing flagging as inappropriate", :js do
comment = create(:comment, commentable: legislation_question)
Flag.flag(user, comment)
login_as(user)
visit legislation_process_question_path(legislation_question.process, legislation_question)
within "#comment_#{comment.id}" do
page.find("#unflag-expand-comment-#{comment.id}").click
page.find("#unflag-comment-#{comment.id}").click
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).not_to be
end
scenario "Flagging turbolinks sanity check", :js do
legislation_question = create(:legislation_question, process: process, title: "Should we change the world?")
comment = create(:comment, commentable: legislation_question)
login_as(user)
visit legislation_process_path(legislation_question.process)
click_link "Should we change the world?"
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
expect(page).to have_selector("#flag-comment-#{comment.id}")
end
end
scenario "Erasing a comment's author" do
comment = create(:comment, commentable: legislation_question, body: "this should be visible")
comment.user.erase

View File

@@ -4,6 +4,8 @@ describe "Commenting proposals" do
let(:user) { create :user }
let(:proposal) { create :proposal }
it_behaves_like "flaggable", :proposal_comment
scenario "Index" do
3.times { create(:comment, commentable: proposal) }
@@ -296,53 +298,6 @@ describe "Commenting proposals" do
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
end
scenario "Flagging as inappropriate", :js do
comment = create(:comment, commentable: proposal)
login_as(user)
visit proposal_path(proposal)
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
page.find("#flag-comment-#{comment.id}").click
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).to be
end
scenario "Undoing flagging as inappropriate", :js do
comment = create(:comment, commentable: proposal)
Flag.flag(user, comment)
login_as(user)
visit proposal_path(proposal)
within "#comment_#{comment.id}" do
page.find("#unflag-expand-comment-#{comment.id}").click
page.find("#unflag-comment-#{comment.id}").click
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).not_to be
end
scenario "Flagging turbolinks sanity check", :js do
proposal = create(:proposal, title: "Should we change the world?")
comment = create(:comment, commentable: proposal)
login_as(user)
visit proposals_path
click_link "Should we change the world?"
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
expect(page).to have_selector("#flag-comment-#{comment.id}")
end
end
scenario "Erasing a comment's author" do
proposal = create(:proposal)
comment = create(:comment, commentable: proposal, body: "this should be visible")

View File

@@ -4,6 +4,8 @@ describe "Commenting topics from proposals" do
let(:user) { create :user }
let(:proposal) { create :proposal }
it_behaves_like "flaggable", :topic_with_community_comment
scenario "Index" do
community = proposal.community
topic = create(:topic, community: community)
@@ -330,58 +332,6 @@ describe "Commenting topics from proposals" do
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
end
scenario "Flagging as inappropriate", :js do
community = proposal.community
topic = create(:topic, community: community)
comment = create(:comment, commentable: topic)
login_as(user)
visit community_topic_path(community, topic)
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
page.find("#flag-comment-#{comment.id}").click
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).to be
end
scenario "Undoing flagging as inappropriate", :js do
community = proposal.community
topic = create(:topic, community: community)
comment = create(:comment, commentable: topic)
Flag.flag(user, comment)
login_as(user)
visit community_topic_path(community, topic)
within "#comment_#{comment.id}" do
page.find("#unflag-expand-comment-#{comment.id}").click
page.find("#unflag-comment-#{comment.id}").click
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).not_to be
end
scenario "Flagging turbolinks sanity check", :js do
community = proposal.community
topic = create(:topic, community: community, title: "Should we change the world?")
comment = create(:comment, commentable: topic)
login_as(user)
visit community_path(community)
click_link "Should we change the world?"
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
expect(page).to have_selector("#flag-comment-#{comment.id}")
end
end
scenario "Erasing a comment's author" do
community = proposal.community
topic = create(:topic, community: community)
@@ -890,58 +840,6 @@ describe "Commenting topics from budget investments" do
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
end
scenario "Flagging as inappropriate", :js do
community = investment.community
topic = create(:topic, community: community)
comment = create(:comment, commentable: topic)
login_as(user)
visit community_topic_path(community, topic)
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
page.find("#flag-comment-#{comment.id}").click
expect(page).to have_css("#unflag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).to be
end
scenario "Undoing flagging as inappropriate", :js do
community = investment.community
topic = create(:topic, community: community)
comment = create(:comment, commentable: topic)
Flag.flag(user, comment)
login_as(user)
visit community_topic_path(community, topic)
within "#comment_#{comment.id}" do
page.find("#unflag-expand-comment-#{comment.id}").click
page.find("#unflag-comment-#{comment.id}").click
expect(page).to have_css("#flag-expand-comment-#{comment.id}")
end
expect(Flag.flagged?(user, comment)).not_to be
end
scenario "Flagging turbolinks sanity check", :js do
community = investment.community
topic = create(:topic, community: community, title: "Should we change the world?")
comment = create(:comment, commentable: topic)
login_as(user)
visit community_path(community)
click_link "Should we change the world?"
within "#comment_#{comment.id}" do
page.find("#flag-expand-comment-#{comment.id}").click
expect(page).to have_selector("#flag-comment-#{comment.id}")
end
end
scenario "Erasing a comment's author" do
community = investment.community
topic = create(:topic, community: community)