Merge pull request #3948 from consul/fix-bug-flagging-legislation-proposals

Fix bug flagging legislation proposals
This commit is contained in:
Javier Martín
2020-07-08 12:34:51 +02:00
committed by GitHub
35 changed files with 170 additions and 701 deletions

View File

@@ -2,7 +2,7 @@
"use strict";
App.Flaggable = {
update: function(resource_id, button) {
$("#" + resource_id + " .js-flag-actions").html(button).foundation();
$("#" + resource_id + " .js-flag-actions").first().html(button).foundation();
}
};
}).call(this);

View File

@@ -35,13 +35,15 @@ class CommentsController < ApplicationController
def flag
Flag.flag(current_user, @comment)
set_comment_flags(@comment)
respond_with @comment, template: "comments/_refresh_flag_actions"
render "shared/_refresh_flag_actions", locals: { flaggable: @comment, divider: true }
end
def unflag
Flag.unflag(current_user, @comment)
set_comment_flags(@comment)
respond_with @comment, template: "comments/_refresh_flag_actions"
render "shared/_refresh_flag_actions", locals: { flaggable: @comment, divider: true }
end
private

View File

@@ -4,21 +4,13 @@ module FlagActions
def flag
Flag.flag(current_user, flaggable)
if controller_name == "investments"
respond_with flaggable, template: "budgets/#{controller_name}/_refresh_flag_actions"
else
respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions"
end
render "shared/_refresh_flag_actions", locals: { flaggable: flaggable }
end
def unflag
Flag.unflag(current_user, flaggable)
if controller_name == "investments"
respond_with flaggable, template: "budgets/#{controller_name}/_refresh_flag_actions"
else
respond_with flaggable, template: "#{controller_name}/_refresh_flag_actions"
end
render "shared/_refresh_flag_actions", locals: { flaggable: flaggable }
end
private
@@ -26,6 +18,8 @@ module FlagActions
def flaggable
if resource_model.to_s == "Budget::Investment"
instance_variable_get("@investment")
elsif resource_model.to_s == "Legislation::Proposal"
instance_variable_get("@proposal")
else
instance_variable_get("@#{resource_model.to_s.downcase}")
end

View File

@@ -2,7 +2,7 @@
<%= t("admin.header.title") %> - <%= t("admin.menu.debates") %> - <%= @debate.title %>
<% end %>
<div class="debate-show">
<div id="<%= dom_id(@debate) %>" class="debate-show">
<h2><%= @debate.title %></h2>
<% if @debate.conflictive? %>
@@ -21,8 +21,8 @@
<%= link_to t("debates.show.comments", count: @debate.comments_count), "#comments" %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="js-flag-actions">
<%= render "debates/flag_actions", debate: @debate %>
</span>
<%= render "shared/flag_actions", flaggable: @debate %>
</span>
</div>
<%= auto_link_already_sanitized_html wysiwyg(@debate.description) %>

View File

@@ -1,25 +0,0 @@
<span class="flag-content">
<% if show_flag_action? investment %>
<a id="flag-expand-investment-<%= investment.id %>" data-toggle="flag-drop-investment-<%= investment.id %>" title="<%= t("shared.flag") %>">
<span class="icon-flag flag-disable"></span>
</a>
<span class="dropdown-pane" id="flag-drop-investment-<%= investment.id %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.flag"), flag_budget_investment_path(investment.budget, investment.id),
method: :put,
remote: true,
id: "flag-investment-#{investment.id}" %>
</span>
<% end %>
<% if show_unflag_action? investment %>
<a id="unflag-expand-investment-<%= investment.id %>" data-toggle="unflag-drop-investment-<%= investment.id %>" title="<%= t("shared.unflag") %>">
<span class="icon-flag flag-active"></span>
</a>
<span class="dropdown-pane" id="unflag-drop-investment-<%= investment.id %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.unflag"), unflag_budget_investment_path(investment.budget, investment.id),
method: :put,
remote: true,
id: "unflag-investment-#{investment.id}" %>
</span>
<% end %>
</span>

View File

@@ -9,7 +9,7 @@
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<% if local_assigns[:preview].nil? %>
<span class="js-flag-actions">
<%= render "budgets/investments/flag_actions", investment: investment %>
<%= render "shared/flag_actions", flaggable: investment %>
</span>
<% end %>
</div>

