Removes use of slugs to edit group name
Changing a group’s `to_param` to return the slug instead of the id, breaks many tests in the user facing interface We should use slugs in upstream soon, but it should be done in a separate PR, bringing the whole slug implementation from Madrid’s fork and the corresponding test coverage
This commit is contained in:
@@ -3,13 +3,14 @@ class Admin::BudgetGroupsController < 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.groups.create(budget_group_params)
|
@budget.groups.create(budget_group_params)
|
||||||
@groups = @budget.groups.includes(:headings)
|
@groups = @budget.groups.includes(:headings)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@group = @budget.groups.by_slug(params[:id]).first
|
@budget = Budget.find(params[:budget_id])
|
||||||
|
@group = @budget.groups.find(params[:id])
|
||||||
@group.update(budget_group_params)
|
@group.update(budget_group_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -19,8 +20,4 @@ class Admin::BudgetGroupsController < Admin::BaseController
|
|||||||
params.require(:budget_group).permit(:name)
|
params.require(:budget_group).permit(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_budget
|
|
||||||
@budget = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id])
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,27 +10,15 @@ class Budget
|
|||||||
validates :name, presence: true, uniqueness: { scope: :budget }
|
validates :name, presence: true, uniqueness: { scope: :budget }
|
||||||
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
|
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
|
||||||
|
|
||||||
scope :by_slug, ->(slug) { where(slug: slug) }
|
|
||||||
|
|
||||||
before_save :strip_name
|
|
||||||
|
|
||||||
def to_param
|
|
||||||
slug
|
|
||||||
end
|
|
||||||
|
|
||||||
def single_heading_group?
|
def single_heading_group?
|
||||||
headings.count == 1
|
headings.count == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_slug?
|
|
||||||
slug.nil? || budget.drafting?
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def strip_name
|
def generate_slug?
|
||||||
self.name = self.name.strip
|
slug.nil? || budget.drafting?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user