Rename contact name field and revert contact name specs

This commit is contained in:
Matt-Yorkley
2017-12-21 15:56:37 +00:00
committed by Rob Harrington
parent abb5adec43
commit 39f0c5b5b0
11 changed files with 56 additions and 20 deletions

View File

@@ -37,7 +37,9 @@ class UpdateAccountInvoices
if billable_periods.any?
oldest_enterprise = billable_periods.first.enterprise
address = oldest_enterprise.address.dup
first, _space, last = (oldest_enterprise.contact_name || "").partition(' ')
address.update_attributes(phone: oldest_enterprise.phone) if oldest_enterprise.phone.present?
address.update_attributes(firstname: first, lastname: last) if first.present? && last.present?
account_invoice.order.update_attributes(bill_address: address, ship_address: address)
end

View File

@@ -44,6 +44,11 @@
 
= f.label :sells, t('admin.enterprises.form.primary_details.any'), value: "any"
.row
.alpha.three.columns
= f.label :contact_name, t('.contact_name')
.omega.nine.columns
= f.text_field :contact_name, { placeholder: t('admin.enterprises.form.contact.name_placeholder')}
.row
.alpha.three.columns
= f.label :email_address, t('admin.enterprises.form.contact.email_address')

View File

@@ -1,3 +1,8 @@
.row
.alpha.three.columns
= f.label :contact_name, t('.name')
.omega.eight.columns
= f.text_field :contact_name, { placeholder: t('.name_placeholder') }
.row
.alpha.three.columns
= f.label :email_address, t('.email_address')

View File

