Allow valuation internal comments to be created
How: Using a local variable at partials to set a hidden true/false value for `valuation` parameter on the comment creation form. Allowing that new param at the comment controller and using it when building a new Comment.
This commit is contained in:
@@ -45,12 +45,13 @@ class CommentsController < ApplicationController
|
||||
|
||||
def comment_params
|
||||
params.require(:comment).permit(:commentable_type, :commentable_id, :parent_id,
|
||||
:body, :as_moderator, :as_administrator)
|
||||
:body, :as_moderator, :as_administrator, :valuation)
|
||||
end
|
||||
|
||||
def build_comment
|
||||
@comment = Comment.build(@commentable, current_user, comment_params[:body],
|
||||
comment_params[:parent_id].presence)
|
||||
comment_params[:parent_id].presence,
|
||||
comment_params[:valuation])
|
||||
check_for_special_comments
|
||||
end
|
||||
|
||||
|
||||
@@ -55,11 +55,12 @@ class Comment < ActiveRecord::Base
|
||||
|
||||
after_create :call_after_commented
|
||||
|
||||
def self.build(commentable, user, body, p_id = nil)
|
||||
new commentable: commentable,
|
||||
def self.build(commentable, user, body, p_id = nil, valuation = false)
|
||||
new(commentable: commentable,
|
||||
user_id: user.id,
|
||||
body: body,
|
||||
parent_id: p_id
|
||||
parent_id: p_id,
|
||||
valuation: valuation)
|
||||
end
|
||||
|
||||
def self.find_commentable(c_type, c_id)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<% comment_flags ||= @comment_flags %>
|
||||
<% valuation = local_assigns.fetch(:valuation, false) %>
|
||||
<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (comment_flags[comment.id] if comment_flags)] do %>
|
||||
<ul id="<%= dom_id(comment) %>" class="comment no-bullet small-12">
|
||||
<li class="comment-body">
|
||||
@@ -88,7 +89,10 @@
|
||||
|
||||
<%= render 'comments/actions', comment: comment %>
|
||||
|
||||
<%= render 'comments/form', {commentable: comment.commentable, parent_id: comment.id, toggeable: true} %>
|
||||
<%= render 'comments/form', {commentable: comment.commentable,
|
||||
parent_id: comment.id,
|
||||
toggeable: true,
|
||||
valuation: valuation } %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -98,7 +102,8 @@
|
||||
<ul id="<%= dom_id(comment) %>_children" class="no-bullet comment-children">
|
||||
<% child_comments_of(comment).each do |child| %>
|
||||
<li>
|
||||
<%= render 'comments/comment', comment: child %>
|
||||
<%= render 'comments/comment', { comment: child,
|
||||
valuation: valuation } %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<% 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, comment_flags] do %>
|
||||
<section class="expanded comments">
|
||||
<div class="row">
|
||||
@@ -27,7 +27,8 @@
|
||||
<% else %>
|
||||
<%= render 'comments/form', { commentable: commentable,
|
||||
parent_id: nil,
|
||||
toggeable: false } %>
|
||||
toggeable: false,
|
||||
valuation: valuation } %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<br>
|
||||
@@ -39,7 +40,9 @@
|
||||
<% end %>
|
||||
|
||||
<% comment_tree.root_comments.each do |comment| %>
|
||||
<%= render 'comments/comment', {comment: comment, comment_flags: comment_flags} %>
|
||||
<%= render 'comments/comment', { comment: comment,
|
||||
comment_flags: comment_flags,
|
||||
valuation: valuation } %>
|
||||
<% end %>
|
||||
<%= paginate comment_tree.root_comments %>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,10 @@
|
||||
<%= render 'shared/wide_order_selector', i18n_namespace: "comments" %>
|
||||
|
||||
<% if user_signed_in? %>
|
||||
<%= render 'comments/form', {commentable: @investment, parent_id: nil, toggeable: false} %>
|
||||
<%= render 'comments/form', { commentable: @investment,
|
||||
parent_id: nil,
|
||||
toggeable: false,
|
||||
valuation: local_assigns.fetch(:valuation, false) } %>
|
||||
<% else %>
|
||||
<br>
|
||||
|
||||
@@ -22,7 +25,8 @@
|
||||
<% end %>
|
||||
|
||||
<% @comment_tree.root_comments.each do |comment| %>
|
||||
<%= render 'comments/comment', comment: comment %>
|
||||
<%= render 'comments/comment', { comment: comment,
|
||||
valuation: local_assigns.fetch(:valuation, false) } %>
|
||||
<% end %>
|
||||
<%= paginate @comment_tree.root_comments %>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<%= f.hidden_field :commentable_type, value: commentable.class.name %>
|
||||
<%= f.hidden_field :commentable_id, value: commentable.id %>
|
||||
<%= f.hidden_field :parent_id, value: parent_id %>
|
||||
<%= f.hidden_field :valuation, value: local_assigns.fetch(:valuation, false) %>
|
||||
|
||||
<%= f.submit comment_button_text(parent_id, commentable), class: "button", id: "publish_comment" %>
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
<% unless @comment_tree.nil? %>
|
||||
<%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree,
|
||||
comment_flags: @comment_flags,
|
||||
display_comments_count: false } %>
|
||||
display_comments_count: false,
|
||||
valuation: true } %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -107,7 +107,8 @@
|
||||
<% unless @comment_tree.nil? %>
|
||||
<%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree,
|
||||
comment_flags: @comment_flags,
|
||||
display_comments_count: false } %>
|
||||
display_comments_count: false,
|
||||
valuation: true } %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -7,16 +7,19 @@ feature 'Commenting Budget::Investments' do
|
||||
|
||||
scenario 'Index' do
|
||||
3.times { create(:comment, commentable: investment) }
|
||||
valuation_comment = 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')
|
||||
|
||||
comment = Comment.last
|
||||
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
|
||||
within("#comments") do
|
||||
Comment.not_valuations.last(3).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
|
||||
|
||||
@@ -24,6 +27,7 @@ feature 'Commenting Budget::Investments' do
|
||||
parent_comment = create(:comment, commentable: investment)
|
||||
first_child = create(:comment, commentable: investment, parent: parent_comment)
|
||||
second_child = create(:comment, commentable: investment, parent: parent_comment)
|
||||
valuation_comment = create(:comment, :valuation, commentable: investment, subject: 'Not viable')
|
||||
|
||||
visit comment_path(parent_comment)
|
||||
|
||||
@@ -31,6 +35,7 @@ feature 'Commenting Budget::Investments' do
|
||||
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).not_to have_content('Not viable')
|
||||
|
||||
expect(page).to have_link "Go back to #{investment.title}", href: budget_investment_path(investment.budget, investment)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user