Support form validation error for non signed in existing employee

This commit is contained in:
2015-02-24 18:25:46 +01:00
parent fd871639b9
commit 6a47ecb0eb
3 changed files with 13 additions and 3 deletions
+3 -3
View File
@@ -13,8 +13,8 @@ class NewSupplier
validates :email, email: without_current_employee
validates :password, presence: without_current_employee, confirmation: without_current_employee
validate :supplier_name_uniqueness
validate :employee_uniqueness_or_existence
validate :supplier_name_uniqueness
def save
if valid?
@@ -49,8 +49,8 @@ class NewSupplier
end
def supplier_name_uniqueness
return unless current_employee.present? and supplier_name.present?
current_suppliers = current_employee.suppliers
return unless (current_employee.present? || @employee.present?) and supplier_name.present?
current_suppliers = (current_employee || @employee).suppliers
errors.add :supplier_name, 'You already have a supplier with that name' if current_suppliers.map(&:name).include? supplier_name
end
end