more extensive database seeds (in two languages) (closes foodcoops#277)

This commit is contained in:
wvengen 2014-04-08 13:11:06 +02:00
parent 8e04074cd3
commit 0e1cde9e2b
7 changed files with 444 additions and 27 deletions

View file

@ -224,7 +224,8 @@ class Article < ActiveRecord::Base
def uniqueness_of_name
matches = Article.where(name: name, supplier_id: supplier_id, deleted_at: deleted_at, type: type)
matches = matches.where.not(id: id) unless new_record?
if supplier.shared_sync_method.blank? or supplier.shared_sync_method == 'import'
# supplier should always be there - except, perhaps, on initialization (on seeding)
if supplier and (supplier.shared_sync_method.blank? or supplier.shared_sync_method == 'import')
errors.add :name, :taken if matches.any?
else
errors.add :name, :taken_with_unit if matches.where(unit: unit, unit_quantity: unit_quantity).any?