Support form validation error for non signed in existing employee
This commit is contained in:
@@ -13,8 +13,8 @@ class NewSupplier
|
|||||||
validates :email, email: without_current_employee
|
validates :email, email: without_current_employee
|
||||||
validates :password, presence: without_current_employee, confirmation: without_current_employee
|
validates :password, presence: without_current_employee, confirmation: without_current_employee
|
||||||
|
|
||||||
validate :supplier_name_uniqueness
|
|
||||||
validate :employee_uniqueness_or_existence
|
validate :employee_uniqueness_or_existence
|
||||||
|
validate :supplier_name_uniqueness
|
||||||
|
|
||||||
def save
|
def save
|
||||||
if valid?
|
if valid?
|
||||||
@@ -49,8 +49,8 @@ class NewSupplier
|
|||||||
end
|
end
|
||||||
|
|
||||||
def supplier_name_uniqueness
|
def supplier_name_uniqueness
|
||||||
return unless current_employee.present? and supplier_name.present?
|
return unless (current_employee.present? || @employee.present?) and supplier_name.present?
|
||||||
current_suppliers = current_employee.suppliers
|
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
|
errors.add :supplier_name, 'You already have a supplier with that name' if current_suppliers.map(&:name).include? supplier_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,6 +38,15 @@ Feature: A supplier can sign up
|
|||||||
And fill in the supplier signup form with an existing supplier name
|
And fill in the supplier signup form with an existing supplier name
|
||||||
And click on the supplier signup submit button
|
And click on the supplier signup submit button
|
||||||
Then the new supplier signup for should have an error on 'supplier_name'
|
Then the new supplier signup for should have an error on 'supplier_name'
|
||||||
|
|
||||||
|
@javascript
|
||||||
|
Scenario: Existing non signed in employee creates existing supplier name
|
||||||
|
Given there is a confirmed and open supplier
|
||||||
|
When I visit the supplier signup path
|
||||||
|
And fill in the supplier signup form with existing employee credentials
|
||||||
|
And fill in the supplier signup form with an existing supplier name
|
||||||
|
And click on the supplier signup submit button
|
||||||
|
Then the new supplier signup for should have an error on 'supplier_name'
|
||||||
#Scenarios
|
#Scenarios
|
||||||
#- non existing non signed in employee
|
#- non existing non signed in employee
|
||||||
#- existing non signed in employee
|
#- existing non signed in employee
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
step 'there is a confirmed and open supplier' do
|
step 'there is a confirmed and open supplier' do
|
||||||
@supplier_password = 'secret1'
|
@supplier_password = 'secret1'
|
||||||
|
@employee_password = @supplier_password
|
||||||
@employee = create :employee, email: 'supplier@mozo.bar', password: @supplier_password
|
@employee = create :employee, email: 'supplier@mozo.bar', password: @supplier_password
|
||||||
@supplier = build :supplier, open: true
|
@supplier = build :supplier, open: true
|
||||||
@supplier.add_manager @employee
|
@supplier.add_manager @employee
|
||||||
|
|||||||
Reference in New Issue
Block a user