From 65e841e44e298ee12a1f3f5d656883ea5b52232d Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Tue, 4 Feb 2020 12:59:15 +0700 Subject: [PATCH] Show edit button instead of remove image on accepting phase Since now it's possible to edit the budget investment during the accepting phase, it does not really make sense to show the button to just remove the image when the investment project can be fully edited, and the image can be removed from the editing form. --- app/helpers/budget_investments_helper.rb | 4 ++ .../investments/_author_actions.html.erb | 18 +++++--- spec/features/budgets/investments_spec.rb | 43 +++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/app/helpers/budget_investments_helper.rb b/app/helpers/budget_investments_helper.rb index 1e6d8405e..68e4435a3 100644 --- a/app/helpers/budget_investments_helper.rb +++ b/app/helpers/budget_investments_helper.rb @@ -49,4 +49,8 @@ module BudgetInvestmentsHelper def investments_secondary_view investments_current_view == "default" ? "minimal" : "default" end + + def show_author_actions?(investment) + can?(:edit, investment) || can_destroy_image?(investment) + end end diff --git a/app/views/budgets/investments/_author_actions.html.erb b/app/views/budgets/investments/_author_actions.html.erb index 20faa2af5..92a4aa863 100644 --- a/app/views/budgets/investments/_author_actions.html.erb +++ b/app/views/budgets/investments/_author_actions.html.erb @@ -1,12 +1,18 @@ -<% if can_destroy_image?(investment) %> +<% if show_author_actions?(investment) %>

<%= t("budgets.investments.show.author") %>

- <%= link_to image_path(investment.image), - method: :delete, - class: "button hollow alert expanded" do %> - - <%= t("images.remove_image") %> + <% if can?(:edit, investment) %> + <%= link_to t("shared.edit"), + edit_budget_investment_path(investment.budget, investment), + method: :get, class: "button hollow expanded" %> + <% else %> + <%= link_to image_path(investment.image), + method: :delete, + class: "button hollow alert expanded" do %> + + <%= t("images.remove_image") %> + <% end %> <% end %>
<% end %> diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 3e432ad5d..8e87b2aad 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -1957,5 +1957,48 @@ describe "Budget Investments" do expect(page).to have_css(".map-icon", count: 3, visible: false) end end + + context "Author actions section" do + scenario "Is not shown if investment is not editable or does not have an image" do + budget.update!(phase: "reviewing") + investment = create(:budget_investment, heading: heading, author: author) + + login_as(author) + visit budget_investment_path(budget, investment) + + within("aside") do + expect(page).not_to have_content "Author" + expect(page).not_to have_link "Edit" + expect(page).not_to have_link "Remove image" + end + end + + scenario "Contains edit button in the accepting phase" do + investment = create(:budget_investment, heading: heading, author: author) + + login_as(author) + visit budget_investment_path(budget, investment) + + within("aside") do + expect(page).to have_content "Author" + expect(page).to have_link "Edit" + expect(page).not_to have_link "Remove image" + end + end + + scenario "Contains remove image button in phases different from accepting" do + budget.update!(phase: "reviewing") + investment = create(:budget_investment, :with_image, heading: heading, author: author) + + login_as(author) + visit budget_investment_path(budget, investment) + + within("aside") do + expect(page).to have_content "Author" + expect(page).not_to have_link "Edit" + expect(page).to have_link "Remove image" + end + end + end end end