Fix signed in employee adding supplier functionality

This commit is contained in:
2015-02-24 18:07:44 +01:00
parent cb723ea432
commit db72cd06aa
5 changed files with 18 additions and 3 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ class Employee
end end
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 devise :database_authenticatable, :recoverable, :rememberable, :trackable #, :registerable #, :confirmable
property :unconfirmed_email property :unconfirmed_email
+2
View File
@@ -28,6 +28,7 @@ class NewSupplier
private private
def persist! def persist!
@employee ||= current_employee
@employee ||= Employee.new email: email, password: password, password_confirmation: password_confirmation @employee ||= Employee.new email: email, password: password, password_confirmation: password_confirmation
raise "Cannot create employee with #{attributes.inspect}" unless employee.save raise "Cannot create employee with #{attributes.inspect}" unless employee.save
@supplier = Supplier.create name: supplier_name @supplier = Supplier.create name: supplier_name
@@ -36,6 +37,7 @@ class NewSupplier
def employee_uniqueness_or_existence def employee_uniqueness_or_existence
return if current_employee.present? return if current_employee.present?
return if @employee = current_employee
if Employee.count_by_email(email) > 0 if Employee.count_by_email(email) > 0
employee = Employee.find_by_email(email) employee = Employee.find_by_email(email)
if employee.valid_password? password if employee.valid_password? password
+10 -1
View File
@@ -19,7 +19,16 @@ Feature: A supplier can sign up
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 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 #Scenarios
#- non existing non signed in employee #- non existing non signed in employee
#- existing non signed in employee #- existing non signed in employee
@@ -1,6 +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 = 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 = build :supplier, open: true
@supplier.add_manager @employee @supplier.add_manager @employee
@section = create :section, title: 'Room', supplier: @supplier, width: 8, height: 8 @section = create :section, title: 'Room', supplier: @supplier, width: 8, height: 8
@@ -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 js_set_field '#new_supplier_password_confirmation', @employee_password
end 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 step "click on the supplier signup submit button" do
find('[name="commit"]').click find('[name="commit"]').click
end end