View File

@@ -1 +0,0 @@
App.Flaggable.update("<%= dom_id(@investment) %>", "<%= j render("budgets/investments/flag_actions", investment: @investment) %>")

View File

@@ -1,5 +1,5 @@
<span id="flag-actions-<%= dom_id(comment) %>" class="js-flag-actions">
<%= render "comments/flag_actions", comment: comment %>
<span class="js-flag-actions">
<%= render "shared/flag_actions", flaggable: comment, divider: true %>
</span>
<span class="js-moderation-actions">

View File

@@ -1,30 +0,0 @@
<span class="flag-content">
<% if show_flag_action? comment %>
<span class="divider">&nbsp;|&nbsp;</span>
<a id="flag-expand-comment-<%= comment.id %>"
data-toggle="flag-drop-comment-<%= comment.id %>"
title="<%= t("shared.flag") %>">
<span class="icon-flag flag-disable"></span>
</a>
<span id="flag-drop-comment-<%= comment.id %>"
class="dropdown-pane"
data-dropdown
data-auto-focus="true">
<%= link_to t("shared.flag"), flag_comment_path(comment), method: :put,
remote: true, id: "flag-comment-#{comment.id}" %>
</span>
<% end %>
<% if show_unflag_action? comment %>
<span class="divider">&nbsp;|&nbsp;</span>
<a id="unflag-expand-comment-<%= comment.id %>"
data-toggle="unflag-drop-comment-<%= comment.id %>"
title="<%= t("shared.unflag") %>">
<span class="icon-flag flag-active"></span>
</a>
<span class="dropdown-pane" id="unflag-drop-comment-<%= comment.id %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.unflag"), unflag_comment_path(comment), method: :put,
remote: true, id: "unflag-comment-#{comment.id}" %>
</span>
<% end %>
</span>

View File

@@ -1 +0,0 @@
$("#flag-actions-<%= dom_id(@comment) %>").html("<%= j render("comments/flag_actions", comment: @comment) %>");

View File

@@ -1,19 +0,0 @@
<span class="flag-content">
<% if show_flag_action? debate %>
<a id="flag-expand-debate-<%= debate.id %>" data-toggle="flag-drop-debate-<%= debate.id %>" title="<%= t("shared.flag") %>">
<span class="icon-flag flag-disable"></span>
</a>
<span class="dropdown-pane" id="flag-drop-debate-<%= debate.id %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.flag"), flag_debate_path(debate), method: :put, remote: true, id: "flag-debate-#{debate.id}" %>
</span>
<% end %>
<% if show_unflag_action? debate %>
<a id="unflag-expand-debate-<%= debate.id %>" data-toggle="unflag-drop-debate-<%= debate.id %>" title="<%= t("shared.unflag") %>">
<span class="icon-flag flag-active"></span>
</a>
<span class="dropdown-pane" id="unflag-drop-debate-<%= debate.id %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.unflag"), unflag_debate_path(debate), method: :put, remote: true, id: "unflag-debate-#{debate.id}" %>
</span>
<% end %>
</span>

View File

@@ -1 +0,0 @@
$("#<%= dom_id(@debate) %> .js-flag-actions").html("<%= j render("debates/flag_actions", debate: @debate) %>");

View File

@@ -26,7 +26,7 @@
<%= link_to t("debates.show.comments", count: @debate.comments_count), "#comments" %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="js-flag-actions">
<%= render "debates/flag_actions", debate: @debate %>
<%= render "shared/flag_actions", flaggable: @debate %>
</span>
</div>

View File

@@ -1,21 +0,0 @@
<span class="js-flag-actions">
<span class="flag-content">
<% if show_flag_action? proposal %>
<a id="flag-expand-proposal-<%= proposal.id %>" data-toggle="flag-drop-proposal-<%= proposal.id %>" title="<%= t("shared.flag") %>">
<span class="icon-flag flag-disable"></span>
</a>
<span class="dropdown-pane" id="flag-drop-proposal-<%= proposal.id %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.flag"), flag_proposal_path(proposal), method: :put, remote: true, id: "flag-proposal-#{proposal.id}" %>
</span>
<% end %>
<% if show_unflag_action? proposal %>
<a id="unflag-expand-proposal-<%= proposal.id %>" data-toggle="unflag-drop-proposal-<%= proposal.id %>" title="<%= t("shared.unflag") %>">
<span class="icon-flag flag-active"></span>
</a>
<span class="dropdown-pane" id="unflag-drop-proposal-<%= proposal.id %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.unflag"), unflag_proposal_path(proposal), method: :put, remote: true, id: "unflag-proposal-#{proposal.id}" %>
</span>
<% end %>
</span>
</span>

