forked from consuldemocracy/consuldemocracy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request consuldemocracy#5369 from consuldemocracy/refactor…
…_comments_specs Make comments specs faster
- Loading branch information
Showing
26 changed files
with
428 additions
and
4,305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<% cache cache_key do %> | ||
<% if comments_closed_for_commentable?(commentable) %> | ||
<br> | ||
<div data-alert class="callout primary"> | ||
<%= comments_closed_text %> | ||
</div> | ||
<% elsif require_verified_resident_for_commentable?(commentable, current_user) %> | ||
<br> | ||
<div data-alert class="callout primary"> | ||
<%= sanitize(t("comments.verified_only", verify_account: link_to_verify_account)) %> | ||
</div> | ||
<% elsif !valuation || can?(:comment_valuation, commentable) %> | ||
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %> | ||
<div id="js-comment-form-<%= css_id %>" class="comment-form"> | ||
<%= form_for Comment.new, remote: true, html: { id: "new_comment_#{css_id}" } do |f| %> | ||
<%= f.text_area :body, | ||
id: "comment-body-#{css_id}", | ||
maxlength: Comment.body_max_length, | ||
label: leave_comment_text(commentable) %> | ||
|
||
<%= f.hidden_field :commentable_type, value: commentable.class.name, id: "comment_commentable_type_#{css_id}" %> | ||
<%= f.hidden_field :commentable_id, value: commentable.id, id: "comment_commentable_id_#{css_id}" %> | ||
<%= f.hidden_field :parent_id, value: parent_id, id: "comment_parent_id_#{css_id}" %> | ||
<%= f.hidden_field :valuation, value: valuation, id: "comment_valuation_#{css_id}" %> | ||
|
||
<%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment_#{css_id}" %> | ||
|
||
<% if can? :comment_as_moderator, commentable %> | ||
<div class="float-right"> | ||
<%= f.check_box :as_moderator, | ||
label: t("comments.form.comment_as_moderator"), | ||
id: "comment-as-moderator-#{css_id}" %> | ||
</div> | ||
<% end %> | ||
<% if can? :comment_as_administrator, commentable %> | ||
<div class="float-right"> | ||
<%= f.check_box :as_administrator, | ||
label: t("comments.form.comment_as_admin"), | ||
id: "comment-as-administrator-#{css_id}" %> | ||
</div> | ||
<% end %> | ||
|
||
<% end %> | ||
</div> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
app/views/valuation/budget_investments/_valuation_comments.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
<h2><%= t("valuation.budget_investments.valuation_comments") %></h2> | ||
<% 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.