Merge pull request #3912 from consul/refactor_editing_budget_investments
Refactor editing budget investments
This commit is contained in:
@@ -49,4 +49,8 @@ module BudgetInvestmentsHelper
|
|||||||
def investments_secondary_view
|
def investments_secondary_view
|
||||||
investments_current_view == "default" ? "minimal" : "default"
|
investments_current_view == "default" ? "minimal" : "default"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show_author_actions?(investment)
|
||||||
|
can?(:edit, investment) || can_destroy_image?(investment)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
18
app/views/budgets/investments/_author_actions.html.erb
Normal file
18
app/views/budgets/investments/_author_actions.html.erb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<% if show_author_actions?(investment) %>
|
||||||
|
<div class="sidebar-divider"></div>
|
||||||
|
<h2><%= t("budgets.investments.show.author") %></h2>
|
||||||
|
<div class="show-actions-menu">
|
||||||
|
<% 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 %>
|
||||||
@@ -23,18 +23,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<aside class="small-12 medium-3 column">
|
<aside class="small-12 medium-3 column">
|
||||||
<% if can_destroy_image?(investment) %>
|
<%= render "/budgets/investments/author_actions", investment: 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") %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if investment.should_show_aside? %>
|
<% if investment.should_show_aside? %>
|
||||||
<% if investment.should_show_votes? %>
|
<% if investment.should_show_votes? %>
|
||||||
|
|||||||
@@ -3,14 +3,14 @@
|
|||||||
<%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %>
|
<%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<% if can? :destroy, budget_investment %>
|
|
||||||
<%= link_to t("shared.delete"), budget_investment_path(budget_investment.budget, budget_investment),
|
|
||||||
method: :delete, class: "button hollow alert expanded",
|
|
||||||
data: { confirm: "#{t("users.show.delete_alert")}" } %>
|
|
||||||
<% end %>
|
|
||||||
<% if can? :update, budget_investment %>
|
<% if can? :update, budget_investment %>
|
||||||
<%= link_to t("shared.edit"), edit_budget_investment_path(budget_investment.budget, budget_investment),
|
<%= link_to t("shared.edit"), edit_budget_investment_path(budget_investment.budget, budget_investment),
|
||||||
class: "button hollow expanded" %>
|
class: "button hollow" %>
|
||||||
|
<% end %>
|
||||||
|
<% if can? :destroy, budget_investment %>
|
||||||
|
<%= link_to t("shared.delete"), budget_investment_path(budget_investment.budget, budget_investment),
|
||||||
|
method: :delete, class: "button hollow alert",
|
||||||
|
data: { confirm: "#{t("users.show.delete_alert")}" } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -1957,5 +1957,48 @@ describe "Budget Investments" do
|
|||||||
expect(page).to have_css(".map-icon", count: 3, visible: false)
|
expect(page).to have_css(".map-icon", count: 3, visible: false)
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user