View File

@@ -1 +0,0 @@
$("#<%= dom_id(@proposal) %> .js-flag-actions").html("<%= j render("proposals/flag_actions", proposal: @proposal) %>");

View File

@@ -45,7 +45,9 @@
<% if current_user %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= render "proposals/flag_actions", proposal: @proposal %>
<span class="js-flag-actions">
<%= render "shared/flag_actions", flaggable: @proposal %>
</span>
<% end %>
</div>

View File

@@ -1,19 +0,0 @@
<span class="flag-content">
<% if show_flag_action? proposal %>
<a id="flag-expand-proposal-<%= proposal.id %>" data-toggle="flag-drop-proposal-<%= proposal.id %>" title="<%= t("shared.flag") %>">
<span class="icon-flag flag-disable"></span>
</a>
<span class="dropdown-pane" id="flag-drop-proposal-<%= proposal.id %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.flag"), flag_proposal_path(proposal), method: :put, remote: true, id: "flag-proposal-#{proposal.id}" %>
</span>
<% end %>
<% if show_unflag_action? proposal %>
<a id="unflag-expand-proposal-<%= proposal.id %>" data-toggle="unflag-drop-proposal-<%= proposal.id %>" title="<%= t("shared.unflag") %>">
<span class="icon-flag flag-active"></span>
</a>
<span class="dropdown-pane" id="unflag-drop-proposal-<%= proposal.id %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.unflag"), unflag_proposal_path(proposal), method: :put, remote: true, id: "unflag-proposal-#{proposal.id}" %>
</span>
<% end %>
</span>

View File

@@ -13,7 +13,7 @@
<% if current_user %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<span class="js-flag-actions">
<%= render "proposals/flag_actions", proposal: @proposal %>
<%= render "shared/flag_actions", flaggable: @proposal %>
</span>
<% end %>

View File

@@ -1,2 +0,0 @@
App.Flaggable.update("<%= dom_id(@proposal) %>",
"<%= j render("proposals/flag_actions", proposal: @proposal) %>")

View File

@@ -0,0 +1,27 @@
<span class="flag-content">
<% if show_flag_action?(flaggable) %>
<% if local_assigns[:divider] %>
<span class="divider">&nbsp;|&nbsp;</span>
<% end %>
<a data-toggle="flag-drop-<%= dom_id(flaggable) %>" title="<%= t("shared.flag") %>">
<span class="icon-flag flag-disable"></span>
</a>
<span class="dropdown-pane" id="flag-drop-<%= dom_id(flaggable) %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.flag"), polymorphic_path(flaggable, action: :flag), method: :put, remote: true %>
</span>
<% end %>
<% if show_unflag_action?(flaggable) %>
<% if local_assigns[:divider] %>
<span class="divider">&nbsp;|&nbsp;</span>
<% end %>
<a data-toggle="unflag-drop-<%= dom_id(flaggable) %>" title="<%= t("shared.unflag") %>">
<span class="icon-flag flag-active"></span>
</a>
<span class="dropdown-pane" id="unflag-drop-<%= dom_id(flaggable) %>" data-dropdown data-auto-focus="true">
<%= link_to t("shared.unflag"), polymorphic_path(flaggable, action: :unflag), method: :put, remote: true %>
</span>
<% end %>
</span>

View File

@@ -0,0 +1,3 @@
App.Flaggable.update("<%= dom_id(flaggable) %>",
"<%= j render("shared/flag_actions", flaggable: flaggable, divider: local_assigns[:divider]) %>"
);

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

