diff --git a/app/components/comments/form_component.html.erb b/app/components/comments/form_component.html.erb
new file mode 100644
index 000000000..767dd15d4
--- /dev/null
+++ b/app/components/comments/form_component.html.erb
@@ -0,0 +1,46 @@
+<% cache cache_key do %>
+ <% if comments_closed_for_commentable?(commentable) %>
+
+
+ <%= comments_closed_text %>
+
+ <% elsif require_verified_resident_for_commentable?(commentable, current_user) %>
+
+
+ <%= sanitize(t("comments.verified_only", verify_account: link_to_verify_account)) %>
+
+ <% elsif !valuation || can?(:comment_valuation, commentable) %>
+ <% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
+
+ <% end %>
+<% end %>
diff --git a/app/components/comments/form_component.rb b/app/components/comments/form_component.rb
new file mode 100644
index 000000000..e690b770e
--- /dev/null
+++ b/app/components/comments/form_component.rb
@@ -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
diff --git a/app/components/shared/comments_component.html.erb b/app/components/shared/comments_component.html.erb
index fd6b3d8ed..864f9cce4 100644
--- a/app/components/shared/comments_component.html.erb
+++ b/app/components/shared/comments_component.html.erb
@@ -4,13 +4,13 @@
<% cache cache_key do %>
<% if current_user %>
- <%= render "comments/form", { commentable: record, parent_id: nil } %>
+ <%= render Comments::FormComponent.new(record, valuation: valuation) %>
<% else %>
<%= render "shared/login_to_comment" %>
<% end %>
<%= 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" } %>
<% end %>
diff --git a/app/components/shared/comments_component.rb b/app/components/shared/comments_component.rb
index f9c9a07ef..d94c8bd1c 100644
--- a/app/components/shared/comments_component.rb
+++ b/app/components/shared/comments_component.rb
@@ -1,10 +1,11 @@
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
- def initialize(record, comment_tree)
+ def initialize(record, comment_tree, valuation: false)
@record = record
@comment_tree = comment_tree
+ @valuation = valuation
end
private
diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb
index 1bf679bb4..866b1e1a4 100644
--- a/app/helpers/comments_helper.rb
+++ b/app/helpers/comments_helper.rb
@@ -1,12 +1,4 @@
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)
if commentable.class == Legislation::Question
t("legislation.questions.comments.form.leave_comment")
@@ -82,12 +74,4 @@ module CommentsHelper
def comments_closed_for_commentable?(commentable)
commentable.respond_to?(:comments_closed?) && commentable.comments_closed?
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
diff --git a/app/views/budgets/investments/show.html.erb b/app/views/budgets/investments/show.html.erb
index c44141cfb..a3eef5948 100644
--- a/app/views/budgets/investments/show.html.erb
+++ b/app/views/budgets/investments/show.html.erb
@@ -17,9 +17,7 @@
<%= render "milestones/milestones", milestoneable: @investment %>
diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb
index 542fa0d71..7b7a67c6e 100644
--- a/app/views/comments/_comment.html.erb
+++ b/app/views/comments/_comment.html.erb
@@ -99,9 +99,9 @@
<% end %>
<% if !valuation || can?(:comment_valuation, comment.commentable) %>
- <%= render "comments/form", { commentable: comment.commentable,
- parent_id: comment.id,
- valuation: valuation } %>
+ <%= render Comments::FormComponent.new(comment.commentable,
+ parent_id: comment.id,
+ valuation: valuation) %>
<% end %>
<% end %>
diff --git a/app/views/comments/_comment_tree.html.erb b/app/views/comments/_comment_tree.html.erb
deleted file mode 100644
index 84204c907..000000000
--- a/app/views/comments/_comment_tree.html.erb
+++ /dev/null
@@ -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 %>
-
-<% end %>
diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb
deleted file mode 100644
index 17813cace..000000000
--- a/app/views/comments/_form.html.erb
+++ /dev/null
@@ -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) %>
-
-<% end %>
diff --git a/app/views/legislation/annotations/show.html.erb b/app/views/legislation/annotations/show.html.erb
index 3015cdd4c..e5e3eba6a 100644
--- a/app/views/legislation/annotations/show.html.erb
+++ b/app/views/legislation/annotations/show.html.erb
@@ -43,8 +43,12 @@
- <%= render "/comments/comment_tree", comment_tree: @comment_tree,
- display_comments_count: true %>
+ <%= render Shared::CommentsComponent.new(@annotation, @comment_tree) do %>
+
+ <%= t("comments_helper.comments_title") %>
+
+
+ <% end %>
diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb
index 16ee0430c..5a37e99d0 100644
--- a/app/views/legislation/questions/show.html.erb
+++ b/app/views/legislation/questions/show.html.erb
@@ -41,7 +41,10 @@
<%= render "/shared/social_share", title: @question.title, url: legislation_process_question_url(@question.process, @question) %>
-
- <%= render "/comments/comment_tree", comment_tree: @comment_tree,
- display_comments_count: true %>
+ <%= render Shared::CommentsComponent.new(@question, @comment_tree) do %>
+
+ <%= t("legislation.questions.comments.comments_title") %>
+
+
+ <% end %>
diff --git a/app/views/valuation/budget_investments/_valuation_comments.html.erb b/app/views/valuation/budget_investments/_valuation_comments.html.erb
index 713727bb3..ca2ef2b38 100644
--- a/app/views/valuation/budget_investments/_valuation_comments.html.erb
+++ b/app/views/valuation/budget_investments/_valuation_comments.html.erb
@@ -1,6 +1,4 @@
<%= t("valuation.budget_investments.valuation_comments") %>
<% unless @comment_tree.nil? %>
- <%= render "/comments/comment_tree", comment_tree: @comment_tree,
- display_comments_count: false,
- valuation: true %>
+ <%= render Shared::CommentsComponent.new(@investment, @comment_tree, valuation: true) %>
<% end %>
diff --git a/spec/components/comments/form_component_spec.rb b/spec/components/comments/form_component_spec.rb
new file mode 100644
index 000000000..3300b5f76
--- /dev/null
+++ b/spec/components/comments/form_component_spec.rb
@@ -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
diff --git a/spec/factories/classifications.rb b/spec/factories/classifications.rb
index 00b4b2d5b..489b5004a 100644
--- a/spec/factories/classifications.rb
+++ b/spec/factories/classifications.rb
@@ -34,7 +34,12 @@ FactoryBot.define do
community { create(:proposal).community }
end
+ trait :with_investment_community do
+ community { create(:budget_investment).community }
+ end
+
factory :topic_with_community, traits: [:with_community]
+ factory :topic_with_investment_community, traits: [:with_investment_community]
end
factory :related_content do
diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb
index 467395ee5..7f694bf7d 100644
--- a/spec/factories/comments.rb
+++ b/spec/factories/comments.rb
@@ -5,7 +5,7 @@ FactoryBot.define do
sequence(:body) { |n| "Comment body #{n}" }
%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
commentable factory: model
end
diff --git a/spec/factories/polls.rb b/spec/factories/polls.rb
index 84bdb9961..a7eb4a1b5 100644
--- a/spec/factories/polls.rb
+++ b/spec/factories/polls.rb
@@ -38,6 +38,10 @@ FactoryBot.define do
after(:create) { |poll| create(:image, imageable: poll) }
end
+ trait :with_author do
+ author factory: :user
+ end
+
transient { officers { [] } }
after(:create) do |poll, evaluator|
@@ -45,6 +49,8 @@ FactoryBot.define do
create(:poll_officer_assignment, poll: poll, officer: officer)
end
end
+
+ factory :poll_with_author, traits: [:with_author]
end
factory :poll_question, class: "Poll::Question" do
diff --git a/spec/system/comments/budget_investments_spec.rb b/spec/system/comments/budget_investments_spec.rb
index 2168faf04..a998f736f 100644
--- a/spec/system/comments/budget_investments_spec.rb
+++ b/spec/system/comments/budget_investments_spec.rb
@@ -1,415 +1,10 @@
require "rails_helper"
describe "Commenting Budget::Investments" do
- let(:user) { create(:user) }
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: " " \
- "click me " \
- "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
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
admin = create(:administrator, description: "user description")
@@ -425,7 +20,7 @@ describe "Commenting Budget::Investments" do
expect(page).to have_content "I am your Admin!"
end
- visit admin_budget_budget_investment_path(investment.budget, investment)
+ refresh
within "#comments" do
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"
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
diff --git a/spec/system/comments/budget_investments_valuation_spec.rb b/spec/system/comments/budget_investments_valuation_spec.rb
index baecf4433..b32ef0f98 100644
--- a/spec/system/comments/budget_investments_valuation_spec.rb
+++ b/spec/system/comments/budget_investments_valuation_spec.rb
@@ -57,112 +57,6 @@ describe "Internal valuation comments on Budget::Investments" do
expect(page).to have_content("Valuator Valuation response")
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 = " " \
- "click me 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
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...?")
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
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.")
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
parent = create(:comment, :valuation, author: valuator_user, commentable: investment)
@@ -279,18 +120,6 @@ describe "Internal valuation comments on Budget::Investments" do
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
scenario "can create valuation comment as an administrator" do
login_as(admin_user)
diff --git a/spec/system/comments/legislation_annotations_spec.rb b/spec/system/comments/legislation_annotations_spec.rb
index 0cbfe0997..e439be1dd 100644
--- a/spec/system/comments/legislation_annotations_spec.rb
+++ b/spec/system/comments/legislation_annotations_spec.rb
@@ -1,579 +1,9 @@
require "rails_helper"
-describe "Commenting legislation questions" do
+describe "Commenting legislation annotations" do
let(:user) { create(: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: " " \
- "click me " \
- "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
let!(:draft_version) { create(:legislation_draft_version, :published) }
let!(:annotation1) do
diff --git a/spec/system/comments/legislation_questions_spec.rb b/spec/system/comments/legislation_questions_spec.rb
deleted file mode 100644
index 6412396fe..000000000
--- a/spec/system/comments/legislation_questions_spec.rb
+++ /dev/null
@@ -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: " " \
- "click me " \
- "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
diff --git a/spec/system/comments/poll_questions_spec.rb b/spec/system/comments/poll_questions_spec.rb
deleted file mode 100644
index 99b14edf3..000000000
--- a/spec/system/comments/poll_questions_spec.rb
+++ /dev/null
@@ -1 +0,0 @@
-#refactor specs and test as one more commmentable
diff --git a/spec/system/comments/polls_spec.rb b/spec/system/comments/polls_spec.rb
deleted file mode 100644
index 94568a747..000000000
--- a/spec/system/comments/polls_spec.rb
+++ /dev/null
@@ -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: " " \
- "click me " \
- "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
diff --git a/spec/system/comments/proposals_spec.rb b/spec/system/comments/proposals_spec.rb
deleted file mode 100644
index 505743a60..000000000
--- a/spec/system/comments/proposals_spec.rb
+++ /dev/null
@@ -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: " " \
- "click me " \
- "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
diff --git a/spec/system/comments/topics_spec.rb b/spec/system/comments/topics_spec.rb
deleted file mode 100644
index b8b6852b7..000000000
--- a/spec/system/comments/topics_spec.rb
+++ /dev/null
@@ -1,1087 +0,0 @@
-require "rails_helper"
-
-describe "Commenting topics from proposals" do
- let(:user) { create(:user) }
- let(:proposal) { create(:proposal) }
-
- it_behaves_like "flaggable", :topic_with_community_comment
-
- scenario "Index" do
- community = proposal.community
- topic = create(:topic, community: community)
- create_list(:comment, 3, commentable: topic)
- comment = Comment.includes(:user).last
-
- visit community_topic_path(community, topic)
-
- expect(page).to have_css(".comment", count: 3)
-
- within first(".comment") do
- expect(page).to have_content comment.user.name
- expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
- expect(page).to have_content comment.body
- end
- end
-
- scenario "Show" do
- community = proposal.community
- topic = create(:topic, community: community)
- parent_comment = create(:comment, commentable: topic)
- first_child = create(:comment, commentable: topic, parent: parent_comment)
- second_child = create(:comment, commentable: topic, parent: parent_comment)
-
- visit comment_path(parent_comment)
-
- expect(page).to have_css(".comment", count: 3)
- expect(page).to have_content parent_comment.body
- expect(page).to have_content first_child.body
- expect(page).to have_content second_child.body
-
- expect(page).to have_link "Go back to #{topic.title}", href: community_topic_path(community, topic)
- end
-
- scenario "Link to comment show" do
- community = proposal.community
- topic = create(:topic, community: community)
- comment = create(:comment, commentable: topic, user: user)
-
- visit community_topic_path(community, topic)
-
- 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 #{topic.title}"
- expect(page).to have_current_path(comment_path(comment))
- end
-
- scenario "Collapsable comments" do
- community = proposal.community
- topic = create(:topic, community: community)
- parent_comment = create(:comment, body: "Main comment", commentable: topic)
- child_comment = create(:comment, body: "First subcomment", commentable: topic, parent: parent_comment)
- grandchild_comment = create(:comment, body: "Last subcomment", commentable: topic, parent: child_comment)
-
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
- c1 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 100,
- cached_votes_total: 120, created_at: Time.current - 2)
- c2 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 10,
- cached_votes_total: 12, created_at: Time.current - 1)
- c3 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 1,
- cached_votes_total: 2, created_at: Time.current)
-
- visit community_topic_path(community, topic, order: :most_voted)
-
- expect(c1.body).to appear_before(c2.body)
- expect(c2.body).to appear_before(c3.body)
-
- click_link "Newest first"
-
- expect(page).to have_link "Newest first", class: "is-active"
- expect(page).to have_current_path(/#comments/, url: true)
- expect(c3.body).to appear_before(c2.body)
- expect(c2.body).to appear_before(c1.body)
-
- click_link "Oldest first"
-
- expect(page).to have_link "Oldest first", class: "is-active"
- expect(page).to have_current_path(/#comments/, url: true)
- expect(c1.body).to appear_before(c2.body)
- expect(c2.body).to appear_before(c3.body)
- end
-
- scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do
- community = proposal.community
- topic = create(:topic, community: community)
- old_root = create(:comment, commentable: topic, created_at: Time.current - 10)
- new_root = create(:comment, commentable: topic, created_at: Time.current)
- old_child = create(:comment, commentable: topic, parent_id: new_root.id, created_at: Time.current - 10)
- new_child = create(:comment, commentable: topic, parent_id: new_root.id, created_at: Time.current)
-
- visit community_topic_path(community, topic, order: :most_voted)
-
- expect(new_root.body).to appear_before(old_root.body)
- expect(old_child.body).to appear_before(new_child.body)
-
- visit community_topic_path(community, topic, order: :newest)
-
- expect(new_root.body).to appear_before(old_root.body)
- expect(new_child.body).to appear_before(old_child.body)
-
- visit community_topic_path(community, topic, 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
- community = proposal.community
- topic = create(:topic, community: community)
- create(:comment, commentable: topic, body: "Built with http://rubyonrails.org/")
-
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
- create(:comment, commentable: topic,
- body: " " \
- "click me " \
- "http://www.url.com")
-
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
- per_page = 10
- (per_page + 2).times { create(:comment, commentable: topic) }
-
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
- create(:comment, commentable: topic)
-
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
-
- login_as(user)
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
-
- login_as(user)
- visit community_topic_path(community, topic)
-
- click_button "Publish comment"
-
- expect(page).to have_content "Can't be blank"
- end
-
- scenario "Reply" do
- community = proposal.community
- topic = create(:topic, community: community)
- citizen = create(:user, username: "Ana")
- manuela = create(:user, username: "Manuela")
- comment = create(:comment, commentable: topic, user: citizen)
-
- login_as(manuela)
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
- comment = create(:comment, commentable: topic)
-
- login_as(create(:user))
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
- comment = create(:comment, commentable: topic)
- create(:comment, commentable: topic, parent: comment)
-
- login_as(create(:user))
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
- comment = create(:comment, commentable: topic, user: user)
-
- login_as(user)
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
- parent = create(:comment, commentable: topic)
-
- 7.times do
- create(:comment, commentable: topic, parent: parent)
- parent = parent.children.first
- end
-
- visit community_topic_path(community, topic)
- expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
- end
-
- scenario "Erasing a comment's author" do
- community = proposal.community
- topic = create(:topic, community: community)
- comment = create(:comment, commentable: topic, body: "this should be visible")
- comment.user.erase
-
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
- moderator = create(:moderator)
-
- login_as(moderator.user)
- visit community_topic_path(community, topic)
-
- fill_in "Leave your comment", with: "I am moderating!"
- check "comment-as-moderator-topic_#{topic.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
- community = proposal.community
- topic = create(:topic, community: community)
- citizen = create(:user, username: "Ana")
- manuela = create(:user, username: "Manuela")
- moderator = create(:moderator, user: manuela)
- comment = create(:comment, commentable: topic, user: citizen)
-
- login_as(manuela)
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
- moderator = create(:moderator)
-
- login_as(moderator.user)
- visit community_topic_path(community, topic)
-
- expect(page).not_to have_content "Comment as administrator"
- end
- end
-
- describe "Administrators" do
- scenario "can create comment as an administrator" do
- community = proposal.community
- topic = create(:topic, community: community)
- admin = create(:administrator)
-
- login_as(admin.user)
- visit community_topic_path(community, topic)
-
- fill_in "Leave your comment", with: "I am your Admin!"
- check "comment-as-administrator-topic_#{topic.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
- community = proposal.community
- topic = create(:topic, community: community)
- citizen = create(:user, username: "Ana")
- manuela = create(:user, username: "Manuela")
- admin = create(:administrator, user: manuela)
- comment = create(:comment, commentable: topic, user: citizen)
-
- login_as(manuela)
- visit community_topic_path(community, topic)
-
- 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
- community = proposal.community
- topic = create(:topic, community: community)
-
- visit community_topic_path(community, topic)
-
- 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(:topic) { create(:topic, community: proposal.community) }
- let!(:comment) { create(:comment, commentable: topic) }
-
- 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 community_topic_path(proposal.community, topic)
-
- 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 community_topic_path(proposal.community, topic)
-
- 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 community_topic_path(proposal.community, topic)
-
- 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 community_topic_path(proposal.community, topic)
-
- 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
-
-describe "Commenting topics from budget investments" do
- let(:user) { create(:user) }
- let(:investment) { create(:budget_investment) }
-
- scenario "Index" do
- community = investment.community
- topic = create(:topic, community: community)
- create_list(:comment, 3, commentable: topic)
- comment = Comment.includes(:user).last
-
- visit community_topic_path(community, topic)
-
- expect(page).to have_css(".comment", count: 3)
-
- within first(".comment") do
- expect(page).to have_content comment.user.name
- expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
- expect(page).to have_content comment.body
- end
- end
-
- scenario "Show" do
- community = investment.community
- topic = create(:topic, community: community)
- parent_comment = create(:comment, commentable: topic)
- first_child = create(:comment, commentable: topic, parent: parent_comment)
- second_child = create(:comment, commentable: topic, parent: parent_comment)
-
- visit comment_path(parent_comment)
-
- expect(page).to have_css(".comment", count: 3)
- expect(page).to have_content parent_comment.body
- expect(page).to have_content first_child.body
- expect(page).to have_content second_child.body
-
- expect(page).to have_link "Go back to #{topic.title}", href: community_topic_path(community, topic)
- end
-
- scenario "Collapsable comments" do
- community = investment.community
- topic = create(:topic, community: community)
- parent_comment = create(:comment, body: "Main comment", commentable: topic)
- child_comment = create(:comment, body: "First subcomment", commentable: topic, parent: parent_comment)
- grandchild_comment = create(:comment, body: "Last subcomment", commentable: topic, parent: child_comment)
-
- visit community_topic_path(community, topic)
-
- expect(page).to have_css(".comment", count: 3)
-
- within ".comment .comment", text: "First subcomment" do
- click_link text: "1 response (collapse)"
- end
-
- expect(page).to have_css(".comment", count: 2)
- 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 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).not_to have_content child_comment.body
- expect(page).not_to have_content grandchild_comment.body
- end
-
- scenario "Comment order" do
- community = investment.community
- topic = create(:topic, community: community)
- c1 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 100,
- cached_votes_total: 120, created_at: Time.current - 2)
- c2 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 10,
- cached_votes_total: 12, created_at: Time.current - 1)
- c3 = create(:comment, :with_confidence_score, commentable: topic, cached_votes_up: 1,
- cached_votes_total: 2, created_at: Time.current)
-
- visit community_topic_path(community, topic, order: :most_voted)
-
- expect(c1.body).to appear_before(c2.body)
- expect(c2.body).to appear_before(c3.body)
-
- click_link "Newest first"
-
- expect(page).to have_link "Newest first", class: "is-active"
- expect(page).to have_current_path(/#comments/, url: true)
- expect(c3.body).to appear_before(c2.body)
- expect(c2.body).to appear_before(c1.body)
-
- click_link "Oldest first"
-
- expect(page).to have_link "Oldest first", class: "is-active"
- expect(page).to have_current_path(/#comments/, url: true)
- expect(c1.body).to appear_before(c2.body)
- expect(c2.body).to appear_before(c3.body)
- end
-
- scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do
- community = investment.community
- topic = create(:topic, community: community)
- old_root = create(:comment, commentable: topic, created_at: Time.current - 10)
- new_root = create(:comment, commentable: topic, created_at: Time.current)
- old_child = create(:comment, commentable: topic, parent_id: new_root.id, created_at: Time.current - 10)
- new_child = create(:comment, commentable: topic, parent_id: new_root.id, created_at: Time.current)
-
- visit community_topic_path(community, topic, order: :most_voted)
-
- expect(new_root.body).to appear_before(old_root.body)
- expect(old_child.body).to appear_before(new_child.body)
-
- visit community_topic_path(community, topic, order: :newest)
-
- expect(new_root.body).to appear_before(old_root.body)
- expect(new_child.body).to appear_before(old_child.body)
-
- visit community_topic_path(community, topic, 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
- community = investment.community
- topic = create(:topic, community: community)
- create(:comment, commentable: topic, body: "Built with http://rubyonrails.org/")
-
- visit community_topic_path(community, topic)
-
- 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
- community = investment.community
- topic = create(:topic, community: community)
- create(:comment, commentable: topic,
- body: " " \
- "click me " \
- "http://www.url.com")
-
- visit community_topic_path(community, topic)
-
- 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
- community = investment.community
- topic = create(:topic, community: community)
- per_page = 10
- (per_page + 2).times { create(:comment, commentable: topic) }
-
- visit community_topic_path(community, topic)
-
- 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
- community = investment.community
- topic = create(:topic, community: community)
- create(:comment, commentable: topic)
-
- visit community_topic_path(community, topic)
-
- 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
- community = investment.community
- topic = create(:topic, community: community)
-
- login_as(user)
- visit community_topic_path(community, topic)
-
- 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
- community = investment.community
- topic = create(:topic, community: community)
-
- login_as(user)
- visit community_topic_path(community, topic)
-
- click_button "Publish comment"
-
- expect(page).to have_content "Can't be blank"
- end
-
- scenario "Reply" do
- community = investment.community
- topic = create(:topic, community: community)
- citizen = create(:user, username: "Ana")
- manuela = create(:user, username: "Manuela")
- comment = create(:comment, commentable: topic, user: citizen)
-
- login_as(manuela)
- visit community_topic_path(community, topic)
-
- 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 "Errors on reply" do
- community = investment.community
- topic = create(:topic, community: community)
- comment = create(:comment, commentable: topic, user: user)
-
- login_as(user)
- visit community_topic_path(community, topic)
-
- 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
- community = investment.community
- topic = create(:topic, community: community)
- parent = create(:comment, commentable: topic)
-
- 7.times do
- create(:comment, commentable: topic, parent: parent)
- parent = parent.children.first
- end
-
- visit community_topic_path(community, topic)
- expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
- end
-
- scenario "Erasing a comment's author" do
- community = investment.community
- topic = create(:topic, community: community)
- comment = create(:comment, commentable: topic, body: "this should be visible")
- comment.user.erase
-
- visit community_topic_path(community, topic)
-
- 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
- community = investment.community
- topic = create(:topic, community: community)
- moderator = create(:moderator)
-
- login_as(moderator.user)
- visit community_topic_path(community, topic)
-
- fill_in "Leave your comment", with: "I am moderating!"
- check "comment-as-moderator-topic_#{topic.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
- community = investment.community
- topic = create(:topic, community: community)
- citizen = create(:user, username: "Ana")
- manuela = create(:user, username: "Manuela")
- moderator = create(:moderator, user: manuela)
- comment = create(:comment, commentable: topic, user: citizen)
-
- login_as(manuela)
- visit community_topic_path(community, topic)
-
- 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
- community = investment.community
- topic = create(:topic, community: community)
- moderator = create(:moderator)
-
- login_as(moderator.user)
- visit community_topic_path(community, topic)
-
- expect(page).not_to have_content "Comment as administrator"
- end
- end
-
- describe "Administrators" do
- scenario "can create comment as an administrator" do
- community = investment.community
- topic = create(:topic, community: community)
- admin = create(:administrator)
-
- login_as(admin.user)
- visit community_topic_path(community, topic)
-
- fill_in "Leave your comment", with: "I am your Admin!"
- check "comment-as-administrator-topic_#{topic.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
- community = investment.community
- topic = create(:topic, community: community)
- citizen = create(:user, username: "Ana")
- manuela = create(:user, username: "Manuela")
- admin = create(:administrator, user: manuela)
- comment = create(:comment, commentable: topic, user: citizen)
-
- login_as(manuela)
- visit community_topic_path(community, topic)
-
- 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
- community = investment.community
- topic = create(:topic, community: community)
-
- visit community_topic_path(community, topic)
-
- 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(:investment) { create(:budget_investment) }
- let(:topic) { create(:topic, community: investment.community) }
- let!(:comment) { create(:comment, commentable: topic) }
-
- 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 community_topic_path(investment.community, topic)
-
- 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 community_topic_path(investment.community, topic)
-
- 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 community_topic_path(investment.community, topic)
-
- 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 community_topic_path(investment.community, topic)
-
- 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
diff --git a/spec/system/comments/debates_spec.rb b/spec/system/comments_spec.rb
similarity index 57%
rename from spec/system/comments/debates_spec.rb
rename to spec/system/comments_spec.rb
index 4b2969658..c8a33de68 100644
--- a/spec/system/comments/debates_spec.rb
+++ b/spec/system/comments_spec.rb
@@ -1,30 +1,94 @@
require "rails_helper"
-describe "Commenting debates" do
- let(:user) { create(:user) }
- let(:debate) { create(:debate) }
+describe "Comments" do
+ factories = [
+ :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
- 3.times { create(:comment, commentable: debate) }
- comment = Comment.includes(:user).last
+ it_behaves_like "flaggable", :"#{(factories - [:poll_with_author]).sample}_comment"
- 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
- 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
+ visit budget_investment_path(investment.budget, investment)
+
+ expect(page).to have_css(".comment", count: 3)
+ expect(page).not_to have_content("Not viable")
+
+ within("#comments") do
+ not_valuations.each do |comment|
+ expect(page).to have_content comment.user.name
+ expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
+ expect(page).to have_content comment.body
+ end
+ end
+ end
+ end
+
+ context "Debates, annotations, question, Polls, Proposals and Topics" do
+ let(:factory) { (factories - [:budget_investment]).sample }
+
+ scenario "render comments" do
+ 3.times { create(:comment, commentable: resource) }
+ comment = Comment.includes(:user).last
+
+ visit polymorphic_path(resource)
+
+ if factory == :legislation_annotation
+ expect(page).to have_css(".comment", count: 4)
+ else
+ expect(page).to have_css(".comment", count: 3)
+ end
+
+ within first(".comment") do
+ expect(page).to have_content comment.user.name
+ expect(page).to have_content I18n.l(comment.created_at, format: :datetime)
+ expect(page).to have_content comment.body
+ end
+ end
end
end
scenario "Show" do
- parent_comment = create(:comment, commentable: debate, body: "Parent")
- create(:comment, commentable: debate, parent: parent_comment, body: "First subcomment")
- create(:comment, commentable: debate, parent: parent_comment, body: "Last subcomment")
+ parent_comment = create(:comment, commentable: resource, body: "Parent")
+ create(:comment, commentable: resource, parent: parent_comment, body: "First subcomment")
+ create(:comment, commentable: resource, parent: parent_comment, body: "Last subcomment")
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 "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
expect(page).to have_css ".comment", count: 2
@@ -41,26 +106,34 @@ describe "Commenting debates" do
end
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
- expect(page).to have_link comment.created_at.strftime("%Y-%m-%d %T")
+ click_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 #{debate.title}"
+ expect(page).to have_link "Go back to #{resource.title}"
expect(page).to have_current_path(comment_path(comment))
end
scenario "Collapsable comments" do
- parent_comment = create(:comment, body: "Main comment", commentable: debate)
- child_comment = create(:comment, body: "First subcomment", commentable: debate, parent: parent_comment)
- grandchild_comment = create(:comment, body: "Last subcomment", commentable: debate, parent: child_comment)
+ if factory == :legislation_annotation
+ parent_comment = resource.comments.first
+ 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_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 grandchild_comment.body
- within ".comment", text: "Main comment" do
+ within ".comment", text: parent_comment.body do
click_link text: "1 response (collapse)", match: :first
end
@@ -93,14 +166,14 @@ describe "Commenting debates" do
end
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)
- visit debate_path(debate)
+ visit polymorphic_path(resource)
within ".comment", text: "Main comment" do
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"
expect(page).to have_content("It will be done next week.")
@@ -111,15 +184,29 @@ describe "Commenting debates" do
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
- 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)
- 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)
- 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)
- visit debate_path(debate, order: :most_voted)
+ visit polymorphic_path(resource, order: :most_voted)
expect(c1.body).to appear_before(c2.body)
expect(c2.body).to appear_before(c3.body)
@@ -140,31 +227,34 @@ describe "Commenting debates" do
end
scenario "Creation date works differently in roots and child comments when sorting by confidence_score" do
- old_root = create(:comment, commentable: debate, created_at: Time.current - 10)
- new_root = create(:comment, commentable: debate, created_at: Time.current)
- old_child = create(:comment, commentable: debate, parent_id: new_root.id, created_at: Time.current - 10)
- new_child = create(:comment, commentable: debate, parent_id: new_root.id, created_at: Time.current)
+ old_root = create(:comment, commentable: resource, created_at: Time.current - 10)
+ new_root = create(:comment, commentable: resource, created_at: Time.current)
+ old_child = create(:comment,
+ 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(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_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_child.body).to appear_before(new_child.body)
end
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
expect(page).to have_content "Built with http://rubyonrails.org/"
@@ -175,12 +265,12 @@ describe "Commenting debates" do
end
scenario "Sanitizes comment body for security" do
- create(:comment, commentable: debate,
+ create(:comment, commentable: resource,
body: " " \
"click me " \
"http://www.url.com")
- visit debate_path(debate)
+ visit polymorphic_path(resource)
within first(".comment") do
expect(page).to have_content "click me http://www.url.com"
@@ -191,9 +281,9 @@ describe "Commenting debates" do
scenario "Paginated comments" do
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)
within("ul.pagination") do
@@ -203,51 +293,47 @@ describe "Commenting debates" do
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: 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
+ if factory == :legislation_annotation
+ expect(page).to have_css(".comment", count: 3)
+ else
+ expect(page).to have_css(".comment", count: 2)
end
+ expect(page).to have_current_path(/#comments/, url: true)
end
scenario "Create" do
login_as(user)
- visit debate_path(debate)
+ visit polymorphic_path(resource)
- fill_in "Leave your comment", with: "Have you thought about...?"
- click_button "Publish comment"
+ fill_in fill_text, with: "Have you thought about...?"
+ 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
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 debate_path(debate)
-
- click_button "Publish comment"
-
- expect(page).to have_content "Can't be blank"
- end
-
describe "Hide" 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)
- 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
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_link "Delete comment"
- visit debate_path(debate)
+ refresh
expect(page).not_to have_content "This was a mistake"
expect(page).not_to have_link "Delete comment"
logout
- login_as(create(:administrator).user)
+ login_as(admin)
visit admin_hidden_comments_path
@@ -270,11 +356,11 @@ describe "Commenting debates" do
end
scenario "With replies" do
- comment = create(:comment, commentable: debate, user: user, body: "Wrong comment")
- create(:comment, commentable: debate, parent: comment, body: "Right reply")
+ comment = create(:comment, commentable: resource, user: user, body: "Wrong comment")
+ create(:comment, commentable: resource, parent: comment, body: "Right reply")
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
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"
end
- visit debate_path(debate)
+ refresh
within "#comments > .comment-list > li", text: "Right reply" do
expect(page).to have_content "This comment has been deleted"
@@ -295,17 +381,17 @@ describe "Commenting debates" do
end
scenario "Reply" do
- citizen = create(:user, username: "Ana")
- manuela = create(:user, username: "Manuela")
- comment = create(:comment, commentable: debate, user: citizen)
+ comment = create(:comment, commentable: resource)
- login_as(manuela)
- visit debate_path(debate)
+ login_as(user)
+ visit polymorphic_path(resource)
- click_link "Reply"
+ within "#comment_#{comment.id}" do
+ click_link "Reply"
+ end
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"
end
@@ -317,20 +403,20 @@ describe "Commenting debates" do
end
scenario "Reply to reply" do
- create(:comment, commentable: debate, body: "Any estimates?")
+ create(:comment, commentable: resource, body: "Any estimates?")
- login_as(create(:user))
- visit debate_path(debate)
+ login_as(user)
+ visit polymorphic_path(resource)
within ".comment", text: "Any estimates?" do
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"
end
within ".comment .comment", text: "It will be done next week" do
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"
expect(page).not_to have_css ".comment-form"
@@ -342,14 +428,14 @@ describe "Commenting debates" do
end
scenario "Reply update parent comment responses count" do
- comment = create(:comment, commentable: debate)
+ comment = create(:comment, commentable: resource)
- login_as(create(:user))
- visit debate_path(debate)
+ login_as(user)
+ visit polymorphic_path(resource)
within ".comment", text: comment.body do
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"
expect(page).to have_content("1 response (collapse)")
@@ -357,39 +443,32 @@ describe "Commenting debates" do
end
scenario "Reply show parent comments responses when hidden" do
- comment = create(:comment, commentable: debate)
- create(:comment, commentable: debate, parent: comment)
+ comment = create(:comment, commentable: resource)
+ create(:comment, commentable: resource, parent: comment)
- login_as(create(:user))
- visit debate_path(debate)
+ login_as(user)
+ visit polymorphic_path(resource)
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."
+ fill_in fill_text, 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 "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
- comment = create(:comment, commentable: debate, user: user)
+ comment = create(:comment, commentable: resource, user: 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
click_button "Publish reply"
@@ -398,52 +477,62 @@ describe "Commenting debates" do
end
scenario "N replies" do
- parent = create(:comment, commentable: debate)
+ parent = create(:comment, commentable: resource)
7.times do
- create(:comment, commentable: debate, parent: parent)
+ create(:comment, commentable: resource, parent: parent)
parent = parent.children.first
end
- visit debate_path(debate)
+ visit polymorphic_path(resource)
expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment")
end
scenario "Erasing a comment's author" do
- debate = create(:debate)
- comment = create(:comment, commentable: debate, body: "this should be visible")
+ comment = create(:comment, commentable: resource, body: "this should be visible")
comment.user.erase
- visit debate_path(debate)
- within "#comment_#{comment.id}" do
+ visit polymorphic_path(resource)
+
+ within ".comment", text: "this should be visible" do
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
scenario "Submit button is disabled after clicking" do
- debate = create(:debate)
login_as(user)
- visit debate_path(debate)
+ visit polymorphic_path(resource)
- fill_in "Leave your comment", with: "Testing submit button!"
- click_button "Publish comment"
+ fill_in fill_text, with: "Testing submit button!"
+ 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_button "Publish comment", disabled: false
+ expect(page).to have_button button_text, disabled: false
end
describe "Moderators" do
+ let(:moderator) { create(:moderator) }
+ before { login_as(moderator.user) }
+
scenario "can create comment as a moderator" do
- moderator = create(:moderator)
+ visit polymorphic_path(resource)
- login_as(moderator.user)
- visit debate_path(debate)
+ expect(page).not_to have_content "Comment as administrator"
- fill_in "Leave your comment", with: "I am moderating!"
- check "comment-as-moderator-debate_#{debate.id}"
- click_button "Publish comment"
+ fill_in fill_text, with: "I am moderating!"
+ check "Comment as moderator"
+ click_button button_text
within "#comments" do
expect(page).to have_content "I am moderating!"
@@ -454,19 +543,17 @@ describe "Commenting debates" do
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: debate, user: citizen)
+ comment = create(:comment, commentable: resource)
- login_as(manuela)
- 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
- fill_in "Leave your comment", with: "I am moderating!"
- check "comment-as-moderator-comment_#{comment.id}"
+ fill_in fill_text, with: "I am moderating!"
+ check "Comment as moderator"
click_button "Publish reply"
end
@@ -479,50 +566,44 @@ describe "Commenting debates" do
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 debate_path(debate)
-
- 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)
+ scenario "can create comment" do
+ admin = create(:administrator, description: "admin user")
login_as(admin.user)
- visit debate_path(debate)
+ visit polymorphic_path(resource)
- fill_in "Leave your comment", with: "I am your Admin!"
- check "comment-as-administrator-debate_#{debate.id}"
- click_button "Publish comment"
+ expect(page).not_to have_content "Comment as moderator"
+
+ fill_in fill_text, with: "I am your Admin!"
+ check "Comment as admin"
+ click_button button_text
within "#comments" do
expect(page).to have_content "I am your Admin!"
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 "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: debate, user: citizen)
+ admin = create(:administrator)
+ comment = create(:comment, commentable: resource)
- login_as(manuela)
- visit debate_path(debate)
+ login_as(admin.user)
+ visit polymorphic_path(resource)
- click_link "Reply"
+ within "#comment_#{comment.id}" do
+ click_link "Reply"
+ end
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}"
+ fill_in fill_text, with: "Top of the world!"
+ check "Comment as admin"
click_button "Publish reply"
end
@@ -535,19 +616,12 @@ describe "Commenting debates" do
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
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
describe "Voting comments" do
let(:verified) { create(:user, verified_at: Time.current) }
let(:unverified) { create(:user) }
- let(:debate) { create(:debate) }
- let!(:comment) { create(:comment, commentable: debate) }
+ let!(:comment) { create(:comment, commentable: resource) }
before do
login_as(verified)
@@ -557,7 +631,7 @@ describe "Commenting debates" do
create(:vote, voter: verified, votable: comment, vote_flag: true)
create(:vote, voter: unverified, votable: comment, vote_flag: false)
- visit debate_path(debate)
+ visit polymorphic_path(resource)
within("#comment_#{comment.id}_votes") do
within(".in-favor") do
@@ -573,7 +647,7 @@ describe "Commenting debates" do
end
scenario "Create" do
- visit debate_path(debate)
+ visit polymorphic_path(resource)
within("#comment_#{comment.id}_votes") do
click_button "I agree"
@@ -591,7 +665,7 @@ describe "Commenting debates" do
end
scenario "Update" do
- visit debate_path(debate)
+ visit polymorphic_path(resource)
within("#comment_#{comment.id}_votes") do
click_button "I agree"
@@ -615,17 +689,18 @@ describe "Commenting debates" do
end
scenario "Allow undoing votes" do
- visit debate_path(debate)
+ visit polymorphic_path(resource)
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
@@ -637,4 +712,13 @@ describe "Commenting debates" do
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
diff --git a/spec/system/legislation/questions_spec.rb b/spec/system/legislation/questions_spec.rb
index 41570c6a6..806a65ea3 100644
--- a/spec/system/legislation/questions_spec.rb
+++ b/spec/system/legislation/questions_spec.rb
@@ -2,6 +2,8 @@ require "rails_helper"
describe "Legislation" do
context "process debate page" do
+ it_behaves_like "notifiable in-app", :legislation_question
+
let(:process) do
create(:legislation_process,
debate_start_date: Date.current - 3.days,
- <%= comment_tree_title_text(commentable) %> - (<%= commentable.comments_count %>) -
- <% end %> - - <% if user_signed_in? %> - <% if comments_closed_for_commentable?(commentable) %> --
-