Add error on existing supplier name for current employee
This commit is contained in:
@@ -51,6 +51,6 @@ class NewSupplier
|
|||||||
def supplier_name_uniqueness
|
def supplier_name_uniqueness
|
||||||
return unless current_employee.present? and supplier_name.present?
|
return unless current_employee.present? and supplier_name.present?
|
||||||
current_suppliers = current_employee.suppliers
|
current_suppliers = current_employee.suppliers
|
||||||
errors.add :base, '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
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ Feature: A supplier can sign up
|
|||||||
And I wait 1 second
|
And I wait 1 second
|
||||||
Then a new supplier with the existing employee should be created
|
Then a new supplier with the existing employee should be created
|
||||||
And the supplier should be redirected to the supplier '/pages/introduction' path
|
And the supplier should be redirected to the supplier '/pages/introduction' path
|
||||||
|
|
||||||
|
@javascript
|
||||||
|
Scenario: Existing signed in employee creates existing supplier name
|
||||||
|
Given there is a confirmed and open supplier
|
||||||
|
And I am signed in as supplier
|
||||||
|
When I visit the supplier signup path
|
||||||
|
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
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ step "fill in the supplier signup form with a new supplier name" do
|
|||||||
js_set_field '#new_supplier_supplier_name', 'Signup Supplier'
|
js_set_field '#new_supplier_supplier_name', 'Signup Supplier'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
step "fill in the supplier signup form with an existing supplier name" do
|
||||||
|
js_set_field '#new_supplier_supplier_name', @supplier.name
|
||||||
|
end
|
||||||
|
|
||||||
step "click on the supplier signup submit button" do
|
step "click on the supplier signup submit button" do
|
||||||
find('[name="commit"]').click
|
find('[name="commit"]').click
|
||||||
end
|
end
|
||||||
@@ -59,3 +63,7 @@ step "the new signup supplier should be confirmed" do
|
|||||||
@signup_supplier.reload
|
@signup_supplier.reload
|
||||||
@signup_supplier.should be_confirmed
|
@signup_supplier.should be_confirmed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
step "the new supplier signup for should have an error on :attribute" do |attribute|
|
||||||
|
page.should have_selector ".#{attribute}.error"
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user