@@ -0,0 +1,97 @@
shared_examples "flaggable" do |factory_name, admin: false|
include ActionView::RecordIdentifier
let(:flaggable) { create(factory_name) }
let(:user) do
if admin
create(:administrator).user
else
create(:user, :level_two)
end
end
let(:path) do
if flaggable.is_a?(Comment)
polymorphic_path(flaggable.commentable)
elsif admin
admin_polymorphic_path(flaggable)
else
polymorphic_path(flaggable)
end
end
scenario "Flagging as inappropriate", :js do
login_as(user)
visit path
within "##{dom_id(flaggable)} .flag-content" do
find(".icon-flag").click
click_link "Flag as inappropriate"
expect(page).to have_css ".flag-active"
expect(page).to have_link "Unflag", visible: false
end
expect(Flag.flagged?(user, flaggable)).to be
end
scenario "Unflagging", :js do
Flag.flag(user, flaggable)
login_as(user)
visit path
within "##{dom_id(flaggable)} .flag-content" do
expect(page).to have_css ".flag-active"
find(".icon-flag").click
click_link "Unflag"
expect(page).not_to have_css ".flag-active"
expect(page).to have_link "Flag as inappropriate", visible: false
end
expect(Flag.flagged?(user, flaggable)).not_to be
end
scenario "Flagging and unflagging", :js do
login_as(user)
visit path
within "##{dom_id(flaggable)} .flag-content" do
find(".icon-flag").click
click_link "Flag as inappropriate"
expect(page).to have_css ".flag-active"
expect(Flag.flagged?(user, flaggable)).to be
find(".icon-flag").click
click_link "Unflag"
expect(page).not_to have_css ".flag-active"
end
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

@@ -6,6 +6,8 @@ describe "Admin debates" do
login_as(admin.user)
end
it_behaves_like "flaggable", :debate, admin: true
scenario "Index" do
create(:debate, title: "Best beaches")

View File

@@ -22,6 +22,7 @@ describe "Budget Investments" do
:budget_investment,
"budget_investment_path",
{ "budget_id": "budget_id", "id": "id" }
it_behaves_like "flaggable", :budget_investment
end
context "Load" do
@@ -1795,70 +1796,6 @@ describe "Budget Investments" do
end
end
scenario "Flagging an investment as innapropriate", :js do
user = create(:user)
investment = create(:budget_investment, heading: heading)
login_as(user)
visit budget_investment_path(budget, investment)
within "#budget_investment_#{investment.id}" do
find("#flag-expand-investment-#{investment.id}").click
find("#flag-investment-#{investment.id}").click
expect(page).to have_css("#unflag-expand-investment-#{investment.id}")
end
expect(Flag.flagged?(user, investment)).to be
end
scenario "Unflagging an investment", :js do
user = create(:user)
investment = create(:budget_investment, heading: heading)
Flag.flag(user, investment)
login_as(user)
visit budget_investment_path(budget, investment)
within "#budget_investment_#{investment.id}" do
find("#unflag-expand-investment-#{investment.id}").click
find("#unflag-investment-#{investment.id}").click
expect(page).to have_css("#flag-expand-investment-#{investment.id}")
end
expect(Flag.flagged?(user, investment)).not_to be
end
scenario "Flagging an investment updates the DOM properly", :js do
user = create(:user)
investment = create(:budget_investment, heading: heading)
login_as(user)
visit budget_investment_path(budget, investment)
within "#budget_investment_#{investment.id}" do
find("#flag-expand-investment-#{investment.id}").click
find("#flag-investment-#{investment.id}").click
expect(page).to have_css("#unflag-expand-investment-#{investment.id}")
end
expect(Flag.flagged?(user, investment)).to be
within "#budget_investment_#{investment.id}" do
find("#unflag-expand-investment-#{investment.id}").click
find("#unflag-investment-#{investment.id}").click
expect(page).to have_css("#flag-expand-investment-#{investment.id}")
end
expect(Flag.flagged?(user, investment)).not_to be
end
context "sidebar map" do
scenario "Display 6 investment's markers on sidebar map", :js do
investment1 = create(:budget_investment, heading: heading)

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,53 +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
expect(page).to have_selector("#flag-comment-#{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

@@ -298,59 +298,6 @@ describe "Commenting polls" do
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
end
scenario "Flagging as inappropriate", :js do
skip "Feature not implemented yet, review soon"
comment = create(:comment, commentable: poll)
login_as(user)
visit poll_path(poll)
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
skip "Feature not implemented yet, review soon"
comment = create(:comment, commentable: poll)
Flag.flag(user, comment)
login_as(user)
visit poll_path(poll)
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
skip "Feature not implemented yet, review soon"
poll = create(:poll, title: "Should we change the world?")
comment = create(:comment, commentable: poll)
login_as(user)
visit polls_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
poll = create(:poll)
comment = create(:comment, commentable: poll, body: "this should be visible")

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)

