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.
This commit is contained in:
Julian Herrero
2020-02-04 12:59:15 +07:00
parent a24524298a
commit 65e841e44e
3 changed files with 59 additions and 6 deletions

View File

@@ -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

View File

@@ -1,12 +1,18 @@
<% if can_destroy_image?(investment) %>
<% if show_author_actions?(investment) %>
<div class="sidebar-divider"></div>
<h2><%= t("budgets.investments.show.author") %></h2>
<div class="show-actions-menu">
<%= link_to image_path(investment.image),
method: :delete,
class: "button hollow alert expanded" do %>
<span class="icon-image"></span>
<%= 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 %>
<span class="icon-image"></span>
<%= t("images.remove_image") %>
<% end %>
<% end %>
</div>
<% end %>

View File

@@ -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