Added interface and methods for edit the name of a Budget::Group if the budget is still inthe drafting phase

This commit is contained in:
Raúl Fuentes
2018-02-13 13:51:47 +01:00
committed by Bertocq
parent 089cef8ead
commit 6d8d44a5e3
10 changed files with 62 additions and 19 deletions

View File

@@ -10,14 +10,27 @@ class Budget
validates :name, presence: true, uniqueness: { scope: :budget }
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?
headings.count == 1
end
private
def generate_slug?
slug.nil? || budget.drafting?
end
private
def strip_name
self.name = self.name.strip
end
end
end