diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 98357e96e..0f5cb680b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 diff --git a/app/models/comment.rb b/app/models/comment.rb index 0651b3442..3c58f966b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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) diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 8d45b5469..a5d84166e 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -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 %>
@@ -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 %>
@@ -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 %> diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 80cd7e2da..8ceefdd59 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -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" %> diff --git a/app/views/valuation/budget_investments/_written_by_valuators.html.erb b/app/views/valuation/budget_investments/_written_by_valuators.html.erb index 965f2b059..eb2d0e81d 100644 --- a/app/views/valuation/budget_investments/_written_by_valuators.html.erb +++ b/app/views/valuation/budget_investments/_written_by_valuators.html.erb @@ -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 %> diff --git a/app/views/valuation/budget_investments/edit.html.erb b/app/views/valuation/budget_investments/edit.html.erb index 5ae5ae5dd..7d3350fe6 100644 --- a/app/views/valuation/budget_investments/edit.html.erb +++ b/app/views/valuation/budget_investments/edit.html.erb @@ -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 %> diff --git a/spec/features/comments/budget_investments_spec.rb b/spec/features/comments/budget_investments_spec.rb index 4afb1e680..bae63e4ec 100644 --- a/spec/features/comments/budget_investments_spec.rb +++ b/spec/features/comments/budget_investments_spec.rb @@ -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)