Changes suggested in the PR made

This commit is contained in:
iagirre
2018-01-10 13:13:05 +01:00
parent f7e96067b0
commit f0724ce13a
5 changed files with 19 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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