normalize article and category attributes (closes foodcoops#294)

This commit is contained in:
wvengen 2014-06-06 16:41:01 +02:00
parent 7c2ecd8658
commit a43020463d
5 changed files with 18 additions and 0 deletions

View file

@ -45,6 +45,8 @@ class Article < ActiveRecord::Base
# Replace numeric seperator with database format
localize_input_of :price, :tax, :deposit
# Get rid of unwanted whitespace. {Unit#new} may even bork on whitespace.
normalize_attributes :name, :unit, :note, :manufacturer, :origin, :order_number
scope :undeleted, -> { where(deleted_at: nil) }
scope :available, -> { undeleted.where(availability: true) }

View file

@ -10,6 +10,8 @@ class ArticleCategory < ActiveRecord::Base
# @return [Array<Article>] Articles with this category.
has_many :articles
normalize_attributes :name, :description
validates :name, :presence => true, :uniqueness => true, :length => { :in => 2..20 }
before_destroy :check_for_associated_articles