@@ -10,6 +10,12 @@
%form{ name: 'contact', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('type',contact)" } }
.row.content
.small-12.medium-12.large-7.columns
.row
.small-12.columns.field
%label{ for: 'enterprise_contact' } {{'enterprise.registration.modal.steps.contact.contact_field' | t}}:
%input.chunky.small-12.columns{ id: 'enterprise_contact', name: 'contact_name', required: true, placeholder: "{{'enterprise.registration.modal.steps.contact.contact_field_placeholder' | t}}", ng: { model: 'enterprise.contact_name' } }
%span.error.small-12.columns{ ng: { show: "contact.contact_name.$error.required && submitted" } }
{{'enterprise.registration.modal.steps.contact.contact_field_required' | t}}
.row
.small-12.columns.field
%label{ for: 'enterprise_email_address' } {{'admin.enterprises.form.contact.email_address' | t}}:

View File

@@ -13,22 +13,11 @@ class RemoveEmailFromEnterprises < ActiveRecord::Migration
EnterpriseRole.reset_column_information
Enterprise.select([:id, :email, :owner_id]).each do |enterprise|
contact_user = Spree::User.find_by_email enterprise.email
unless contact_user
password = Devise.friendly_token.first(8)
contact_user = Spree::User.create(email: enterprise.email, password: password, password_confirmation: password)
contact_user.send_reset_password_instructions if contact_user.persisted?
end
unless contact_user.persisted?
contact_user = Spree::User.find enterprise.owner_id
end
manager = EnterpriseRole.find_or_initialize_by_user_id_and_enterprise_id(contact_user.id, enterprise.id)
manager.update_attribute :receives_notifications, true
update_enterprise_contact enterprise
end
remove_columns :enterprises, :email, :contact
remove_column :enterprises, :email
rename_column :enterprises, :contact, :contact_name
end
def down
@@ -37,7 +26,7 @@ class RemoveEmailFromEnterprises < ActiveRecord::Migration
EnterpriseRole.reset_column_information
add_column :enterprises, :email, :string
add_column :enterprises, :contact, :string
rename_column :enterprises, :contact_name, :contact
Enterprise.select(:id).each do |e|
manager = EnterpriseRole.find_by_enterprise_id_and_receives_notifications(e.id, true)
@@ -45,4 +34,22 @@ class RemoveEmailFromEnterprises < ActiveRecord::Migration
e.update_attribute :email, user.email
end
end
def update_enterprise_contact(enterprise)
contact_user = Spree::User.find_by_email(enterprise.email) || create_contact_user(enterprise)
unless contact_user.persisted?
contact_user = Spree::User.find enterprise.owner_id
end
manager = EnterpriseRole.find_or_initialize_by_user_id_and_enterprise_id(contact_user.id, enterprise.id)
manager.update_attribute :receives_notifications, true
end
def create_contact_user(enterprise)
password = Devise.friendly_token.first(8)
contact_user = Spree::User.create(email: enterprise.email, password: password, password_confirmation: password)
contact_user.send_reset_password_instructions if contact_user.persisted?
contact_user
end
end

View File

@@ -247,6 +247,7 @@ ActiveRecord::Schema.define(:version => 20170921065259) do
t.text "invoice_text"
t.boolean "display_invoice_logo", :default => false
t.boolean "allow_order_changes", :default => false, :null => false
t.string "contact_name"
end
add_index "enterprises", ["address_id"], :name => "index_enterprises_on_address_id"

View File

@@ -20,11 +20,11 @@ namespace :openfoodnetwork do
end
def enterprise_header
['name', 'description', 'long_description', 'is_primary_producer', 'is_distributor', 'phone', 'email', 'website', 'twitter', 'abn', 'acn', 'pickup_times', 'next_collection_at', 'distributor_info', 'visible', 'facebook', 'instagram', 'linkedin', 'address1', 'address2', 'city', 'zipcode', 'state', 'country']
['name', 'description', 'long_description', 'is_primary_producer', 'is_distributor', 'contact_name', 'phone', 'email', 'website', 'twitter', 'abn', 'acn', 'pickup_times', 'next_collection_at', 'distributor_info', 'visible', 'facebook', 'instagram', 'linkedin', 'address1', 'address2', 'city', 'zipcode', 'state', 'country']
end
def enterprise_row(enterprise)
[enterprise.name, enterprise.description, enterprise.long_description, enterprise.is_primary_producer, enterprise.is_distributor, enterprise.phone, enterprise.contact.email, enterprise.website, enterprise.twitter, enterprise.abn, enterprise.acn, enterprise.pickup_times, enterprise.next_collection_at, enterprise.distributor_info, enterprise.visible, enterprise.facebook, enterprise.instagram, enterprise.linkedin, enterprise.address.address1, enterprise.address.address2, enterprise.address.city, enterprise.address.zipcode, enterprise.address.state_name, enterprise.address.country.andand.name]
[enterprise.name, enterprise.description, enterprise.long_description, enterprise.is_primary_producer, enterprise.is_distributor, enterprise.contact_name, enterprise.phone, enterprise.email, enterprise.website, enterprise.twitter, enterprise.abn, enterprise.acn, enterprise.pickup_times, enterprise.next_collection_at, enterprise.distributor_info, enterprise.visible, enterprise.facebook, enterprise.instagram, enterprise.linkedin, enterprise.address.address1, enterprise.address.address2, enterprise.address.city, enterprise.address.zipcode, enterprise.address.state_name, enterprise.address.country.andand.name]
end
end
end

View File

@@ -20,7 +20,7 @@ module Api
let(:new_enterprise_params) do
{
enterprise: {
name: 'name', email: 'email@example.com', address_attributes: {
name: 'name', contact_name: 'Sheila', address_attributes: {
address1: '123 Abc Street',
city: 'Northcote',
zipcode: '3070',

View File

@@ -45,6 +45,7 @@ feature %q{
select2_search admin.email, from: 'Owner'
select2_search admin.email, from: 'Owner'
fill_in 'enterprise_contact_name', :with => 'Kirsten or Ren'
fill_in 'enterprise_phone', :with => '0413 897 321'
fill_in 'enterprise_email_address', :with => 'info@eaterprises.com.au'
fill_in 'enterprise_website', :with => 'http://eaterprises.com.au'
@@ -138,6 +139,7 @@ feature %q{
check "enterprise_shipping_method_ids_#{shipping_method.id}"
click_link "Contact"
fill_in 'enterprise_contact_name', :with => 'Kirsten or Ren'
fill_in 'enterprise_phone', :with => '0413 897 321'
fill_in 'enterprise_email_address', :with => 'info@eaterprises.com.au'
fill_in 'enterprise_website', :with => 'http://eaterprises.com.au'

View File

@@ -54,6 +54,7 @@ feature "Registration", js: true do
# Filling in Contact Details
fill_in 'enterprise_contact', with: 'Saskia Munroe'
page.should have_field 'enterprise_email_address', with: user.email
fill_in 'enterprise_phone', with: '12 3456 7890'
perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Last step to add My Awesome Enterprise!' })
@@ -68,6 +69,7 @@ feature "Registration", js: true do
expect(e.sells).to eq "unspecified"
expect(e.is_primary_producer).to eq true
expect(e.contact.id).to eq e.owner_id
expect(e.contact_name).to eq "Saskia Munroe"
# Filling in about
fill_in 'enterprise_description', with: 'Short description'

View File

@@ -157,7 +157,7 @@ describe UpdateAccountInvoices do
context "where the order is not complete" do
before do
allow(invoice_order).to receive(:complete?) { false }
june_billable_period1.enterprise.update_attributes(phone: '12345')
june_billable_period1.enterprise.update_attributes(contact_name: "Firstname Lastname Something Else", phone: '12345')
updater.update(june_account_invoice)
end
@@ -175,6 +175,8 @@ describe UpdateAccountInvoices do
[:address1, :address2, :city, :zipcode, :state_id, :country_id].each do |attr|
expect(invoice_order.billing_address[attr]).to eq june_billable_period1.enterprise.address[attr]
end
expect(invoice_order.billing_address.firstname).to eq "Firstname"
expect(invoice_order.billing_address.lastname).to eq "Lastname Something Else"
expect(invoice_order.billing_address.phone).to eq "12345"
end
@@ -352,7 +354,7 @@ describe UpdateAccountInvoices do
before do
Spree::Config.set({ accounts_distributor_id: accounts_distributor.id })
july_billable_period2.enterprise.update_attributes(phone: '3433523')
july_billable_period2.enterprise.update_attributes(contact_name: 'Anna Karenina', phone: '3433523')
end
context "when no invoice_order currently exists" do
@@ -375,6 +377,8 @@ describe UpdateAccountInvoices do
[:address1, :address2, :city, :zipcode, :state_id, :country_id].each do |attr|
expect(invoice_order.billing_address[attr]).to eq july_billable_period2.enterprise.address[attr]
end
expect(invoice_order.billing_address.firstname).to eq "Anna"
expect(invoice_order.billing_address.lastname).to eq "Karenina"
expect(invoice_order.billing_address.phone).to eq "3433523"
end
end
@@ -417,6 +421,8 @@ describe UpdateAccountInvoices do
[:address1, :address2, :city, :zipcode, :state_id, :country_id].each do |attr|
expect(invoice_order.billing_address[attr]).to eq july_billable_period2.enterprise.address[attr]
end
expect(invoice_order.billing_address.firstname).to eq "Anna"
expect(invoice_order.billing_address.lastname).to eq "Karenina"
expect(invoice_order.billing_address.phone).to eq "3433523"
end
end