Merge pull request #5369 from consuldemocracy/refactor_comments_specs
Make comments specs faster
This commit is contained in:
46
app/components/comments/form_component.html.erb
Normal file
46
app/components/comments/form_component.html.erb
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<% cache cache_key do %>
|
||||||
|
<% if comments_closed_for_commentable?(commentable) %>
|
||||||
|
<br>
|
||||||
|
<div data-alert class="callout primary">
|
||||||
|
<%= comments_closed_text %>
|
||||||
|
</div>
|
||||||
|
<% elsif require_verified_resident_for_commentable?(commentable, current_user) %>
|
||||||
|
<br>
|
||||||
|
<div data-alert class="callout primary">
|
||||||
|
<%= sanitize(t("comments.verified_only", verify_account: link_to_verify_account)) %>
|
||||||
|
</div>
|
||||||
|
<% elsif !valuation || can?(:comment_valuation, commentable) %>
|
||||||
|
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
|
||||||
|
<div id="js-comment-form-<%= css_id %>" class="comment-form">
|
||||||
|
<%= form_for Comment.new, remote: true, html: { id: "new_comment_#{css_id}" } do |f| %>
|
||||||
|
<%= f.text_area :body,
|
||||||
|
id: "comment-body-#{css_id}",
|
||||||
|
maxlength: Comment.body_max_length,
|
||||||
|
label: leave_comment_text(commentable) %>
|
||||||
|
|
||||||
|
<%= f.hidden_field :commentable_type, value: commentable.class.name, id: "comment_commentable_type_#{css_id}" %>
|
||||||
|
<%= f.hidden_field :commentable_id, value: commentable.id, id: "comment_commentable_id_#{css_id}" %>
|
||||||
|
<%= f.hidden_field :parent_id, value: parent_id, id: "comment_parent_id_#{css_id}" %>
|
||||||
|
<%= f.hidden_field :valuation, value: valuation, id: "comment_valuation_#{css_id}" %>
|
||||||
|
|
||||||
|
<%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment_#{css_id}" %>
|
||||||
|
|
||||||
|
<% if can? :comment_as_moderator, commentable %>
|
||||||
|
<div class="float-right">
|
||||||
|
<%= f.check_box :as_moderator,
|
||||||
|
label: t("comments.form.comment_as_moderator"),
|
||||||
|
id: "comment-as-moderator-#{css_id}" %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% if can? :comment_as_administrator, commentable %>
|
||||||
|
<div class="float-right">
|
||||||
|
<%= f.check_box :as_administrator,
|
||||||
|
label: t("comments.form.comment_as_admin"),
|
||||||
|
id: "comment-as-administrator-#{css_id}" %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
32
app/components/comments/form_component.rb
Normal file
32
app/components/comments/form_component.rb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
class Comments::FormComponent < ApplicationComponent
|
||||||
|
attr_reader :commentable, :parent_id, :valuation
|
||||||
|
use_helpers :current_user, :locale_and_user_status, :commentable_cache_key,
|
||||||
|
:comments_closed_for_commentable?, :require_verified_resident_for_commentable?,
|
||||||
|
:link_to_verify_account, :parent_or_commentable_dom_id, :leave_comment_text, :can?,
|
||||||
|
:comment_button_text
|
||||||
|
|
||||||
|
def initialize(commentable, parent_id: nil, valuation: false)
|
||||||
|
@commentable = commentable
|
||||||
|
@parent_id = parent_id
|
||||||
|
@valuation = valuation
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def cache_key
|
||||||
|
[
|
||||||
|
locale_and_user_status,
|
||||||
|
parent_id,
|
||||||
|
commentable_cache_key(commentable),
|
||||||
|
valuation
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
def comments_closed_text
|
||||||
|
if commentable.class == Legislation::Question
|
||||||
|
t("legislation.questions.comments.comments_closed")
|
||||||
|
else
|
||||||
|
t("comments.comments_closed")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -4,13 +4,13 @@
|
|||||||
|
|
||||||
<% cache cache_key do %>
|
<% cache cache_key do %>
|
||||||
<% if current_user %>
|
<% if current_user %>
|
||||||
<%= render "comments/form", { commentable: record, parent_id: nil } %>
|
<%= render Comments::FormComponent.new(record, valuation: valuation) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= render "shared/login_to_comment" %>
|
<%= render "shared/login_to_comment" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render Shared::OrderLinksComponent.new("comments", anchor: "comments") %>
|
<%= render Shared::OrderLinksComponent.new("comments", anchor: "comments") %>
|
||||||
<%= render "comments/comment_list", comments: comment_tree.root_comments %>
|
<%= render "comments/comment_list", comments: comment_tree.root_comments, valuation: valuation %>
|
||||||
<%= paginate comment_tree.root_comments, params: { anchor: "comments" } %>
|
<%= paginate comment_tree.root_comments, params: { anchor: "comments" } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
class Shared::CommentsComponent < ApplicationComponent
|
class Shared::CommentsComponent < ApplicationComponent
|
||||||
attr_reader :record, :comment_tree
|
attr_reader :record, :comment_tree, :valuation
|
||||||
use_helpers :current_user, :current_order, :locale_and_user_status, :commentable_cache_key
|
use_helpers :current_user, :current_order, :locale_and_user_status, :commentable_cache_key
|
||||||
|
|
||||||
def initialize(record, comment_tree)
|
def initialize(record, comment_tree, valuation: false)
|
||||||
@record = record
|
@record = record
|
||||||
@comment_tree = comment_tree
|
@comment_tree = comment_tree
|
||||||
|
@valuation = valuation
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -1,12 +1,4 @@
|
|||||||
module CommentsHelper
|
module CommentsHelper
|
||||||
def comment_tree_title_text(commentable)
|
|
||||||
if commentable.class == Legislation::Question
|
|
||||||
t("legislation.questions.comments.comments_title")
|
|
||||||
else
|
|
||||||
t("comments_helper.comments_title")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def leave_comment_text(commentable)
|
def leave_comment_text(commentable)
|
||||||
if commentable.class == Legislation::Question
|
if commentable.class == Legislation::Question
|
||||||
t("legislation.questions.comments.form.leave_comment")
|
t("legislation.questions.comments.form.leave_comment")
|
||||||
@@ -82,12 +74,4 @@ module CommentsHelper
|
|||||||
def comments_closed_for_commentable?(commentable)
|
def comments_closed_for_commentable?(commentable)
|
||||||
commentable.respond_to?(:comments_closed?) && commentable.comments_closed?
|
commentable.respond_to?(:comments_closed?) && commentable.comments_closed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def comments_closed_text(commentable)
|
|
||||||
if commentable.class == Legislation::Question
|
|
||||||
t("legislation.questions.comments.comments_closed")
|
|
||||||
else
|
|
||||||
t("comments.comments_closed")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,9 +17,7 @@
|
|||||||
<div class="tabs-content" data-tabs-content="investments_tabs">
|
<div class="tabs-content" data-tabs-content="investments_tabs">
|
||||||
<div class="tabs-panel is-active" id="tab-comments">
|
<div class="tabs-panel is-active" id="tab-comments">
|
||||||
<%= render MachineLearning::CommentsSummaryComponent.new(@investment) %>
|
<%= render MachineLearning::CommentsSummaryComponent.new(@investment) %>
|
||||||
|
<%= render Shared::CommentsComponent.new(@investment, @comment_tree) %>
|
||||||
<%= render "/comments/comment_tree", comment_tree: @comment_tree,
|
|
||||||
display_comments_count: false %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= render "milestones/milestones", milestoneable: @investment %>
|
<%= render "milestones/milestones", milestoneable: @investment %>
|
||||||
|
|||||||
@@ -99,9 +99,9 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if !valuation || can?(:comment_valuation, comment.commentable) %>
|
<% if !valuation || can?(:comment_valuation, comment.commentable) %>
|
||||||
<%= render "comments/form", { commentable: comment.commentable,
|
<%= render Comments::FormComponent.new(comment.commentable,
|
||||||
parent_id: comment.id,
|
parent_id: comment.id,
|
||||||
valuation: valuation } %>
|
valuation: valuation) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
<% commentable = comment_tree.commentable %>
|
|
||||||
<% valuation = local_assigns.fetch(:valuation, false) %>
|
|
||||||
<% cache [locale_and_user_status, comment_tree.order, commentable_cache_key(commentable), comment_tree.comments, comment_tree.comment_authors, commentable.comments_count] do %>
|
|
||||||
<section class="expanded comments">
|
|
||||||
<div class="row">
|
|
||||||
<div id="comments" class="small-12 column">
|
|
||||||
<% if display_comments_count %>
|
|
||||||
<h2>
|
|
||||||
<%= comment_tree_title_text(commentable) %>
|
|
||||||
<span class="js-comments-count">(<%= commentable.comments_count %>)</span>
|
|
||||||
</h2>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if user_signed_in? %>
|
|
||||||
<% if comments_closed_for_commentable?(commentable) %>
|
|
||||||
<br>
|
|
||||||
<div data-alert class="callout primary">
|
|
||||||
<%= comments_closed_text(commentable) %>
|
|
||||||
</div>
|
|
||||||
<% elsif require_verified_resident_for_commentable?(commentable, current_user) %>
|
|
||||||
<br>
|
|
||||||
<div data-alert class="callout primary">
|
|
||||||
<%= sanitize(t("comments.verified_only", verify_account: link_to_verify_account)) %>
|
|
||||||
</div>
|
|
||||||
<% elsif !valuation || can?(:comment_valuation, commentable) %>
|
|
||||||
<%= render "comments/form", { commentable: commentable,
|
|
||||||
parent_id: nil,
|
|
||||||
valuation: valuation } %>
|
|
||||||
<% end %>
|
|
||||||
<% else %>
|
|
||||||
<%= render "shared/login_to_comment" %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render Shared::OrderLinksComponent.new("comments", anchor: "comments") %>
|
|
||||||
<%= render "comments/comment_list", comments: comment_tree.root_comments, valuation: valuation %>
|
|
||||||
<%= paginate comment_tree.root_comments, params: { anchor: "comments" } %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<% end %>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<% valuation = local_assigns.fetch(:valuation, false) %>
|
|
||||||
<% cache [locale_and_user_status, parent_id, commentable_cache_key(commentable), valuation] do %>
|
|
||||||
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
|
|
||||||
<div id="js-comment-form-<%= css_id %>" class="comment-form">
|
|
||||||
<%= form_for Comment.new, remote: true, html: { id: "new_comment_#{css_id}" } do |f| %>
|
|
||||||
<%= f.text_area :body,
|
|
||||||
id: "comment-body-#{css_id}",
|
|
||||||
maxlength: Comment.body_max_length,
|
|
||||||
label: leave_comment_text(commentable) %>
|
|
||||||
|
|
||||||
<%= f.hidden_field :commentable_type, value: commentable.class.name, id: "comment_commentable_type_#{css_id}" %>
|
|
||||||
<%= f.hidden_field :commentable_id, value: commentable.id, id: "comment_commentable_id_#{css_id}" %>
|
|
||||||
<%= f.hidden_field :parent_id, value: parent_id, id: "comment_parent_id_#{css_id}" %>
|
|
||||||
<%= f.hidden_field :valuation, value: valuation, id: "comment_valuation_#{css_id}" %>
|
|
||||||
|
|
||||||
<%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment_#{css_id}" %>
|
|
||||||
|
|
||||||
<% if can? :comment_as_moderator, commentable %>
|
|
||||||
<div class="float-right">
|
|
||||||
<%= f.check_box :as_moderator,
|
|
||||||
label: t("comments.form.comment_as_moderator"),
|
|
||||||
id: "comment-as-moderator-#{css_id}" %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
<% if can? :comment_as_administrator, commentable %>
|
|
||||||
<div class="float-right">
|
|
||||||
<%= f.check_box :as_administrator,
|
|
||||||
label: t("comments.form.comment_as_admin"),
|
|
||||||
id: "comment-as-administrator-#{css_id}" %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
@@ -43,8 +43,12 @@
|
|||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= render "/comments/comment_tree", comment_tree: @comment_tree,
|
<%= render Shared::CommentsComponent.new(@annotation, @comment_tree) do %>
|
||||||
display_comments_count: true %>
|
<h2>
|
||||||
|
<%= t("comments_helper.comments_title") %>
|
||||||
|
<span class="js-comments-count">(<%= @annotation.comments_count %>)</span>
|
||||||
|
</h2>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -41,7 +41,10 @@
|
|||||||
<%= render "/shared/social_share", title: @question.title, url: legislation_process_question_url(@question.process, @question) %>
|
<%= render "/shared/social_share", title: @question.title, url: legislation_process_question_url(@question.process, @question) %>
|
||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
|
<%= render Shared::CommentsComponent.new(@question, @comment_tree) do %>
|
||||||
<%= render "/comments/comment_tree", comment_tree: @comment_tree,
|
<h2>
|
||||||
display_comments_count: true %>
|
<%= t("legislation.questions.comments.comments_title") %>
|
||||||
|
<span class="js-comments-count">(<%= @question.comments_count %>)</span>
|
||||||
|
</h2>
|
||||||
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
<h2><%= t("valuation.budget_investments.valuation_comments") %></h2>
|
<h2><%= t("valuation.budget_investments.valuation_comments") %></h2>
|
||||||
<% unless @comment_tree.nil? %>
|
<% unless @comment_tree.nil? %>
|
||||||
<%= render "/comments/comment_tree", comment_tree: @comment_tree,
|
<%= render Shared::CommentsComponent.new(@investment, @comment_tree, valuation: true) %>
|
||||||
display_comments_count: false,
|
|
||||||
valuation: true %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
44
spec/components/comments/form_component_spec.rb
Normal file
44
spec/components/comments/form_component_spec.rb
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Comments::FormComponent do
|
||||||
|
context "Legislation annotation" do
|
||||||
|
it "disables comments when the allegations phase is closed" do
|
||||||
|
process = create(:legislation_process,
|
||||||
|
allegations_start_date: 1.month.ago,
|
||||||
|
allegations_end_date: Date.yesterday)
|
||||||
|
|
||||||
|
version = create(:legislation_draft_version, process: process)
|
||||||
|
annotation = create(:legislation_annotation, draft_version: version, text: "One annotation")
|
||||||
|
|
||||||
|
render_inline Comments::FormComponent.new(annotation)
|
||||||
|
|
||||||
|
expect(page).to have_content "Comments are closed"
|
||||||
|
expect(page).not_to have_content "Leave your comment"
|
||||||
|
expect(page).not_to have_button "Publish comment"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Legislation question" do
|
||||||
|
let(:process) { create(:legislation_process, :in_debate_phase) }
|
||||||
|
let(:question) { create(:legislation_question, process: process) }
|
||||||
|
|
||||||
|
it "prevents unverified users from creating comments" do
|
||||||
|
unverified_user = create(:user)
|
||||||
|
sign_in unverified_user
|
||||||
|
|
||||||
|
render_inline Comments::FormComponent.new(question)
|
||||||
|
|
||||||
|
expect(page).to have_content "To participate verify your account"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "blocks comment creation when the debate phase is not open" do
|
||||||
|
user = create(:user, :level_two)
|
||||||
|
process.update!(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day)
|
||||||
|
sign_in(user)
|
||||||
|
|
||||||
|
render_inline Comments::FormComponent.new(question)
|
||||||
|
|
||||||
|
expect(page).to have_content "Closed phase"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -34,7 +34,12 @@ FactoryBot.define do
|
|||||||
community { create(:proposal).community }
|
community { create(:proposal).community }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_investment_community do
|
||||||
|
community { create(:budget_investment).community }
|
||||||
|
end
|
||||||
|
|
||||||
factory :topic_with_community, traits: [:with_community]
|
factory :topic_with_community, traits: [:with_community]
|
||||||
|
factory :topic_with_investment_community, traits: [:with_investment_community]
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :related_content do
|
factory :related_content do
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ FactoryBot.define do
|
|||||||
sequence(:body) { |n| "Comment body #{n}" }
|
sequence(:body) { |n| "Comment body #{n}" }
|
||||||
|
|
||||||
%i[budget_investment debate legislation_annotation legislation_question legislation_proposal
|
%i[budget_investment debate legislation_annotation legislation_question legislation_proposal
|
||||||
poll proposal topic_with_community].each do |model|
|
poll proposal topic_with_community topic_with_investment_community].each do |model|
|
||||||
factory :"#{model}_comment" do
|
factory :"#{model}_comment" do
|
||||||
commentable factory: model
|
commentable factory: model
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ FactoryBot.define do
|
|||||||
after(:create) { |poll| create(:image, imageable: poll) }
|
after(:create) { |poll| create(:image, imageable: poll) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_author do
|
||||||
|
author factory: :user
|
||||||
|
end
|
||||||
|
|
||||||
transient { officers { [] } }
|
transient { officers { [] } }
|
||||||
|
|
||||||
after(:create) do |poll, evaluator|
|
after(:create) do |poll, evaluator|
|
||||||
@@ -45,6 +49,8 @@ FactoryBot.define do
|
|||||||
create(:poll_officer_assignment, poll: poll, officer: officer)
|
create(:poll_officer_assignment, poll: poll, officer: officer)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :poll_with_author, traits: [:with_author]
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :poll_question, class: "Poll::Question" do
|
factory :poll_question, class: "Poll::Question" do
|
||||||
|
|||||||
@@ -1,415 +1,10 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe "Commenting Budget::Investments" do
|
describe "Commenting Budget::Investments" do
|
||||||
let(:user) { create(:user) }
|
|
||||||
let(:investment) { create(:budget_investment) }
|
let(:investment) { create(:budget_investment) }
|
||||||
|
|
||||||
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
|
|
||||||
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: "Last subcomment")
|
|
||||||
|
|
||||||
visit comment_path(parent_comment)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content "Parent"
|
|
||||||
expect(page).to have_content "First subcomment"
|
|
||||||
expect(page).to have_content "Last subcomment"
|
|
||||||
|
|
||||||
expect(page).to have_link "Go back to #{investment.title}",
|
|
||||||
href: budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
within ".comment", text: "Parent" do
|
|
||||||
expect(page).to have_css ".comment", count: 2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Link to comment show" do
|
|
||||||
comment = create(:comment, commentable: investment, user: user)
|
|
||||||
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_link comment.created_at.strftime("%Y-%m-%d %T")
|
|
||||||
end
|
|
||||||
|
|
||||||
click_link comment.created_at.strftime("%Y-%m-%d %T")
|
|
||||||
|
|
||||||
expect(page).to have_link "Go back to #{investment.title}"
|
|
||||||
expect(page).to have_current_path(comment_path(comment))
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Collapsable comments" do
|
|
||||||
parent_comment = create(:comment, body: "Main comment", commentable: investment)
|
|
||||||
child_comment = create(:comment,
|
|
||||||
body: "First subcomment",
|
|
||||||
commentable: investment,
|
|
||||||
parent: parent_comment)
|
|
||||||
grandchild_comment = create(:comment,
|
|
||||||
body: "Last subcomment",
|
|
||||||
commentable: investment,
|
|
||||||
parent: child_comment)
|
|
||||||
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 2)
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (show)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
expect(page).to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment", text: "Main comment" do
|
|
||||||
click_link text: "1 response (collapse)", match: :first
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 1)
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content child_comment.body
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
end
|
|
||||||
|
|
||||||
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)
|
|
||||||
old_child = create(:comment,
|
|
||||||
commentable: investment,
|
|
||||||
parent_id: new_root.id,
|
|
||||||
created_at: Time.current - 10)
|
|
||||||
new_child = create(:comment,
|
|
||||||
commentable: investment,
|
|
||||||
parent_id: new_root.id,
|
|
||||||
created_at: Time.current)
|
|
||||||
|
|
||||||
visit budget_investment_path(investment.budget, investment, order: :most_voted)
|
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
|
||||||
|
|
||||||
visit budget_investment_path(investment.budget, investment, order: :newest)
|
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
|
||||||
expect(new_child.body).to appear_before(old_child.body)
|
|
||||||
|
|
||||||
visit budget_investment_path(investment.budget, investment, order: :oldest)
|
|
||||||
|
|
||||||
expect(old_root.body).to appear_before(new_root.body)
|
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Turns links into html links" do
|
|
||||||
create(:comment, commentable: investment, body: "Built with http://rubyonrails.org/")
|
|
||||||
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
within first(".comment") do
|
|
||||||
expect(page).to have_content "Built with http://rubyonrails.org/"
|
|
||||||
expect(page).to have_link("http://rubyonrails.org/", href: "http://rubyonrails.org/")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:rel]).to eq("nofollow")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:target]).to be_blank
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Sanitizes comment body for security" do
|
|
||||||
create(:comment, commentable: investment,
|
|
||||||
body: "<script>alert('hola')</script> " \
|
|
||||||
"<a href=\"javascript:alert('sorpresa!')\">click me<a/> " \
|
|
||||||
"http://www.url.com")
|
|
||||||
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
within first(".comment") do
|
|
||||||
expect(page).to have_content "click me http://www.url.com"
|
|
||||||
expect(page).to have_link("http://www.url.com", href: "http://www.url.com")
|
|
||||||
expect(page).not_to have_link("click me")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
describe "Not logged user" do
|
|
||||||
scenario "can not see comments forms" do
|
|
||||||
create(:comment, commentable: investment)
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
expect(page).to have_content "You must sign in or sign up to leave a comment"
|
|
||||||
within("#comments") do
|
|
||||||
expect(page).not_to have_content "Write a comment"
|
|
||||||
expect(page).not_to have_content "Reply"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Create" do
|
|
||||||
login_as(user)
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "Have you thought about...?"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#tab-comments-label" do
|
|
||||||
expect(page).to have_content "Comments (1)"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "Have you thought about...?"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on create" do
|
|
||||||
login_as(user)
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
comment = create(:comment, commentable: investment, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "It will be done next week."
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply update parent comment responses count" do
|
|
||||||
comment = create(:comment, commentable: investment)
|
|
||||||
|
|
||||||
login_as(create(:user))
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply show parent comments responses when hidden" do
|
|
||||||
comment = create(:comment, commentable: investment)
|
|
||||||
create(:comment, commentable: investment, parent: comment)
|
|
||||||
|
|
||||||
login_as(create(:user))
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("It will be done next week.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on reply" do
|
|
||||||
comment = create(:comment, commentable: investment, user: user)
|
|
||||||
|
|
||||||
login_as(user)
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
click_button "Publish reply"
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "N replies" do
|
|
||||||
parent = create(:comment, commentable: investment)
|
|
||||||
|
|
||||||
7.times do
|
|
||||||
create(:comment, commentable: investment, parent: parent)
|
|
||||||
parent = parent.children.first
|
|
||||||
end
|
|
||||||
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Erasing a comment's author" do
|
|
||||||
investment = create(:budget_investment)
|
|
||||||
comment = create(:comment, commentable: investment, body: "this should be visible")
|
|
||||||
comment.user.erase
|
|
||||||
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content("User deleted")
|
|
||||||
expect(page).to have_content("this should be visible")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Moderators" do
|
|
||||||
scenario "can create comment as a moderator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am moderating!"
|
|
||||||
check "comment-as-moderator-budget_investment_#{investment.id}"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am moderating!"
|
|
||||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
|
||||||
expect(page).to have_css "div.is-moderator"
|
|
||||||
expect(page).to have_css "img.moderator-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can create reply as a moderator" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
moderator = create(:moderator, user: manuela)
|
|
||||||
comment = create(:comment, commentable: investment, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "I am moderating!"
|
|
||||||
check "comment-as-moderator-comment_#{comment.id}"
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "I am moderating!"
|
|
||||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
|
||||||
expect(page).to have_css "div.is-moderator"
|
|
||||||
expect(page).to have_css "img.moderator-avatar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can not comment as an administrator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as administrator"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Administrators" do
|
describe "Administrators" do
|
||||||
context "comment as administrator" do
|
context "comment as administrator" do
|
||||||
scenario "can create comment" do
|
|
||||||
admin = create(:administrator)
|
|
||||||
|
|
||||||
login_as(admin.user)
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am your Admin!"
|
|
||||||
check "comment-as-administrator-budget_investment_#{investment.id}"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am your Admin!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "display administrator description on admin views" do
|
scenario "display administrator description on admin views" do
|
||||||
admin = create(:administrator, description: "user description")
|
admin = create(:administrator, description: "user description")
|
||||||
|
|
||||||
@@ -425,7 +20,7 @@ describe "Commenting Budget::Investments" do
|
|||||||
expect(page).to have_content "I am your Admin!"
|
expect(page).to have_content "I am your Admin!"
|
||||||
end
|
end
|
||||||
|
|
||||||
visit admin_budget_budget_investment_path(investment.budget, investment)
|
refresh
|
||||||
|
|
||||||
within "#comments" do
|
within "#comments" do
|
||||||
expect(page).to have_content "I am your Admin!"
|
expect(page).to have_content "I am your Admin!"
|
||||||
@@ -434,172 +29,6 @@ describe "Commenting Budget::Investments" do
|
|||||||
expect(page).to have_css "img.admin-avatar"
|
expect(page).to have_css "img.admin-avatar"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "display administrator id on public views" do
|
|
||||||
admin = create(:administrator, description: "user description")
|
|
||||||
|
|
||||||
login_as(admin.user)
|
|
||||||
visit admin_budget_budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am your Admin!"
|
|
||||||
check "comment-as-administrator-budget_investment_#{investment.id}"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am your Admin!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can create reply as an administrator" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
admin = create(:administrator, user: manuela)
|
|
||||||
comment = create(:comment, commentable: investment, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "Top of the world!"
|
|
||||||
check "comment-as-administrator-comment_#{comment.id}"
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "Top of the world!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "public users not see admin description" do
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
admin = create(:administrator, user: manuela)
|
|
||||||
comment = create(:comment,
|
|
||||||
commentable: investment,
|
|
||||||
user: manuela,
|
|
||||||
administrator_id: admin.id)
|
|
||||||
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content comment.body
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can not comment as a moderator", :admin do
|
|
||||||
visit budget_investment_path(investment.budget, investment)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as moderator"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Voting comments" do
|
|
||||||
let(:verified) { create(:user, verified_at: Time.current) }
|
|
||||||
let(:unverified) { create(:user) }
|
|
||||||
let(:budget) { create(:budget) }
|
|
||||||
let(:investment) { create(:budget_investment, budget: budget) }
|
|
||||||
let!(:comment) { create(:comment, commentable: investment) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
login_as(verified)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Show" do
|
|
||||||
create(:vote, voter: verified, votable: comment, vote_flag: true)
|
|
||||||
create(:vote, voter: unverified, votable: comment, vote_flag: false)
|
|
||||||
|
|
||||||
visit budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "2 votes"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Create" do
|
|
||||||
visit budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "1 vote"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Update" do
|
|
||||||
visit budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
click_button "I disagree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "1 vote"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Allow undoing votes" do
|
|
||||||
visit budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "No votes"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -57,112 +57,6 @@ describe "Internal valuation comments on Budget::Investments" do
|
|||||||
expect(page).to have_content("Valuator Valuation response")
|
expect(page).to have_content("Valuator Valuation response")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Collapsable comments" do
|
|
||||||
parent_comment = create(:comment, :valuation, author: valuator_user, body: "Main comment",
|
|
||||||
commentable: investment)
|
|
||||||
child_comment = create(:comment, :valuation, author: valuator_user, body: "First subcomment",
|
|
||||||
commentable: investment, parent: parent_comment)
|
|
||||||
grandchild_comment = create(:comment, :valuation, author: valuator_user,
|
|
||||||
parent: child_comment,
|
|
||||||
body: "Last child",
|
|
||||||
commentable: investment)
|
|
||||||
|
|
||||||
visit valuation_budget_budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 2)
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (show)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
expect(page).to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment", text: "Main comment" do
|
|
||||||
click_link text: "1 response (collapse)", match: :first
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 1)
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content child_comment.body
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Comment order" do
|
|
||||||
create(:comment, :valuation, commentable: investment,
|
|
||||||
author: valuator_user,
|
|
||||||
body: "Valuator Valuation",
|
|
||||||
created_at: Time.current - 1)
|
|
||||||
admin_valuation = create(:comment, :valuation, commentable: investment,
|
|
||||||
author: admin_user,
|
|
||||||
body: "Admin Valuation",
|
|
||||||
created_at: Time.current - 2)
|
|
||||||
|
|
||||||
visit valuation_budget_budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
expect(admin_valuation.body).to appear_before("Valuator Valuation")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Turns links into html links" do
|
|
||||||
create(:comment, :valuation, author: admin_user, commentable: investment,
|
|
||||||
body: "Check http://rubyonrails.org/")
|
|
||||||
|
|
||||||
visit valuation_budget_budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
within first(".comment") do
|
|
||||||
expect(page).to have_content("Check http://rubyonrails.org/")
|
|
||||||
expect(page).to have_link("http://rubyonrails.org/", href: "http://rubyonrails.org/")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:rel]).to eq("nofollow")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:target]).to be_blank
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Sanitizes comment body for security" do
|
|
||||||
comment_with_js = "<script>alert('hola')</script> <a href=\"javascript:alert('sorpresa!')\">" \
|
|
||||||
"click me<a/> http://www.url.com"
|
|
||||||
create(:comment, :valuation, author: admin_user, commentable: investment,
|
|
||||||
body: comment_with_js)
|
|
||||||
|
|
||||||
visit valuation_budget_budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
within first(".comment") do
|
|
||||||
expect(page).to have_content("click me http://www.url.com")
|
|
||||||
expect(page).to have_link("http://www.url.com", href: "http://www.url.com")
|
|
||||||
expect(page).not_to have_link("click me")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Paginated comments" do
|
|
||||||
per_page = 10
|
|
||||||
(per_page + 2).times do
|
|
||||||
create(:comment, :valuation, commentable: investment, author: valuator_user)
|
|
||||||
end
|
|
||||||
|
|
||||||
visit valuation_budget_budget_investment_path(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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Valuation comment creation" do
|
context "Valuation comment creation" do
|
||||||
@@ -186,14 +80,6 @@ describe "Internal valuation comments on Budget::Investments" do
|
|||||||
expect(page).not_to have_content("Have you thought about...?")
|
expect(page).not_to have_content("Have you thought about...?")
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Errors on create without comment text" do
|
|
||||||
visit valuation_budget_budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply to existing valuation" do
|
scenario "Reply to existing valuation" do
|
||||||
comment = create(:comment, :valuation, author: admin_user, commentable: investment)
|
comment = create(:comment, :valuation, author: admin_user, commentable: investment)
|
||||||
|
|
||||||
@@ -217,51 +103,6 @@ describe "Internal valuation comments on Budget::Investments" do
|
|||||||
expect(page).not_to have_content("It will be done next week.")
|
expect(page).not_to have_content("It will be done next week.")
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Reply update parent comment responses count" do
|
|
||||||
comment = create(:comment, :valuation, author: admin_user, commentable: investment)
|
|
||||||
|
|
||||||
login_as(valuator_user)
|
|
||||||
visit valuation_budget_budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply show parent comments responses when hidden" do
|
|
||||||
comment = create(:comment, :valuation, author: admin_user, commentable: investment)
|
|
||||||
create(:comment, :valuation, author: admin_user, commentable: investment, parent: comment)
|
|
||||||
|
|
||||||
login_as(valuator_user)
|
|
||||||
visit valuation_budget_budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("It will be done next week.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on reply without comment text" do
|
|
||||||
comment = create(:comment, :valuation, author: admin_user, commentable: investment)
|
|
||||||
|
|
||||||
visit valuation_budget_budget_investment_path(budget, investment)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
click_button "Publish reply"
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Multiple nested replies" do
|
scenario "Multiple nested replies" do
|
||||||
parent = create(:comment, :valuation, author: valuator_user, commentable: investment)
|
parent = create(:comment, :valuation, author: valuator_user, commentable: investment)
|
||||||
|
|
||||||
@@ -279,18 +120,6 @@ describe "Internal valuation comments on Budget::Investments" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Erasing a comment's author" do
|
|
||||||
comment = create(:comment, :valuation, author: valuator_user, commentable: investment,
|
|
||||||
body: "this should be visible")
|
|
||||||
comment.user.erase
|
|
||||||
|
|
||||||
visit valuation_budget_budget_investment_path(budget, investment)
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content("User deleted")
|
|
||||||
expect(page).to have_content("this should be visible")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Administrators" do
|
describe "Administrators" do
|
||||||
scenario "can create valuation comment as an administrator" do
|
scenario "can create valuation comment as an administrator" do
|
||||||
login_as(admin_user)
|
login_as(admin_user)
|
||||||
|
|||||||
@@ -1,579 +1,9 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe "Commenting legislation questions" do
|
describe "Commenting legislation annotations" do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
let(:annotation) { create(:legislation_annotation, author: user) }
|
let(:annotation) { create(:legislation_annotation, author: user) }
|
||||||
|
|
||||||
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
|
|
||||||
href = polymorphic_path(annotation)
|
|
||||||
parent_comment = create(:comment, commentable: annotation, body: "Parent")
|
|
||||||
create(:comment, commentable: annotation, parent: parent_comment, body: "First subcomment")
|
|
||||||
create(:comment, commentable: annotation, parent: parent_comment, body: "Last subcomment")
|
|
||||||
|
|
||||||
visit comment_path(parent_comment)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content "Parent"
|
|
||||||
expect(page).to have_content "First subcomment"
|
|
||||||
expect(page).to have_content "Last subcomment"
|
|
||||||
|
|
||||||
expect(page).to have_link "Go back to #{annotation.title}", href: href
|
|
||||||
|
|
||||||
within ".comment", text: "Parent" do
|
|
||||||
expect(page).to have_css ".comment", count: 2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Link to comment show" do
|
|
||||||
comment = create(:comment, commentable: annotation, user: user)
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_link comment.created_at.strftime("%Y-%m-%d %T")
|
|
||||||
click_link comment.created_at.strftime("%Y-%m-%d %T")
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_link "Go back to #{annotation.title}"
|
|
||||||
expect(page).to have_current_path(comment_path(comment))
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Collapsable comments" do
|
|
||||||
parent_comment = annotation.comments.first
|
|
||||||
child_comment = create(:comment,
|
|
||||||
body: "First subcomment",
|
|
||||||
commentable: annotation,
|
|
||||||
parent: parent_comment)
|
|
||||||
grandchild_comment = create(:comment,
|
|
||||||
body: "Last subcomment",
|
|
||||||
commentable: annotation,
|
|
||||||
parent: child_comment)
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 2)
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (show)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
expect(page).to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment", text: parent_comment.body do
|
|
||||||
click_link text: "1 response (collapse)", match: :first
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 1)
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content child_comment.body
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
end
|
|
||||||
|
|
||||||
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)
|
|
||||||
old_child = create(:comment,
|
|
||||||
commentable: annotation,
|
|
||||||
parent_id: new_root.id,
|
|
||||||
created_at: Time.current - 10)
|
|
||||||
new_child = create(:comment,
|
|
||||||
commentable: annotation,
|
|
||||||
parent_id: new_root.id,
|
|
||||||
created_at: Time.current)
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation, order: :most_voted)
|
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation, order: :newest)
|
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
|
||||||
expect(new_child.body).to appear_before(old_child.body)
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation, order: :oldest)
|
|
||||||
|
|
||||||
expect(old_root.body).to appear_before(new_root.body)
|
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Turns links into html links" do
|
|
||||||
annotation = create(:legislation_annotation, author: user)
|
|
||||||
annotation.comments << create(:comment, body: "Built with http://rubyonrails.org/")
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within all(".comment").first do
|
|
||||||
expect(page).to have_content "Built with http://rubyonrails.org/"
|
|
||||||
expect(page).to have_link("http://rubyonrails.org/", href: "http://rubyonrails.org/")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:rel]).to eq("nofollow")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:target]).to be_blank
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Sanitizes comment body for security" do
|
|
||||||
create(:comment, commentable: annotation,
|
|
||||||
body: "<script>alert('hola')</script> " \
|
|
||||||
"<a href=\"javascript:alert('sorpresa!')\">click me<a/> " \
|
|
||||||
"http://www.url.com")
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within all(".comment").first do
|
|
||||||
expect(page).to have_content "click me http://www.url.com"
|
|
||||||
expect(page).to have_link("http://www.url.com", href: "http://www.url.com")
|
|
||||||
expect(page).not_to have_link("click me")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
describe "Not logged user" do
|
|
||||||
scenario "can not see comments forms" do
|
|
||||||
create(:comment, commentable: annotation)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
expect(page).to have_content "You must sign in or sign up to leave a comment"
|
|
||||||
within("#comments") do
|
|
||||||
expect(page).not_to have_content "Write a comment"
|
|
||||||
expect(page).not_to have_content "Reply"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Create" do
|
|
||||||
login_as(user)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "Have you thought about...?"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "Have you thought about...?"
|
|
||||||
expect(page).to have_content "(2)"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on create" do
|
|
||||||
login_as(user)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Comments are disabled when the allegations phase is closed" do
|
|
||||||
process = create(:legislation_process,
|
|
||||||
allegations_start_date: 1.month.ago,
|
|
||||||
allegations_end_date: Date.yesterday)
|
|
||||||
|
|
||||||
version = create(:legislation_draft_version, process: process)
|
|
||||||
annotation = create(:legislation_annotation, draft_version: version, text: "One annotation")
|
|
||||||
|
|
||||||
login_as(user)
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "Comments are closed"
|
|
||||||
expect(page).not_to have_content "Leave your comment"
|
|
||||||
expect(page).not_to have_button "Publish comment"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
annotation = create(:legislation_annotation, author: citizen)
|
|
||||||
comment = annotation.comments.first
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "It will be done next week."
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply update parent comment responses count" do
|
|
||||||
manuela = create(:user, :level_two, username: "Manuela")
|
|
||||||
annotation = create(:legislation_annotation)
|
|
||||||
comment = annotation.comments.first
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply show parent comments responses when hidden" do
|
|
||||||
manuela = create(:user, :level_two, username: "Manuela")
|
|
||||||
annotation = create(:legislation_annotation)
|
|
||||||
comment = annotation.comments.first
|
|
||||||
create(:comment, commentable: annotation, parent: comment)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("It will be done next week.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on reply" do
|
|
||||||
comment = annotation.comments.first
|
|
||||||
|
|
||||||
login_as(user)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
click_button "Publish reply"
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "N replies" do
|
|
||||||
parent = create(:comment, commentable: annotation)
|
|
||||||
|
|
||||||
7.times do
|
|
||||||
create(:comment, commentable: annotation, parent: parent)
|
|
||||||
parent = parent.children.first
|
|
||||||
end
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Erasing a comment's author" do
|
|
||||||
annotation = create(:legislation_annotation)
|
|
||||||
comment = create(:comment, commentable: annotation, body: "this should be visible")
|
|
||||||
comment.user.erase
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content("User deleted")
|
|
||||||
expect(page).to have_content("this should be visible")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Submit button is disabled after clicking" do
|
|
||||||
annotation = create(:legislation_annotation)
|
|
||||||
login_as(user)
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "Testing submit button!"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
expect(page).to have_button "Publish comment", disabled: true
|
|
||||||
expect(page).to have_content "Testing submit button!"
|
|
||||||
expect(page).to have_button "Publish comment", disabled: false
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Moderators" do
|
|
||||||
scenario "can create comment as a moderator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am moderating!"
|
|
||||||
check "comment-as-moderator-legislation_annotation_#{annotation.id}"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am moderating!"
|
|
||||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
|
||||||
expect(page).to have_css "div.is-moderator"
|
|
||||||
expect(page).to have_css "img.moderator-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can create reply as a moderator" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
moderator = create(:moderator, user: manuela)
|
|
||||||
annotation = create(:legislation_annotation, author: citizen)
|
|
||||||
comment = annotation.comments.first
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "I am moderating!"
|
|
||||||
check "comment-as-moderator-comment_#{comment.id}"
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "I am moderating!"
|
|
||||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
|
||||||
expect(page).to have_css "div.is-moderator"
|
|
||||||
expect(page).to have_css "img.moderator-avatar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can not comment as an administrator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as administrator"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Administrators" do
|
|
||||||
scenario "can create comment as an administrator" do
|
|
||||||
admin = create(:administrator)
|
|
||||||
|
|
||||||
login_as(admin.user)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am your Admin!"
|
|
||||||
check "comment-as-administrator-legislation_annotation_#{annotation.id}"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am your Admin!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can create reply as an administrator" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
admin = create(:administrator, user: manuela)
|
|
||||||
annotation = create(:legislation_annotation, author: citizen)
|
|
||||||
comment = annotation.comments.first
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "Top of the world!"
|
|
||||||
check "comment-as-administrator-comment_#{comment.id}"
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "Top of the world!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can not comment as a moderator", :admin do
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as moderator"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Voting comments" do
|
|
||||||
let(:verified) { create(:user, verified_at: Time.current) }
|
|
||||||
let(:unverified) { create(:user) }
|
|
||||||
let(:annotation) { create(:legislation_annotation) }
|
|
||||||
let!(:comment) { create(:comment, commentable: annotation) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
login_as(verified)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Show" do
|
|
||||||
create(:vote, voter: verified, votable: comment, vote_flag: true)
|
|
||||||
create(:vote, voter: unverified, votable: comment, vote_flag: false)
|
|
||||||
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "2 votes"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Create" do
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "1 vote"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Update" do
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
click_button "I disagree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "1 vote"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Allow undoing votes" do
|
|
||||||
visit polymorphic_path(annotation)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
click_button "I agree"
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).not_to have_content "2"
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "No votes"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Merged comment threads" do
|
describe "Merged comment threads" do
|
||||||
let!(:draft_version) { create(:legislation_draft_version, :published) }
|
let!(:draft_version) { create(:legislation_draft_version, :published) }
|
||||||
let!(:annotation1) do
|
let!(:annotation1) do
|
||||||
|
|||||||
@@ -1,560 +0,0 @@
|
|||||||
require "rails_helper"
|
|
||||||
|
|
||||||
describe "Commenting legislation questions" do
|
|
||||||
let(:user) { create(:user, :level_two) }
|
|
||||||
let(:process) { create(:legislation_process, :in_debate_phase) }
|
|
||||||
let(:question) { create(:legislation_question, process: process) }
|
|
||||||
|
|
||||||
context "Concerns" do
|
|
||||||
it_behaves_like "notifiable in-app", :legislation_question
|
|
||||||
it_behaves_like "flaggable", :legislation_question_comment
|
|
||||||
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
|
|
||||||
href = legislation_process_question_path(question.process, question)
|
|
||||||
parent_comment = create(:comment, commentable: question, body: "Parent")
|
|
||||||
create(:comment, commentable: question, parent: parent_comment, body: "First subcomment")
|
|
||||||
create(:comment, commentable: question, parent: parent_comment, body: "Last subcomment")
|
|
||||||
|
|
||||||
visit comment_path(parent_comment)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content "Parent"
|
|
||||||
expect(page).to have_content "First subcomment"
|
|
||||||
expect(page).to have_content "Last subcomment"
|
|
||||||
|
|
||||||
expect(page).to have_link "Go back to #{question.title}", href: href
|
|
||||||
|
|
||||||
within ".comment", text: "Parent" do
|
|
||||||
expect(page).to have_css ".comment", count: 2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Link to comment show" do
|
|
||||||
comment = create(:comment, commentable: question, user: user)
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_link comment.created_at.strftime("%Y-%m-%d %T")
|
|
||||||
end
|
|
||||||
|
|
||||||
click_link comment.created_at.strftime("%Y-%m-%d %T")
|
|
||||||
|
|
||||||
expect(page).to have_link "Go back to #{question.title}"
|
|
||||||
expect(page).to have_current_path(comment_path(comment))
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Collapsable comments" do
|
|
||||||
parent_comment = create(:comment, body: "Main comment", commentable: question)
|
|
||||||
child_comment = create(:comment, body: "First subcomment", commentable: question, parent: parent_comment)
|
|
||||||
grandchild_comment = create(:comment,
|
|
||||||
body: "Last subcomment",
|
|
||||||
commentable: question,
|
|
||||||
parent: child_comment)
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 2)
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (show)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
expect(page).to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment", text: "Main comment" do
|
|
||||||
click_link text: "1 response (collapse)", match: :first
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 1)
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content child_comment.body
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
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)
|
|
||||||
old_child = create(:comment, commentable: question, parent_id: new_root.id, created_at: Time.current - 10)
|
|
||||||
new_child = create(:comment, commentable: question, parent_id: new_root.id, created_at: Time.current)
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question, order: :most_voted)
|
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question, order: :newest)
|
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
|
||||||
expect(new_child.body).to appear_before(old_child.body)
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question, order: :oldest)
|
|
||||||
|
|
||||||
expect(old_root.body).to appear_before(new_root.body)
|
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Turns links into html links" do
|
|
||||||
create(:comment, commentable: question, body: "Built with http://rubyonrails.org/")
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
within first(".comment") do
|
|
||||||
expect(page).to have_content "Built with http://rubyonrails.org/"
|
|
||||||
expect(page).to have_link("http://rubyonrails.org/", href: "http://rubyonrails.org/")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:rel]).to eq("nofollow")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:target]).to be_blank
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Sanitizes comment body for security" do
|
|
||||||
create(:comment, commentable: question,
|
|
||||||
body: "<script>alert('hola')</script> " \
|
|
||||||
"<a href=\"javascript:alert('sorpresa!')\">click me<a/> " \
|
|
||||||
"http://www.url.com")
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
within first(".comment") do
|
|
||||||
expect(page).to have_content "click me http://www.url.com"
|
|
||||||
expect(page).to have_link("http://www.url.com", href: "http://www.url.com")
|
|
||||||
expect(page).not_to have_link("click me")
|
|
||||||
end
|
|
||||||
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
|
|
||||||
|
|
||||||
describe "Not logged user" do
|
|
||||||
scenario "can not see comments forms" do
|
|
||||||
create(:comment, commentable: question)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
expect(page).to have_content "You must sign in or sign up to leave a comment"
|
|
||||||
within("#comments") do
|
|
||||||
expect(page).not_to have_content "Write a comment"
|
|
||||||
expect(page).not_to have_content "Reply"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Create" do
|
|
||||||
login_as(user)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
fill_in "Leave your answer", with: "Have you thought about...?"
|
|
||||||
click_button "Publish answer"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "Have you thought about...?"
|
|
||||||
expect(page).to have_content "(1)"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on create" do
|
|
||||||
login_as(user)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
click_button "Publish answer"
|
|
||||||
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Unverified user can't create comments" do
|
|
||||||
unverified_user = create(:user)
|
|
||||||
login_as(unverified_user)
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
expect(page).to have_content "To participate verify your account"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Can't create comments if debate phase is not open" do
|
|
||||||
process.update!(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day)
|
|
||||||
login_as(user)
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
expect(page).to have_content "Closed phase"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, :level_two, username: "Manuela")
|
|
||||||
comment = create(:comment, commentable: question, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your answer", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "It will be done next week."
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply update parent comment responses count" do
|
|
||||||
manuela = create(:user, :level_two, username: "Manuela")
|
|
||||||
comment = create(:comment, commentable: question)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your answer", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply show parent comments responses when hidden" do
|
|
||||||
manuela = create(:user, :level_two, username: "Manuela")
|
|
||||||
comment = create(:comment, commentable: question)
|
|
||||||
create(:comment, commentable: question, parent: comment)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your answer", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("It will be done next week.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on reply" do
|
|
||||||
comment = create(:comment, commentable: question, user: user)
|
|
||||||
|
|
||||||
login_as(user)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
click_button "Publish reply"
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "N replies" do
|
|
||||||
parent = create(:comment, commentable: question)
|
|
||||||
|
|
||||||
7.times do
|
|
||||||
create(:comment, commentable: question, parent: parent)
|
|
||||||
parent = parent.children.first
|
|
||||||
end
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Erasing a comment's author" do
|
|
||||||
comment = create(:comment, commentable: question, body: "this should be visible")
|
|
||||||
comment.user.erase
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content("User deleted")
|
|
||||||
expect(page).to have_content("this should be visible")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Submit button is disabled after clicking" do
|
|
||||||
login_as(user)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
fill_in "Leave your answer", with: "Testing submit button!"
|
|
||||||
click_button "Publish answer"
|
|
||||||
|
|
||||||
expect(page).to have_button "Publish answer", disabled: true
|
|
||||||
expect(page).to have_content "Testing submit button!"
|
|
||||||
expect(page).to have_button "Publish answer", disabled: false
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Moderators" do
|
|
||||||
scenario "can create comment as a moderator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
fill_in "Leave your answer", with: "I am moderating!"
|
|
||||||
check "comment-as-moderator-legislation_question_#{question.id}"
|
|
||||||
click_button "Publish answer"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am moderating!"
|
|
||||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
|
||||||
expect(page).to have_css "div.is-moderator"
|
|
||||||
expect(page).to have_css "img.moderator-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can create reply as a moderator" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
moderator = create(:moderator, user: manuela)
|
|
||||||
comment = create(:comment, commentable: question, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your answer", with: "I am moderating!"
|
|
||||||
check "comment-as-moderator-comment_#{comment.id}"
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "I am moderating!"
|
|
||||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
|
||||||
expect(page).to have_css "div.is-moderator"
|
|
||||||
expect(page).to have_css "img.moderator-avatar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can not comment as an administrator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as administrator"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Administrators" do
|
|
||||||
scenario "can create comment as an administrator" do
|
|
||||||
admin = create(:administrator)
|
|
||||||
|
|
||||||
login_as(admin.user)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
fill_in "Leave your answer", with: "I am your Admin!"
|
|
||||||
check "comment-as-administrator-legislation_question_#{question.id}"
|
|
||||||
click_button "Publish answer"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am your Admin!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can create reply as an administrator" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
admin = create(:administrator, user: manuela)
|
|
||||||
comment = create(:comment, commentable: question, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your answer", with: "Top of the world!"
|
|
||||||
check "comment-as-administrator-comment_#{comment.id}"
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "Top of the world!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can not comment as a moderator", :admin do
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as moderator"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Voting comments" do
|
|
||||||
let(:verified) { create(:user, verified_at: Time.current) }
|
|
||||||
let(:unverified) { create(:user) }
|
|
||||||
let(:question) { create(:legislation_question) }
|
|
||||||
let!(:comment) { create(:comment, commentable: question) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
login_as(verified)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Show" do
|
|
||||||
create(:vote, voter: verified, votable: comment, vote_flag: true)
|
|
||||||
create(:vote, voter: unverified, votable: comment, vote_flag: false)
|
|
||||||
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "2 votes"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Create" do
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "1 vote"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Update" do
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
click_button "I disagree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "1 vote"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Allow undoing votes" do
|
|
||||||
visit legislation_process_question_path(question.process, question)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
click_button "I agree"
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).not_to have_content "2"
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "No votes"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
#refactor specs and test as one more commmentable
|
|
||||||
@@ -1,522 +0,0 @@
|
|||||||
require "rails_helper"
|
|
||||||
|
|
||||||
describe "Commenting polls" do
|
|
||||||
let(:user) { 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
|
|
||||||
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: "Last subcomment")
|
|
||||||
|
|
||||||
visit comment_path(parent_comment)
|
|
||||||
|
|
||||||
expect(page).to have_css ".comment", count: 3
|
|
||||||
expect(page).to have_content "Parent"
|
|
||||||
expect(page).to have_content "First subcomment"
|
|
||||||
expect(page).to have_content "Last subcomment"
|
|
||||||
expect(page).to have_link "Go back to #{poll.name}", href: poll_path(poll)
|
|
||||||
|
|
||||||
within ".comment", text: "Parent" do
|
|
||||||
expect(page).to have_css ".comment", count: 2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Link to comment show" do
|
|
||||||
comment = create(:comment, commentable: poll, user: user)
|
|
||||||
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_link comment.created_at.strftime("%Y-%m-%d %T")
|
|
||||||
end
|
|
||||||
|
|
||||||
click_link comment.created_at.strftime("%Y-%m-%d %T")
|
|
||||||
|
|
||||||
expect(page).to have_link "Go back to #{poll.title}"
|
|
||||||
expect(page).to have_current_path(comment_path(comment))
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Collapsable comments" do
|
|
||||||
parent_comment = create(:comment, body: "Main comment", commentable: poll)
|
|
||||||
child_comment = create(:comment, body: "First subcomment", commentable: poll, parent: parent_comment)
|
|
||||||
grandchild_comment = create(:comment, body: "Last subcomment", commentable: poll, parent: child_comment)
|
|
||||||
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 2)
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (show)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
expect(page).to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment", text: "Main comment" do
|
|
||||||
click_link text: "1 response (collapse)", match: :first
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 1)
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content child_comment.body
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
end
|
|
||||||
|
|
||||||
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)
|
|
||||||
old_child = create(:comment, commentable: poll, parent_id: new_root.id, created_at: Time.current - 10)
|
|
||||||
new_child = create(:comment, commentable: poll, parent_id: new_root.id, created_at: Time.current)
|
|
||||||
|
|
||||||
visit poll_path(poll, order: :most_voted)
|
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
|
||||||
|
|
||||||
visit poll_path(poll, order: :newest)
|
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
|
||||||
expect(new_child.body).to appear_before(old_child.body)
|
|
||||||
|
|
||||||
visit poll_path(poll, order: :oldest)
|
|
||||||
|
|
||||||
expect(old_root.body).to appear_before(new_root.body)
|
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Turns links into html links" do
|
|
||||||
create(:comment, commentable: poll, body: "Built with http://rubyonrails.org/")
|
|
||||||
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
within first(".comment") do
|
|
||||||
expect(page).to have_content "Built with http://rubyonrails.org/"
|
|
||||||
expect(page).to have_link("http://rubyonrails.org/", href: "http://rubyonrails.org/")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:rel]).to eq("nofollow")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:target]).to be_blank
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Sanitizes comment body for security" do
|
|
||||||
create(:comment, commentable: poll,
|
|
||||||
body: "<script>alert('hola')</script> " \
|
|
||||||
"<a href=\"javascript:alert('sorpresa!')\">click me<a/> " \
|
|
||||||
"http://www.url.com")
|
|
||||||
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
within first(".comment") do
|
|
||||||
expect(page).to have_content "click me http://www.url.com"
|
|
||||||
expect(page).to have_link("http://www.url.com", href: "http://www.url.com")
|
|
||||||
expect(page).not_to have_link("click me")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
describe "Not logged user" do
|
|
||||||
scenario "can not see comments forms" do
|
|
||||||
create(:comment, commentable: poll)
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
expect(page).to have_content "You must sign in or sign up to leave a comment"
|
|
||||||
within("#comments") do
|
|
||||||
expect(page).not_to have_content "Write a comment"
|
|
||||||
expect(page).not_to have_content "Reply"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Create" do
|
|
||||||
login_as(user)
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "Have you thought about...?"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "Have you thought about...?"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#tab-comments-label" do
|
|
||||||
expect(page).to have_content "Comments (1)"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on create" do
|
|
||||||
login_as(user)
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
comment = create(:comment, commentable: poll, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "It will be done next week."
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply update parent comment responses count" do
|
|
||||||
comment = create(:comment, commentable: poll)
|
|
||||||
|
|
||||||
login_as(create(:user))
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply show parent comments responses when hidden" do
|
|
||||||
comment = create(:comment, commentable: poll)
|
|
||||||
create(:comment, commentable: poll, parent: comment)
|
|
||||||
|
|
||||||
login_as(create(:user))
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("It will be done next week.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on reply" do
|
|
||||||
comment = create(:comment, commentable: poll, user: user)
|
|
||||||
|
|
||||||
login_as(user)
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
click_button "Publish reply"
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "N replies" do
|
|
||||||
parent = create(:comment, commentable: poll)
|
|
||||||
|
|
||||||
7.times do
|
|
||||||
create(:comment, commentable: poll, parent: parent)
|
|
||||||
parent = parent.children.first
|
|
||||||
end
|
|
||||||
|
|
||||||
visit poll_path(poll)
|
|
||||||
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Erasing a comment's author" do
|
|
||||||
poll = create(:poll)
|
|
||||||
comment = create(:comment, commentable: poll, body: "this should be visible")
|
|
||||||
comment.user.erase
|
|
||||||
|
|
||||||
visit poll_path(poll)
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content("User deleted")
|
|
||||||
expect(page).to have_content("this should be visible")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Moderators" do
|
|
||||||
scenario "can create comment as a moderator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am moderating!"
|
|
||||||
check "comment-as-moderator-poll_#{poll.id}"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am moderating!"
|
|
||||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
|
||||||
expect(page).to have_css "div.is-moderator"
|
|
||||||
expect(page).to have_css "img.moderator-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can create reply as a moderator" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
moderator = create(:moderator, user: manuela)
|
|
||||||
comment = create(:comment, commentable: poll, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "I am moderating!"
|
|
||||||
check "comment-as-moderator-comment_#{comment.id}"
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "I am moderating!"
|
|
||||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
|
||||||
expect(page).to have_css "div.is-moderator"
|
|
||||||
expect(page).to have_css "img.moderator-avatar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can not comment as an administrator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as administrator"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Administrators" do
|
|
||||||
scenario "can create comment as an administrator" do
|
|
||||||
admin = create(:administrator)
|
|
||||||
|
|
||||||
login_as(admin.user)
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am your Admin!"
|
|
||||||
check "comment-as-administrator-poll_#{poll.id}"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am your Admin!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can create reply as an administrator" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
admin = create(:administrator, user: manuela)
|
|
||||||
comment = create(:comment, commentable: poll, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "Top of the world!"
|
|
||||||
check "comment-as-administrator-comment_#{comment.id}"
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "Top of the world!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can not comment as a moderator", :admin do
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as moderator"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Voting comments" do
|
|
||||||
let(:verified) { create(:user, verified_at: Time.current) }
|
|
||||||
let(:unverified) { create(:user) }
|
|
||||||
let(:poll) { create(:poll) }
|
|
||||||
let!(:comment) { create(:comment, commentable: poll) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
login_as(verified)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Show" do
|
|
||||||
create(:vote, voter: verified, votable: comment, vote_flag: true)
|
|
||||||
create(:vote, voter: unverified, votable: comment, vote_flag: false)
|
|
||||||
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "2 votes"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Create" do
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "1 vote"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Update" do
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
click_button "I disagree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "1 vote"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Allow undoing votes" do
|
|
||||||
visit poll_path(poll)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "No votes"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,527 +0,0 @@
|
|||||||
require "rails_helper"
|
|
||||||
|
|
||||||
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) }
|
|
||||||
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
|
|
||||||
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: "Last subcomment")
|
|
||||||
|
|
||||||
visit comment_path(parent_comment)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content "Parent"
|
|
||||||
expect(page).to have_content "First subcomment"
|
|
||||||
expect(page).to have_content "Last subcomment"
|
|
||||||
expect(page).to have_link "Go back to #{proposal.title}", href: proposal_path(proposal)
|
|
||||||
|
|
||||||
within ".comment", text: "Parent" do
|
|
||||||
expect(page).to have_css ".comment", count: 2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Link to comment show" do
|
|
||||||
comment = create(:comment, commentable: proposal, user: user)
|
|
||||||
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_link comment.created_at.strftime("%Y-%m-%d %T")
|
|
||||||
end
|
|
||||||
|
|
||||||
click_link comment.created_at.strftime("%Y-%m-%d %T")
|
|
||||||
|
|
||||||
expect(page).to have_link "Go back to #{proposal.title}"
|
|
||||||
expect(page).to have_current_path(comment_path(comment))
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Collapsable comments" do
|
|
||||||
parent_comment = create(:comment, body: "Main comment", commentable: proposal)
|
|
||||||
child_comment = create(:comment, body: "First subcomment", commentable: proposal, parent: parent_comment)
|
|
||||||
grandchild_comment = create(:comment,
|
|
||||||
body: "Last subcomment",
|
|
||||||
commentable: proposal,
|
|
||||||
parent: child_comment)
|
|
||||||
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 2)
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment .comment", text: "First subcomment" do
|
|
||||||
click_link text: "1 response (show)"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
|
||||||
expect(page).to have_content grandchild_comment.body
|
|
||||||
|
|
||||||
within ".comment", text: "Main comment" do
|
|
||||||
click_link text: "1 response (collapse)", match: :first
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 1)
|
|
||||||
expect(page).to have_content("1 response (show)")
|
|
||||||
expect(page).not_to have_content child_comment.body
|
|
||||||
expect(page).not_to have_content grandchild_comment.body
|
|
||||||
end
|
|
||||||
|
|
||||||
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)
|
|
||||||
old_child = create(:comment, commentable: proposal, parent_id: new_root.id, created_at: Time.current - 10)
|
|
||||||
new_child = create(:comment, commentable: proposal, parent_id: new_root.id, created_at: Time.current)
|
|
||||||
|
|
||||||
visit proposal_path(proposal, order: :most_voted)
|
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
|
||||||
|
|
||||||
visit proposal_path(proposal, order: :newest)
|
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
|
||||||
expect(new_child.body).to appear_before(old_child.body)
|
|
||||||
|
|
||||||
visit proposal_path(proposal, order: :oldest)
|
|
||||||
|
|
||||||
expect(old_root.body).to appear_before(new_root.body)
|
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Turns links into html links" do
|
|
||||||
create(:comment, commentable: proposal, body: "Built with http://rubyonrails.org/")
|
|
||||||
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
within first(".comment") do
|
|
||||||
expect(page).to have_content "Built with http://rubyonrails.org/"
|
|
||||||
expect(page).to have_link("http://rubyonrails.org/", href: "http://rubyonrails.org/")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:rel]).to eq("nofollow")
|
|
||||||
expect(find_link("http://rubyonrails.org/")[:target]).to be_blank
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Sanitizes comment body for security" do
|
|
||||||
create(:comment, commentable: proposal,
|
|
||||||
body: "<script>alert('hola')</script> " \
|
|
||||||
"<a href=\"javascript:alert('sorpresa!')\">click me<a/> " \
|
|
||||||
"http://www.url.com")
|
|
||||||
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
within first(".comment") do
|
|
||||||
expect(page).to have_content "click me http://www.url.com"
|
|
||||||
expect(page).to have_link("http://www.url.com", href: "http://www.url.com")
|
|
||||||
expect(page).not_to have_link("click me")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
describe "Not logged user" do
|
|
||||||
scenario "can not see comments forms" do
|
|
||||||
create(:comment, commentable: proposal)
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
expect(page).to have_content "You must sign in or sign up to leave a comment"
|
|
||||||
within("#comments") do
|
|
||||||
expect(page).not_to have_content "Write a comment"
|
|
||||||
expect(page).not_to have_content "Reply"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Create" do
|
|
||||||
login_as(user)
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "Have you thought about...?"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "Have you thought about...?"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#tab-comments-label" do
|
|
||||||
expect(page).to have_content "Comments (1)"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on create" do
|
|
||||||
login_as(user)
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
comment = create(:comment, commentable: proposal, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "It will be done next week."
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply update parent comment responses count" do
|
|
||||||
comment = create(:comment, commentable: proposal)
|
|
||||||
|
|
||||||
login_as(create(:user))
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Reply show parent comments responses when hidden" do
|
|
||||||
comment = create(:comment, commentable: proposal)
|
|
||||||
create(:comment, commentable: proposal, parent: comment)
|
|
||||||
|
|
||||||
login_as(create(:user))
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
|
||||||
click_link text: "1 response (collapse)"
|
|
||||||
click_link "Reply"
|
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
|
||||||
click_button "Publish reply"
|
|
||||||
|
|
||||||
expect(page).to have_content("It will be done next week.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on reply" do
|
|
||||||
comment = create(:comment, commentable: proposal, user: user)
|
|
||||||
|
|
||||||
login_as(user)
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
click_button "Publish reply"
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "N replies" do
|
|
||||||
parent = create(:comment, commentable: proposal)
|
|
||||||
|
|
||||||
7.times do
|
|
||||||
create(:comment, commentable: proposal, parent: parent)
|
|
||||||
parent = parent.children.first
|
|
||||||
end
|
|
||||||
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Erasing a comment's author" do
|
|
||||||
proposal = create(:proposal)
|
|
||||||
comment = create(:comment, commentable: proposal, body: "this should be visible")
|
|
||||||
comment.user.erase
|
|
||||||
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content("User deleted")
|
|
||||||
expect(page).to have_content("this should be visible")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Moderators" do
|
|
||||||
scenario "can create comment as a moderator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am moderating!"
|
|
||||||
check "comment-as-moderator-proposal_#{proposal.id}"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am moderating!"
|
|
||||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
|
||||||
expect(page).to have_css "div.is-moderator"
|
|
||||||
expect(page).to have_css "img.moderator-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can create reply as a moderator" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
moderator = create(:moderator, user: manuela)
|
|
||||||
comment = create(:comment, commentable: proposal, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "I am moderating!"
|
|
||||||
check "comment-as-moderator-comment_#{comment.id}"
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "I am moderating!"
|
|
||||||
expect(page).to have_content "Moderator ##{moderator.id}"
|
|
||||||
expect(page).to have_css "div.is-moderator"
|
|
||||||
expect(page).to have_css "img.moderator-avatar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can not comment as an administrator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as administrator"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Administrators" do
|
|
||||||
scenario "can create comment as an administrator" do
|
|
||||||
admin = create(:administrator)
|
|
||||||
|
|
||||||
login_as(admin.user)
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am your Admin!"
|
|
||||||
check "comment-as-administrator-proposal_#{proposal.id}"
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
within "#comments" do
|
|
||||||
expect(page).to have_content "I am your Admin!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can create reply as an administrator" do
|
|
||||||
citizen = create(:user, username: "Ana")
|
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
admin = create(:administrator, user: manuela)
|
|
||||||
comment = create(:comment, commentable: proposal, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
click_link "Reply"
|
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
|
||||||
fill_in "Leave your comment", with: "Top of the world!"
|
|
||||||
check "comment-as-administrator-comment_#{comment.id}"
|
|
||||||
click_button "Publish reply"
|
|
||||||
end
|
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
expect(page).to have_content "Top of the world!"
|
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
|
||||||
expect(page).to have_css "div.is-admin"
|
|
||||||
expect(page).to have_css "img.admin-avatar"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "can not comment as a moderator", :admin do
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as moderator"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Voting comments" do
|
|
||||||
let(:verified) { create(:user, verified_at: Time.current) }
|
|
||||||
let(:unverified) { create(:user) }
|
|
||||||
let(:proposal) { create(:proposal) }
|
|
||||||
let!(:comment) { create(:comment, commentable: proposal) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
login_as(verified)
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Show" do
|
|
||||||
create(:vote, voter: verified, votable: comment, vote_flag: true)
|
|
||||||
create(:vote, voter: unverified, votable: comment, vote_flag: false)
|
|
||||||
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "2 votes"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Create" do
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "1 vote"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Update" do
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
click_button "I disagree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "1 vote"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Allow undoing votes" do
|
|
||||||
visit proposal_path(proposal)
|
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "1"
|
|
||||||
end
|
|
||||||
|
|
||||||
click_button "I agree"
|
|
||||||
|
|
||||||
within(".in-favor") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
within(".against") do
|
|
||||||
expect(page).to have_content "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(page).to have_content "No votes"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,30 +1,94 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe "Commenting debates" do
|
describe "Comments" do
|
||||||
let(:user) { create(:user) }
|
factories = [
|
||||||
let(:debate) { create(:debate) }
|
:budget_investment,
|
||||||
|
:debate,
|
||||||
|
:legislation_annotation,
|
||||||
|
:legislation_question,
|
||||||
|
:poll_with_author,
|
||||||
|
:proposal,
|
||||||
|
:topic_with_community,
|
||||||
|
:topic_with_investment_community
|
||||||
|
]
|
||||||
|
|
||||||
it_behaves_like "flaggable", :debate_comment
|
let(:factory) { factories.sample }
|
||||||
|
let(:resource) { create(factory) }
|
||||||
|
let(:user) do
|
||||||
|
if factory == :legislation_question
|
||||||
|
create(:user, :level_two)
|
||||||
|
else
|
||||||
|
create(:user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
let(:fill_text) do
|
||||||
|
if factory == :legislation_question
|
||||||
|
"Leave your answer"
|
||||||
|
else
|
||||||
|
"Leave your comment"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
let(:button_text) do
|
||||||
|
if factory == :legislation_question
|
||||||
|
"Publish answer"
|
||||||
|
else
|
||||||
|
"Publish comment"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Index" do
|
it_behaves_like "flaggable", :"#{(factories - [:poll_with_author]).sample}_comment"
|
||||||
3.times { create(:comment, commentable: debate) }
|
|
||||||
comment = Comment.includes(:user).last
|
|
||||||
|
|
||||||
visit debate_path(debate)
|
describe "Index" do
|
||||||
|
context "Budget Investments" do
|
||||||
|
let(:investment) { create(:budget_investment) }
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
scenario "render comments" do
|
||||||
|
not_valuations = 3.times.map { create(:comment, commentable: investment) }
|
||||||
|
create(:comment, :valuation, commentable: investment, subject: "Not viable")
|
||||||
|
|
||||||
within first(".comment") do
|
visit budget_investment_path(investment.budget, investment)
|
||||||
expect(page).to have_content comment.user.name
|
|
||||||
expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
|
expect(page).to have_css(".comment", count: 3)
|
||||||
expect(page).to have_content comment.body
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Show" do
|
scenario "Show" do
|
||||||
parent_comment = create(:comment, commentable: debate, body: "Parent")
|
parent_comment = create(:comment, commentable: resource, body: "Parent")
|
||||||
create(:comment, commentable: debate, parent: parent_comment, body: "First subcomment")
|
create(:comment, commentable: resource, parent: parent_comment, body: "First subcomment")
|
||||||
create(:comment, commentable: debate, parent: parent_comment, body: "Last subcomment")
|
create(:comment, commentable: resource, parent: parent_comment, body: "Last subcomment")
|
||||||
|
|
||||||
visit comment_path(parent_comment)
|
visit comment_path(parent_comment)
|
||||||
|
|
||||||
@@ -33,7 +97,8 @@ describe "Commenting debates" do
|
|||||||
expect(page).to have_content "First subcomment"
|
expect(page).to have_content "First subcomment"
|
||||||
expect(page).to have_content "Last subcomment"
|
expect(page).to have_content "Last subcomment"
|
||||||
|
|
||||||
expect(page).to have_link "Go back to #{debate.title}", href: debate_path(debate)
|
expect(page).to have_link "Go back to #{resource.title}",
|
||||||
|
href: polymorphic_path(resource)
|
||||||
|
|
||||||
within ".comment", text: "Parent" do
|
within ".comment", text: "Parent" do
|
||||||
expect(page).to have_css ".comment", count: 2
|
expect(page).to have_css ".comment", count: 2
|
||||||
@@ -41,26 +106,34 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Link to comment show" do
|
scenario "Link to comment show" do
|
||||||
comment = create(:comment, commentable: debate, user: user)
|
comment = create(:comment, commentable: resource, user: user)
|
||||||
|
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within "#comment_#{comment.id}" do
|
within "#comment_#{comment.id}" do
|
||||||
expect(page).to have_link comment.created_at.strftime("%Y-%m-%d %T")
|
click_link comment.created_at.strftime("%Y-%m-%d %T")
|
||||||
end
|
end
|
||||||
|
|
||||||
click_link comment.created_at.strftime("%Y-%m-%d %T")
|
expect(page).to have_link "Go back to #{resource.title}"
|
||||||
|
|
||||||
expect(page).to have_link "Go back to #{debate.title}"
|
|
||||||
expect(page).to have_current_path(comment_path(comment))
|
expect(page).to have_current_path(comment_path(comment))
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Collapsable comments" do
|
scenario "Collapsable comments" do
|
||||||
parent_comment = create(:comment, body: "Main comment", commentable: debate)
|
if factory == :legislation_annotation
|
||||||
child_comment = create(:comment, body: "First subcomment", commentable: debate, parent: parent_comment)
|
parent_comment = resource.comments.first
|
||||||
grandchild_comment = create(:comment, body: "Last subcomment", commentable: debate, parent: child_comment)
|
else
|
||||||
|
parent_comment = create(:comment, body: "Main comment", commentable: resource)
|
||||||
|
end
|
||||||
|
child_comment = create(:comment,
|
||||||
|
body: "First subcomment",
|
||||||
|
commentable: resource,
|
||||||
|
parent: parent_comment)
|
||||||
|
grandchild_comment = create(:comment,
|
||||||
|
body: "Last subcomment",
|
||||||
|
commentable: resource,
|
||||||
|
parent: child_comment)
|
||||||
|
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 3)
|
expect(page).to have_css(".comment", count: 3)
|
||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
expect(page).to have_content("1 response (collapse)", count: 2)
|
||||||
@@ -82,7 +155,7 @@ describe "Commenting debates" do
|
|||||||
expect(page).to have_content("1 response (collapse)", count: 2)
|
expect(page).to have_content("1 response (collapse)", count: 2)
|
||||||
expect(page).to have_content grandchild_comment.body
|
expect(page).to have_content grandchild_comment.body
|
||||||
|
|
||||||
within ".comment", text: "Main comment" do
|
within ".comment", text: parent_comment.body do
|
||||||
click_link text: "1 response (collapse)", match: :first
|
click_link text: "1 response (collapse)", match: :first
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -93,14 +166,14 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "can collapse comments after adding a reply" do
|
scenario "can collapse comments after adding a reply" do
|
||||||
create(:comment, body: "Main comment", commentable: debate)
|
create(:comment, body: "Main comment", commentable: resource)
|
||||||
|
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within ".comment", text: "Main comment" do
|
within ".comment", text: "Main comment" do
|
||||||
first(:link, "Reply").click
|
first(:link, "Reply").click
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
fill_in fill_text, with: "It will be done next week."
|
||||||
click_button "Publish reply"
|
click_button "Publish reply"
|
||||||
|
|
||||||
expect(page).to have_content("It will be done next week.")
|
expect(page).to have_content("It will be done next week.")
|
||||||
@@ -111,15 +184,29 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Not logged user" do
|
||||||
|
scenario "can not see comments forms" do
|
||||||
|
create(:comment, commentable: resource)
|
||||||
|
|
||||||
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
|
expect(page).to have_content "You must sign in or sign up to leave a comment"
|
||||||
|
within("#comments") do
|
||||||
|
expect(page).not_to have_content fill_text
|
||||||
|
expect(page).not_to have_content "Reply"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Comment order" do
|
scenario "Comment order" do
|
||||||
c1 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 100,
|
c1 = create(:comment, :with_confidence_score, commentable: resource, cached_votes_up: 100,
|
||||||
cached_votes_total: 120, created_at: Time.current - 2)
|
cached_votes_total: 120, created_at: Time.current - 2)
|
||||||
c2 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 10,
|
c2 = create(:comment, :with_confidence_score, commentable: resource, cached_votes_up: 10,
|
||||||
cached_votes_total: 12, created_at: Time.current - 1)
|
cached_votes_total: 12, created_at: Time.current - 1)
|
||||||
c3 = create(:comment, :with_confidence_score, commentable: debate, cached_votes_up: 1,
|
c3 = create(:comment, :with_confidence_score, commentable: resource, cached_votes_up: 1,
|
||||||
cached_votes_total: 2, created_at: Time.current)
|
cached_votes_total: 2, created_at: Time.current)
|
||||||
|
|
||||||
visit debate_path(debate, order: :most_voted)
|
visit polymorphic_path(resource, order: :most_voted)
|
||||||
|
|
||||||
expect(c1.body).to appear_before(c2.body)
|
expect(c1.body).to appear_before(c2.body)
|
||||||
expect(c2.body).to appear_before(c3.body)
|
expect(c2.body).to appear_before(c3.body)
|
||||||
@@ -140,31 +227,34 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do
|
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)
|
old_root = create(:comment, commentable: resource, created_at: Time.current - 10)
|
||||||
new_root = create(:comment, commentable: debate, created_at: Time.current)
|
new_root = create(:comment, commentable: resource, created_at: Time.current)
|
||||||
old_child = create(:comment, commentable: debate, parent_id: new_root.id, created_at: Time.current - 10)
|
old_child = create(:comment,
|
||||||
new_child = create(:comment, commentable: debate, parent_id: new_root.id, created_at: Time.current)
|
commentable: resource,
|
||||||
|
parent_id: new_root.id,
|
||||||
|
created_at: Time.current - 10)
|
||||||
|
new_child = create(:comment, commentable: resource, parent_id: new_root.id, created_at: Time.current)
|
||||||
|
|
||||||
visit debate_path(debate, order: :most_voted)
|
visit polymorphic_path(resource, order: :most_voted)
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
expect(new_root.body).to appear_before(old_root.body)
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
expect(old_child.body).to appear_before(new_child.body)
|
||||||
|
|
||||||
visit debate_path(debate, order: :newest)
|
visit polymorphic_path(resource, order: :newest)
|
||||||
|
|
||||||
expect(new_root.body).to appear_before(old_root.body)
|
expect(new_root.body).to appear_before(old_root.body)
|
||||||
expect(new_child.body).to appear_before(old_child.body)
|
expect(new_child.body).to appear_before(old_child.body)
|
||||||
|
|
||||||
visit debate_path(debate, order: :oldest)
|
visit polymorphic_path(resource, order: :oldest)
|
||||||
|
|
||||||
expect(old_root.body).to appear_before(new_root.body)
|
expect(old_root.body).to appear_before(new_root.body)
|
||||||
expect(old_child.body).to appear_before(new_child.body)
|
expect(old_child.body).to appear_before(new_child.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Turns links into html links" do
|
scenario "Turns links into html links" do
|
||||||
create(:comment, commentable: debate, body: "Built with http://rubyonrails.org/")
|
create(:comment, commentable: resource, body: "Built with http://rubyonrails.org/")
|
||||||
|
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within first(".comment") do
|
within first(".comment") do
|
||||||
expect(page).to have_content "Built with http://rubyonrails.org/"
|
expect(page).to have_content "Built with http://rubyonrails.org/"
|
||||||
@@ -175,12 +265,12 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Sanitizes comment body for security" do
|
scenario "Sanitizes comment body for security" do
|
||||||
create(:comment, commentable: debate,
|
create(:comment, commentable: resource,
|
||||||
body: "<script>alert('hola')</script> " \
|
body: "<script>alert('hola')</script> " \
|
||||||
"<a href=\"javascript:alert('sorpresa!')\">click me<a/> " \
|
"<a href=\"javascript:alert('sorpresa!')\">click me<a/> " \
|
||||||
"http://www.url.com")
|
"http://www.url.com")
|
||||||
|
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within first(".comment") do
|
within first(".comment") do
|
||||||
expect(page).to have_content "click me http://www.url.com"
|
expect(page).to have_content "click me http://www.url.com"
|
||||||
@@ -191,9 +281,9 @@ describe "Commenting debates" do
|
|||||||
|
|
||||||
scenario "Paginated comments" do
|
scenario "Paginated comments" do
|
||||||
per_page = 10
|
per_page = 10
|
||||||
(per_page + 2).times { create(:comment, commentable: debate) }
|
(per_page + 2).times { create(:comment, commentable: resource) }
|
||||||
|
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: per_page)
|
expect(page).to have_css(".comment", count: per_page)
|
||||||
within("ul.pagination") do
|
within("ul.pagination") do
|
||||||
@@ -203,51 +293,47 @@ describe "Commenting debates" do
|
|||||||
click_link "Next", exact: false
|
click_link "Next", exact: false
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_css(".comment", count: 2)
|
if factory == :legislation_annotation
|
||||||
expect(page).to have_current_path(/#comments/, url: true)
|
expect(page).to have_css(".comment", count: 3)
|
||||||
end
|
else
|
||||||
|
expect(page).to have_css(".comment", count: 2)
|
||||||
describe "Not logged user" do
|
|
||||||
scenario "can not see comments forms" do
|
|
||||||
create(:comment, commentable: debate)
|
|
||||||
visit debate_path(debate)
|
|
||||||
|
|
||||||
expect(page).to have_content "You must sign in or sign up to leave a comment"
|
|
||||||
within("#comments") do
|
|
||||||
expect(page).not_to have_content "Write a comment"
|
|
||||||
expect(page).not_to have_content "Reply"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
expect(page).to have_current_path(/#comments/, url: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Create" do
|
scenario "Create" do
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "Have you thought about...?"
|
fill_in fill_text, with: "Have you thought about...?"
|
||||||
click_button "Publish comment"
|
click_button button_text
|
||||||
|
|
||||||
|
if [:debate, :legislation_question].include?(factory)
|
||||||
|
within "#comments" do
|
||||||
|
expect(page).to have_content "(1)"
|
||||||
|
end
|
||||||
|
elsif factory == :legislation_annotation
|
||||||
|
within "#comments" do
|
||||||
|
expect(page).to have_content "Comments (2)"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
within "#tab-comments-label" do
|
||||||
|
expect(page).to have_content "Comments (1)"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
within "#comments" do
|
within "#comments" do
|
||||||
expect(page).to have_content "Have you thought about...?"
|
expect(page).to have_content "Have you thought about...?"
|
||||||
expect(page).to have_content "(1)"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Errors on create" do
|
|
||||||
login_as(user)
|
|
||||||
visit debate_path(debate)
|
|
||||||
|
|
||||||
click_button "Publish comment"
|
|
||||||
|
|
||||||
expect(page).to have_content "Can't be blank"
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "Hide" do
|
describe "Hide" do
|
||||||
scenario "Without replies" do
|
scenario "Without replies" do
|
||||||
create(:comment, commentable: debate, user: user, body: "This was a mistake")
|
create(:comment, commentable: resource, user: user, body: "This was a mistake")
|
||||||
|
admin = create(:administrator).user
|
||||||
|
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
|
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
|
||||||
within(".comment-body", text: "This was a mistake") { click_link "Delete comment" }
|
within(".comment-body", text: "This was a mistake") { click_link "Delete comment" }
|
||||||
@@ -256,13 +342,13 @@ describe "Commenting debates" do
|
|||||||
expect(page).not_to have_content "This was a mistake"
|
expect(page).not_to have_content "This was a mistake"
|
||||||
expect(page).not_to have_link "Delete comment"
|
expect(page).not_to have_link "Delete comment"
|
||||||
|
|
||||||
visit debate_path(debate)
|
refresh
|
||||||
|
|
||||||
expect(page).not_to have_content "This was a mistake"
|
expect(page).not_to have_content "This was a mistake"
|
||||||
expect(page).not_to have_link "Delete comment"
|
expect(page).not_to have_link "Delete comment"
|
||||||
|
|
||||||
logout
|
logout
|
||||||
login_as(create(:administrator).user)
|
login_as(admin)
|
||||||
|
|
||||||
visit admin_hidden_comments_path
|
visit admin_hidden_comments_path
|
||||||
|
|
||||||
@@ -270,11 +356,11 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "With replies" do
|
scenario "With replies" do
|
||||||
comment = create(:comment, commentable: debate, user: user, body: "Wrong comment")
|
comment = create(:comment, commentable: resource, user: user, body: "Wrong comment")
|
||||||
create(:comment, commentable: debate, parent: comment, body: "Right reply")
|
create(:comment, commentable: resource, parent: comment, body: "Right reply")
|
||||||
|
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
|
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
|
||||||
within(".comment-body", text: "Wrong comment") { click_link "Delete comment" }
|
within(".comment-body", text: "Wrong comment") { click_link "Delete comment" }
|
||||||
@@ -285,7 +371,7 @@ describe "Commenting debates" do
|
|||||||
expect(page).not_to have_content "Wrong comment"
|
expect(page).not_to have_content "Wrong comment"
|
||||||
end
|
end
|
||||||
|
|
||||||
visit debate_path(debate)
|
refresh
|
||||||
|
|
||||||
within "#comments > .comment-list > li", text: "Right reply" do
|
within "#comments > .comment-list > li", text: "Right reply" do
|
||||||
expect(page).to have_content "This comment has been deleted"
|
expect(page).to have_content "This comment has been deleted"
|
||||||
@@ -295,17 +381,17 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Reply" do
|
scenario "Reply" do
|
||||||
citizen = create(:user, username: "Ana")
|
comment = create(:comment, commentable: resource)
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
comment = create(:comment, commentable: debate, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
click_link "Reply"
|
within "#comment_#{comment.id}" do
|
||||||
|
click_link "Reply"
|
||||||
|
end
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
within "#js-comment-form-comment_#{comment.id}" do
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
fill_in fill_text, with: "It will be done next week."
|
||||||
click_button "Publish reply"
|
click_button "Publish reply"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -317,20 +403,20 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Reply to reply" do
|
scenario "Reply to reply" do
|
||||||
create(:comment, commentable: debate, body: "Any estimates?")
|
create(:comment, commentable: resource, body: "Any estimates?")
|
||||||
|
|
||||||
login_as(create(:user))
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within ".comment", text: "Any estimates?" do
|
within ".comment", text: "Any estimates?" do
|
||||||
click_link "Reply"
|
click_link "Reply"
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
fill_in fill_text, with: "It will be done next week."
|
||||||
click_button "Publish reply"
|
click_button "Publish reply"
|
||||||
end
|
end
|
||||||
|
|
||||||
within ".comment .comment", text: "It will be done next week" do
|
within ".comment .comment", text: "It will be done next week" do
|
||||||
click_link "Reply"
|
click_link "Reply"
|
||||||
fill_in "Leave your comment", with: "Probably if government approves."
|
fill_in fill_text, with: "Probably if government approves."
|
||||||
click_button "Publish reply"
|
click_button "Publish reply"
|
||||||
|
|
||||||
expect(page).not_to have_css ".comment-form"
|
expect(page).not_to have_css ".comment-form"
|
||||||
@@ -342,14 +428,14 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Reply update parent comment responses count" do
|
scenario "Reply update parent comment responses count" do
|
||||||
comment = create(:comment, commentable: debate)
|
comment = create(:comment, commentable: resource)
|
||||||
|
|
||||||
login_as(create(:user))
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
within ".comment", text: comment.body do
|
||||||
click_link "Reply"
|
click_link "Reply"
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
fill_in fill_text, with: "It will be done next week."
|
||||||
click_button "Publish reply"
|
click_button "Publish reply"
|
||||||
|
|
||||||
expect(page).to have_content("1 response (collapse)")
|
expect(page).to have_content("1 response (collapse)")
|
||||||
@@ -357,39 +443,32 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Reply show parent comments responses when hidden" do
|
scenario "Reply show parent comments responses when hidden" do
|
||||||
comment = create(:comment, commentable: debate)
|
comment = create(:comment, commentable: resource)
|
||||||
create(:comment, commentable: debate, parent: comment)
|
create(:comment, commentable: resource, parent: comment)
|
||||||
|
|
||||||
login_as(create(:user))
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within ".comment", text: comment.body do
|
within ".comment", text: comment.body do
|
||||||
click_link text: "1 response (collapse)"
|
click_link text: "1 response (collapse)"
|
||||||
click_link "Reply"
|
click_link "Reply"
|
||||||
fill_in "Leave your comment", with: "It will be done next week."
|
fill_in fill_text, with: "It will be done next week."
|
||||||
|
|
||||||
click_button "Publish reply"
|
click_button "Publish reply"
|
||||||
|
|
||||||
expect(page).to have_content("It will be done next week.")
|
expect(page).to have_content("It will be done next week.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Show comment when the author is hidden" do
|
|
||||||
create(:comment, body: "This is pointless", commentable: debate, author: create(:user, :hidden))
|
|
||||||
|
|
||||||
visit debate_path(debate)
|
|
||||||
|
|
||||||
within ".comment", text: "This is pointless" do
|
|
||||||
expect(page).to have_content "User deleted"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Errors on reply" do
|
scenario "Errors on reply" do
|
||||||
comment = create(:comment, commentable: debate, user: user)
|
comment = create(:comment, commentable: resource, user: user)
|
||||||
|
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
click_link "Reply"
|
within "#comment_#{comment.id}" do
|
||||||
|
click_link "Reply"
|
||||||
|
end
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
within "#js-comment-form-comment_#{comment.id}" do
|
||||||
click_button "Publish reply"
|
click_button "Publish reply"
|
||||||
@@ -398,52 +477,62 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "N replies" do
|
scenario "N replies" do
|
||||||
parent = create(:comment, commentable: debate)
|
parent = create(:comment, commentable: resource)
|
||||||
|
|
||||||
7.times do
|
7.times do
|
||||||
create(:comment, commentable: debate, parent: parent)
|
create(:comment, commentable: resource, parent: parent)
|
||||||
parent = parent.children.first
|
parent = parent.children.first
|
||||||
end
|
end
|
||||||
|
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
|
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Erasing a comment's author" do
|
scenario "Erasing a comment's author" do
|
||||||
debate = create(:debate)
|
comment = create(:comment, commentable: resource, body: "this should be visible")
|
||||||
comment = create(:comment, commentable: debate, body: "this should be visible")
|
|
||||||
comment.user.erase
|
comment.user.erase
|
||||||
|
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
within "#comment_#{comment.id}" do
|
|
||||||
|
within ".comment", text: "this should be visible" do
|
||||||
expect(page).to have_content("User deleted")
|
expect(page).to have_content("User deleted")
|
||||||
expect(page).to have_content("this should be visible")
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Show comment when the author is hidden" do
|
||||||
|
create(:comment, body: "This is pointless", commentable: resource, author: create(:user, :hidden))
|
||||||
|
|
||||||
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
|
within ".comment", text: "This is pointless" do
|
||||||
|
expect(page).to have_content "User deleted"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Submit button is disabled after clicking" do
|
scenario "Submit button is disabled after clicking" do
|
||||||
debate = create(:debate)
|
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "Testing submit button!"
|
fill_in fill_text, with: "Testing submit button!"
|
||||||
click_button "Publish comment"
|
click_button button_text
|
||||||
|
|
||||||
expect(page).to have_button "Publish comment", disabled: true
|
expect(page).to have_button button_text, disabled: true
|
||||||
expect(page).to have_content "Testing submit button!"
|
expect(page).to have_content "Testing submit button!"
|
||||||
expect(page).to have_button "Publish comment", disabled: false
|
expect(page).to have_button button_text, disabled: false
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Moderators" do
|
describe "Moderators" do
|
||||||
|
let(:moderator) { create(:moderator) }
|
||||||
|
before { login_as(moderator.user) }
|
||||||
|
|
||||||
scenario "can create comment as a moderator" do
|
scenario "can create comment as a moderator" do
|
||||||
moderator = create(:moderator)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
login_as(moderator.user)
|
expect(page).not_to have_content "Comment as administrator"
|
||||||
visit debate_path(debate)
|
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am moderating!"
|
fill_in fill_text, with: "I am moderating!"
|
||||||
check "comment-as-moderator-debate_#{debate.id}"
|
check "Comment as moderator"
|
||||||
click_button "Publish comment"
|
click_button button_text
|
||||||
|
|
||||||
within "#comments" do
|
within "#comments" do
|
||||||
expect(page).to have_content "I am moderating!"
|
expect(page).to have_content "I am moderating!"
|
||||||
@@ -454,19 +543,17 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "can create reply as a moderator" do
|
scenario "can create reply as a moderator" do
|
||||||
citizen = create(:user, username: "Ana")
|
comment = create(:comment, commentable: resource)
|
||||||
manuela = create(:user, username: "Manuela")
|
|
||||||
moderator = create(:moderator, user: manuela)
|
|
||||||
comment = create(:comment, commentable: debate, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
visit polymorphic_path(resource)
|
||||||
visit debate_path(debate)
|
|
||||||
|
|
||||||
click_link "Reply"
|
within "#comment_#{comment.id}" do
|
||||||
|
click_link "Reply"
|
||||||
|
end
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
within "#js-comment-form-comment_#{comment.id}" do
|
||||||
fill_in "Leave your comment", with: "I am moderating!"
|
fill_in fill_text, with: "I am moderating!"
|
||||||
check "comment-as-moderator-comment_#{comment.id}"
|
check "Comment as moderator"
|
||||||
click_button "Publish reply"
|
click_button "Publish reply"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -479,50 +566,44 @@ describe "Commenting debates" do
|
|||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "can not comment as an administrator" do
|
|
||||||
moderator = create(:moderator)
|
|
||||||
|
|
||||||
login_as(moderator.user)
|
|
||||||
visit debate_path(debate)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as administrator"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Administrators" do
|
describe "Administrators" do
|
||||||
scenario "can create comment as an administrator" do
|
scenario "can create comment" do
|
||||||
admin = create(:administrator)
|
admin = create(:administrator, description: "admin user")
|
||||||
|
|
||||||
login_as(admin.user)
|
login_as(admin.user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
fill_in "Leave your comment", with: "I am your Admin!"
|
expect(page).not_to have_content "Comment as moderator"
|
||||||
check "comment-as-administrator-debate_#{debate.id}"
|
|
||||||
click_button "Publish comment"
|
fill_in fill_text, with: "I am your Admin!"
|
||||||
|
check "Comment as admin"
|
||||||
|
click_button button_text
|
||||||
|
|
||||||
within "#comments" do
|
within "#comments" do
|
||||||
expect(page).to have_content "I am your Admin!"
|
expect(page).to have_content "I am your Admin!"
|
||||||
expect(page).to have_content "Administrator ##{admin.id}"
|
expect(page).to have_content "Administrator ##{admin.id}"
|
||||||
|
expect(page).not_to have_content "Administrator admin user"
|
||||||
expect(page).to have_css "div.is-admin"
|
expect(page).to have_css "div.is-admin"
|
||||||
expect(page).to have_css "img.admin-avatar"
|
expect(page).to have_css "img.admin-avatar"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "can create reply as an administrator" do
|
scenario "can create reply as an administrator" do
|
||||||
citizen = create(:user, username: "Ana")
|
admin = create(:administrator)
|
||||||
manuela = create(:user, username: "Manuela")
|
comment = create(:comment, commentable: resource)
|
||||||
admin = create(:administrator, user: manuela)
|
|
||||||
comment = create(:comment, commentable: debate, user: citizen)
|
|
||||||
|
|
||||||
login_as(manuela)
|
login_as(admin.user)
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
click_link "Reply"
|
within "#comment_#{comment.id}" do
|
||||||
|
click_link "Reply"
|
||||||
|
end
|
||||||
|
|
||||||
within "#js-comment-form-comment_#{comment.id}" do
|
within "#js-comment-form-comment_#{comment.id}" do
|
||||||
fill_in "Leave your comment", with: "Top of the world!"
|
fill_in fill_text, with: "Top of the world!"
|
||||||
check "comment-as-administrator-comment_#{comment.id}"
|
check "Comment as admin"
|
||||||
click_button "Publish reply"
|
click_button "Publish reply"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -535,19 +616,12 @@ describe "Commenting debates" do
|
|||||||
|
|
||||||
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "can not comment as a moderator", :admin do
|
|
||||||
visit debate_path(debate)
|
|
||||||
|
|
||||||
expect(page).not_to have_content "Comment as moderator"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Voting comments" do
|
describe "Voting comments" do
|
||||||
let(:verified) { create(:user, verified_at: Time.current) }
|
let(:verified) { create(:user, verified_at: Time.current) }
|
||||||
let(:unverified) { create(:user) }
|
let(:unverified) { create(:user) }
|
||||||
let(:debate) { create(:debate) }
|
let!(:comment) { create(:comment, commentable: resource) }
|
||||||
let!(:comment) { create(:comment, commentable: debate) }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
login_as(verified)
|
login_as(verified)
|
||||||
@@ -557,7 +631,7 @@ describe "Commenting debates" do
|
|||||||
create(:vote, voter: verified, votable: comment, vote_flag: true)
|
create(:vote, voter: verified, votable: comment, vote_flag: true)
|
||||||
create(:vote, voter: unverified, votable: comment, vote_flag: false)
|
create(:vote, voter: unverified, votable: comment, vote_flag: false)
|
||||||
|
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
within("#comment_#{comment.id}_votes") do
|
||||||
within(".in-favor") do
|
within(".in-favor") do
|
||||||
@@ -573,7 +647,7 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Create" do
|
scenario "Create" do
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
within("#comment_#{comment.id}_votes") do
|
||||||
click_button "I agree"
|
click_button "I agree"
|
||||||
@@ -591,7 +665,7 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Update" do
|
scenario "Update" do
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
within("#comment_#{comment.id}_votes") do
|
||||||
click_button "I agree"
|
click_button "I agree"
|
||||||
@@ -615,17 +689,18 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Allow undoing votes" do
|
scenario "Allow undoing votes" do
|
||||||
visit debate_path(debate)
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
within("#comment_#{comment.id}_votes") do
|
within("#comment_#{comment.id}_votes") do
|
||||||
click_button "I agree"
|
click_button "I agree"
|
||||||
|
|
||||||
within(".in-favor") do
|
within(".in-favor") do
|
||||||
expect(page).to have_content "1"
|
expect(page).to have_content "1"
|
||||||
end
|
end
|
||||||
|
|
||||||
click_button "I agree"
|
click_button "I agree"
|
||||||
|
|
||||||
within(".in-favor") do
|
within(".in-favor") do
|
||||||
expect(page).not_to have_content "2"
|
|
||||||
expect(page).to have_content "0"
|
expect(page).to have_content "0"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -637,4 +712,13 @@ describe "Commenting debates" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Errors on create" do
|
||||||
|
login_as(user)
|
||||||
|
visit polymorphic_path(resource)
|
||||||
|
|
||||||
|
click_button button_text
|
||||||
|
|
||||||
|
expect(page).to have_content "Can't be blank"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -2,6 +2,8 @@ require "rails_helper"
|
|||||||
|
|
||||||
describe "Legislation" do
|
describe "Legislation" do
|
||||||
context "process debate page" do
|
context "process debate page" do
|
||||||
|
it_behaves_like "notifiable in-app", :legislation_question
|
||||||
|
|
||||||
let(:process) do
|
let(:process) do
|
||||||
create(:legislation_process,
|
create(:legislation_process,
|
||||||
debate_start_date: Date.current - 3.days,
|
debate_start_date: Date.current - 3.days,
|
||||||
|
|||||||
Reference in New Issue
Block a user