diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 9fc0f875b..8e72d6c53 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -3,7 +3,8 @@ <% allow_votes = local_assigns.fetch(:allow_votes, true) %> <% allow_actions = local_assigns.fetch(:allow_actions, true) %> <% allow_comments = local_assigns.fetch(:allow_comments, true) %> -<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (comment_flags[comment.id] if comment_flags)] do %> +<% admin_layout = local_assigns.fetch(:admin_layout, false) %> +<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (comment_flags[comment.id] if comment_flags), (admin_layout if admin_layout)] do %>
<%= t("valuation.budget_investments.valuation_comments") %>
<% unless @comment_tree.nil? %> - <%= render partial: "/comments/comment_tree", locals: { comment_tree: @comment_tree, - comment_flags: @comment_flags, - display_comments_count: false, - valuation: true, - allow_comments: !@budget.finished? } %> + <%= render partial: "/comments/comment_tree", locals: { + comment_tree: @comment_tree, + comment_flags: @comment_flags, + display_comments_count: false, + valuation: true, + allow_comments: !@budget.finished?, + admin_layout: true } %> <% end %> diff --git a/spec/features/comments/budget_investments_spec.rb b/spec/features/comments/budget_investments_spec.rb index b5f064d93..5aeb77f7f 100644 --- a/spec/features/comments/budget_investments_spec.rb +++ b/spec/features/comments/budget_investments_spec.rb @@ -382,49 +382,109 @@ describe "Commenting Budget::Investments" do end describe "Administrators" do - scenario "can create comment as an administrator", :js do - admin = create(:administrator) + context "comment as administrator" do + scenario "can create comment", :js do + admin = create(:administrator) - login_as(admin.user) - visit budget_investment_path(investment.budget, investment) + login_as(admin.user) + visit budget_investment_path(investment.budget, investment) - fill_in "comment-body-budget_investment_#{investment.id}", with: "I am your Admin!" - check "comment-as-administrator-budget_investment_#{investment.id}" - click_button "Publish comment" + fill_in "comment-body-budget_investment_#{investment.id}", 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}" + 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", :js do + admin = create(:administrator, description: "user description") + + login_as(admin.user) + + visit admin_budget_budget_investment_path(investment.budget, investment) + + fill_in "comment-body-budget_investment_#{investment.id}", with: "I am your Admin!" + check "comment-as-administrator-budget_investment_#{investment.id}" + click_button "Publish comment" + + visit admin_budget_budget_investment_path(investment.budget, investment) + + within "#comments" do + expect(page).to have_content "I am your Admin!" + expect(page).to have_content "Administrator user description" + expect(page).to have_css "div.is-admin" + expect(page).to have_css "img.admin-avatar" + end + end + + scenario "display administrator id on public views", :js do + admin = create(:administrator, description: "user description") + + login_as(admin.user) + visit admin_budget_budget_investment_path(investment.budget, investment) + + fill_in "comment-body-budget_investment_#{investment.id}", 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", :js 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 "comment-body-comment_#{comment.id}", 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_selector("#js-comment-form-comment_#{comment.id}", visible: true) 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", :js 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 "comment-body-comment_#{comment.id}", 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" + scenario "public users not see admin description", :js 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 - expect(page).not_to have_selector("#js-comment-form-comment_#{comment.id}", visible: true) end scenario "can not comment as a moderator" do