Changes suggested in the PR made
This commit is contained in:
@@ -3,30 +3,30 @@ class Admin::BudgetHeadingsController < Admin::BaseController
|
|||||||
feature_flag :budgets
|
feature_flag :budgets
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@budget = Budget.find params[:budget_id]
|
@budget = Budget.find(params[:budget_id])
|
||||||
@budget_group = @budget.groups.find params[:budget_group_id]
|
@budget_group = @budget.groups.find(params[:budget_group_id])
|
||||||
@budget_group.headings.create(budget_heading_params)
|
@budget_group.headings.create(budget_heading_params)
|
||||||
@headings = @budget_group.headings
|
@headings = @budget_group.headings
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@budget = Budget.find params[:budget_id]
|
@budget = Budget.find(params[:budget_id])
|
||||||
@budget_group = @budget.groups.find params[:budget_group_id]
|
@budget_group = @budget.groups.find(params[:budget_group_id])
|
||||||
@heading = Budget::Heading.find params[:id]
|
@heading = Budget::Heading.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@budget = Budget.find params[:budget_id]
|
@budget = Budget.find(params[:budget_id])
|
||||||
@budget_group = @budget.groups.find params[:budget_group_id]
|
@budget_group = @budget.groups.find(params[:budget_group_id])
|
||||||
@heading = Budget::Heading.find params[:id]
|
@heading = Budget::Heading.find(params[:id])
|
||||||
@heading.assign_attributes(budget_heading_params)
|
@heading.assign_attributes(budget_heading_params)
|
||||||
@errors = @heading.errors.full_messages unless @heading.save
|
render :edit unless @heading.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@heading = Budget::Heading.find params[:id]
|
@heading = Budget::Heading.find(params[:id])
|
||||||
@heading.destroy
|
@heading.destroy
|
||||||
@budget = Budget.find params[:budget_id]
|
@budget = Budget.find(params[:budget_id])
|
||||||
redirect_to admin_budget_path(@budget)
|
redirect_to admin_budget_path(@budget)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1 @@
|
|||||||
<% if @errors %>
|
$("#<%= dom_id(@budget_group) %>").html('<%= j render("admin/budgets/group", group: @budget_group, headings: @budget_group.headings) %>');
|
||||||
$("#heading-<%=@heading.id%> div#error_explanation").replaceWith("<%= j render("admin/budget_headings/errors", errors: @errors) %>");
|
|
||||||
<% else %>
|
|
||||||
$("#heading-<%=@heading.id%>").html("<td colspan='4'><%= j render("admin/budgets/heading", group: @budget_group, budget: @budget, heading: @heading) %></td>");
|
|
||||||
<% end %>
|
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
<%= link_to t("admin.actions.edit"),
|
<%= link_to t("admin.actions.edit"),
|
||||||
edit_admin_budget_budget_group_budget_heading_path(budget_id: group.budget.id, budget_group_id: group.id, id: heading.id),
|
edit_admin_budget_budget_group_budget_heading_path(budget_id: group.budget.id, budget_group_id: group.id, id: heading.id),
|
||||||
class: "button hollow",
|
class: "button hollow",
|
||||||
remote: true%>
|
remote: true %>
|
||||||
<%= link_to t("admin.budget_investments.index.title"),
|
<%= link_to t("admin.budget_investments.index.title"),
|
||||||
admin_budget_budget_investments_path(budget_id: group.budget.id, heading_id: heading.id),
|
admin_budget_budget_investments_path(budget_id: group.budget.id, heading_id: heading.id),
|
||||||
class: "button hollow"%>
|
class: "button hollow" %>
|
||||||
<% if heading.can_be_deleted? %>
|
<% if heading.can_be_deleted? %>
|
||||||
<%= link_to t('admin.administrators.administrator.delete'),
|
<%= link_to t('admin.administrators.administrator.delete'),
|
||||||
#admin_budget_budget_group_budget_headings_path(group.budget.id, group.id),
|
#admin_budget_budget_group_budget_headings_path(group.budget.id, group.id),
|
||||||
[:admin, group.budget, group, heading],
|
[:admin, group.budget, group, heading],
|
||||||
method: :delete,
|
method: :delete,
|
||||||
class: "button hollow alert"%>
|
class: "button hollow alert" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<%= form_for [:admin, budget, group, heading], remote: true do |f| %>
|
<%= form_for [:admin, budget, group, heading], remote: true do |f| %>
|
||||||
|
<%= render 'shared/errors', resource: heading %>
|
||||||
<label><%= t("admin.budgets.form.heading") %></label>
|
<label><%= t("admin.budgets.form.heading") %></label>
|
||||||
<%= f.text_field :name,
|
<%= f.text_field :name,
|
||||||
label: false,
|
label: false,
|
||||||
@@ -25,6 +26,4 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %>
|
<%= f.submit t("admin.budgets.form.save_heading"), class: "button success" %>
|
||||||
|
|
||||||
<div id="error_explanation"></div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -26,7 +26,7 @@ describe Budget::Heading do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "heading" do
|
describe "heading" do
|
||||||
it "can be deleted if not budget's investments associated" do
|
it "can be deleted if no budget's investments associated" do
|
||||||
heading1 = create(:budget_heading, group: group, name: 'name')
|
heading1 = create(:budget_heading, group: group, name: 'name')
|
||||||
heading2 = create(:budget_heading, group: group, name: 'name 2')
|
heading2 = create(:budget_heading, group: group, name: 'name 2')
|
||||||
|
|
||||||
@@ -34,7 +34,6 @@ describe Budget::Heading do
|
|||||||
|
|
||||||
expect(heading1.can_be_deleted?).to eq false
|
expect(heading1.can_be_deleted?).to eq false
|
||||||
expect(heading2.can_be_deleted?).to eq true
|
expect(heading2.can_be_deleted?).to eq true
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user