View File

@@ -17,6 +17,7 @@ describe "Debates" do
:debate,
"debate_path",
{ "id": "id" }
it_behaves_like "flaggable", :debate
end
scenario "Index" do
@@ -345,41 +346,6 @@ describe "Debates" do
expect(page).to have_content error_message
end
scenario "Flagging", :js do
user = create(:user)
debate = create(:debate)
login_as(user)
visit debate_path(debate)
within "#debate_#{debate.id}" do
page.find("#flag-expand-debate-#{debate.id}").click
page.find("#flag-debate-#{debate.id}").click
expect(page).to have_css("#unflag-expand-debate-#{debate.id}")
end
expect(Flag.flagged?(user, debate)).to be
end
scenario "Unflagging", :js do
user = create(:user)
debate = create(:debate)
Flag.flag(user, debate)
login_as(user)
visit debate_path(debate)
within "#debate_#{debate.id}" do
page.find("#unflag-expand-debate-#{debate.id}").click
page.find("#unflag-debate-#{debate.id}").click
expect(page).to have_css("#flag-expand-debate-#{debate.id}")
end
expect(Flag.flagged?(user, debate)).not_to be
end
describe "Debate index order filters" do
scenario "Default order is hot_score", :js do
best_debate = create(:debate, title: "Best")

View File

@@ -8,6 +8,7 @@ describe "Legislation Proposals" do
context "Concerns" do
it_behaves_like "notifiable in-app", :legislation_proposal
it_behaves_like "flaggable", :legislation_proposal
end
scenario "Only one menu element has 'active' CSS selector" do

View File

@@ -19,6 +19,7 @@ describe "Proposals" do
:proposal,
"proposal_path",
{ "id": "id" }
it_behaves_like "flaggable", :proposal
end
context "Index" do
@@ -1501,69 +1502,6 @@ describe "Proposals" do
expect(page).not_to have_content "This proposal has been flagged as inappropriate by several users."
end
scenario "Flagging", :js do
user = create(:user)
proposal = create(:proposal)
login_as(user)
visit proposal_path(proposal)
within "#proposal_#{proposal.id}" do
page.find("#flag-expand-proposal-#{proposal.id}").click
page.find("#flag-proposal-#{proposal.id}").click
expect(page).to have_css("#unflag-expand-proposal-#{proposal.id}")
end
expect(Flag.flagged?(user, proposal)).to be
end
scenario "Unflagging", :js do
user = create(:user)
proposal = create(:proposal)
Flag.flag(user, proposal)
login_as(user)
visit proposal_path(proposal)
within "#proposal_#{proposal.id}" do
page.find("#unflag-expand-proposal-#{proposal.id}").click
page.find("#unflag-proposal-#{proposal.id}").click
expect(page).to have_css("#flag-expand-proposal-#{proposal.id}")
end
expect(Flag.flagged?(user, proposal)).not_to be
end
scenario "Flagging/Unflagging AJAX", :js do
user = create(:user)
proposal = create(:proposal)
login_as(user)
visit proposal_path(proposal)
# Flagging
within "#proposal_#{proposal.id}" do
page.find("#flag-expand-proposal-#{proposal.id}").click
page.find("#flag-proposal-#{proposal.id}").click
expect(page).to have_css("#unflag-expand-proposal-#{proposal.id}")
end
expect(Flag.flagged?(user, proposal)).to be
# Unflagging
within "#proposal_#{proposal.id}" do
page.find("#unflag-expand-proposal-#{proposal.id}").click
page.find("#unflag-proposal-#{proposal.id}").click
expect(page).to have_css("#flag-expand-proposal-#{proposal.id}")
end
expect(Flag.flagged?(user, proposal)).not_to be
end
it_behaves_like "followable", "proposal", "proposal_path", { "id": "id" }
it_behaves_like "imageable", "proposal", "proposal_path", { "id": "id" }