From fd871639b9713ad8ea05a78f40700368ae8cdadd Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Tue, 24 Feb 2015 18:18:55 +0100 Subject: [PATCH] Add error on existing supplier name for current employee --- app/services/new_supplier.rb | 2 +- spec/acceptance/suppliers/signup.feature | 9 +++++++++ spec/acceptance_steps/suppliers/signup_steps.rb | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/services/new_supplier.rb b/app/services/new_supplier.rb index 63df4f2c..89ab48e2 100644 --- a/app/services/new_supplier.rb +++ b/app/services/new_supplier.rb @@ -51,6 +51,6 @@ class NewSupplier def supplier_name_uniqueness return unless current_employee.present? and supplier_name.present? 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 diff --git a/spec/acceptance/suppliers/signup.feature b/spec/acceptance/suppliers/signup.feature index 68ad3738..eb5440bf 100644 --- a/spec/acceptance/suppliers/signup.feature +++ b/spec/acceptance/suppliers/signup.feature @@ -29,6 +29,15 @@ Feature: A supplier can sign up And I wait 1 second Then a new supplier with the existing employee should be created 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 #- non existing non signed in employee #- existing non signed in employee diff --git a/spec/acceptance_steps/suppliers/signup_steps.rb b/spec/acceptance_steps/suppliers/signup_steps.rb index 8649f70c..a72fe593 100644 --- a/spec/acceptance_steps/suppliers/signup_steps.rb +++ b/spec/acceptance_steps/suppliers/signup_steps.rb @@ -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' 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 find('[name="commit"]').click end @@ -59,3 +63,7 @@ step "the new signup supplier should be confirmed" do @signup_supplier.reload @signup_supplier.should be_confirmed end + +step "the new supplier signup for should have an error on :attribute" do |attribute| + page.should have_selector ".#{attribute}.error" +end