diff --git a/app/models/employee.rb b/app/models/employee.rb index 15d6b785..46c359da 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -15,7 +15,7 @@ class Employee end end - view :by_confirmation_token, key: :confirmation_token # devise confirmable + #view :by_confirmation_token, key: :confirmation_token # devise confirmable devise :database_authenticatable, :recoverable, :rememberable, :trackable #, :registerable #, :confirmable property :unconfirmed_email diff --git a/app/services/new_supplier.rb b/app/services/new_supplier.rb index d5053769..63df4f2c 100644 --- a/app/services/new_supplier.rb +++ b/app/services/new_supplier.rb @@ -28,6 +28,7 @@ class NewSupplier private def persist! + @employee ||= current_employee @employee ||= Employee.new email: email, password: password, password_confirmation: password_confirmation raise "Cannot create employee with #{attributes.inspect}" unless employee.save @supplier = Supplier.create name: supplier_name @@ -36,6 +37,7 @@ class NewSupplier def employee_uniqueness_or_existence return if current_employee.present? + return if @employee = current_employee if Employee.count_by_email(email) > 0 employee = Employee.find_by_email(email) if employee.valid_password? password diff --git a/spec/acceptance/suppliers/signup.feature b/spec/acceptance/suppliers/signup.feature index 0220b135..68ad3738 100644 --- a/spec/acceptance/suppliers/signup.feature +++ b/spec/acceptance/suppliers/signup.feature @@ -19,7 +19,16 @@ Feature: A supplier can sign up 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 new supplier + 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 a new supplier name + And click on the supplier signup submit button + 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 #Scenarios #- non existing non signed in employee #- existing non signed in employee diff --git a/spec/acceptance_steps/suppliers/existance_steps.rb b/spec/acceptance_steps/suppliers/existance_steps.rb index 58de4ef9..30709d5c 100644 --- a/spec/acceptance_steps/suppliers/existance_steps.rb +++ b/spec/acceptance_steps/suppliers/existance_steps.rb @@ -1,6 +1,6 @@ step 'there is a confirmed and open supplier' do @supplier_password = 'secret1' - @employee = create :employee, email: 'supplier@mozo.bar', password: @supplier_password, confirmation_token: 'abc', confirmed_at: Time.now.utc + @employee = create :employee, email: 'supplier@mozo.bar', password: @supplier_password @supplier = build :supplier, open: true @supplier.add_manager @employee @section = create :section, title: 'Room', supplier: @supplier, width: 8, height: 8 diff --git a/spec/acceptance_steps/suppliers/signup_steps.rb b/spec/acceptance_steps/suppliers/signup_steps.rb index 0ef35eb1..8649f70c 100644 --- a/spec/acceptance_steps/suppliers/signup_steps.rb +++ b/spec/acceptance_steps/suppliers/signup_steps.rb @@ -16,6 +16,10 @@ step "fill in the supplier signup form with existing employee credentials" do js_set_field '#new_supplier_password_confirmation', @employee_password end +step "fill in the supplier signup form with a new supplier name" do + js_set_field '#new_supplier_supplier_name', 'Signup Supplier' +end + step "click on the supplier signup submit button" do find('[name="commit"]').click end