From ba98c7e2c5ed2db1c449244d4ce6072ae7e7cb63 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley Date: Fri, 28 Jul 2017 17:03:00 +0100 Subject: [PATCH] Rewrite enterprise contact functionality --- .../enterprise_controller.js.coffee | 1 - .../enterprise_registration_service.js.coffee | 1 - app/controllers/api/enterprises_controller.rb | 5 +++ app/jobs/update_account_invoices.rb | 2 - app/mailers/enterprise_mailer.rb | 2 +- app/mailers/producer_mailer.rb | 6 +-- app/mailers/spree/order_mailer_decorator.rb | 6 +-- app/models/enterprise.rb | 14 +++---- app/models/spree/user_decorator.rb | 1 + .../api/admin/enterprise_serializer.rb | 5 ++- .../admin/enterprises/_new_form.html.haml | 5 --- .../admin/enterprises/form/_contact.html.haml | 7 +--- .../admin/enterprises/form/_users.html.haml | 37 ++++++++++--------- app/views/enterprise_mailer/welcome.html.haml | 2 +- .../order_cycle_report.html.haml | 2 +- .../order_cycle_report.text.haml | 2 +- .../registration/steps/_contact.html.haml | 10 +---- .../registration/steps/_finished.html.haml | 4 -- .../spree/admin/orders/invoice.html.haml | 2 +- app/views/spree/admin/orders/ticket.html.haml | 2 +- .../spree/order_mailer/_signoff.html.haml | 6 +-- .../confirm_email_for_shop.html.haml | 4 +- .../orders/order_cycle_expired.html.haml | 2 +- config/locales/en.yml | 5 ++- lib/tasks/enterprises.rake | 4 +- .../admin/enterprises_controller_spec.rb | 2 +- spec/factories.rb | 1 - spec/features/admin/enterprises_spec.rb | 2 - spec/features/consumer/registration_spec.rb | 4 +- spec/jobs/update_account_invoices_spec.rb | 10 +---- spec/mailers/order_mailer_spec.rb | 4 +- spec/mailers/producer_mailer_spec.rb | 8 ++-- spec/models/enterprise_spec.rb | 19 +++++----- 33 files changed, 83 insertions(+), 104 deletions(-) diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index 54aae74cc3..43ecc7ac0c 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -4,7 +4,6 @@ angular.module("admin.enterprises") $scope.PaymentMethods = EnterprisePaymentMethods.paymentMethods $scope.ShippingMethods = EnterpriseShippingMethods.shippingMethods $scope.navClear = NavigationCheck.clear - $scope.pristineEmail = $scope.Enterprise.email $scope.menu = SideMenu $scope.newManager = { id: '', email: (t('add_manager')) } diff --git a/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee b/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee index 25ec644a66..dc9f6617ee 100644 --- a/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee @@ -2,7 +2,6 @@ Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService, new class EnterpriseRegistrationService enterprise: user_ids: [CurrentUser.id] - email: CurrentUser.email email_address: CurrentUser.email address: {} country: availableCountries[0] diff --git a/app/controllers/api/enterprises_controller.rb b/app/controllers/api/enterprises_controller.rb index c1f6fb3ce7..2971e648b6 100644 --- a/app/controllers/api/enterprises_controller.rb +++ b/app/controllers/api/enterprises_controller.rb @@ -2,6 +2,7 @@ module Api class EnterprisesController < Spree::Api::BaseController before_filter :override_owner, only: [:create, :update] + before_filter :set_contact, only: [:create] before_filter :check_type, only: :update before_filter :override_sells, only: [:create, :update] before_filter :override_visible, only: [:create, :update] @@ -53,6 +54,10 @@ module Api params[:enterprise][:owner_id] = current_api_user.id end + def set_contact + params[:enterprise][:contact_id] = current_api_user.id + end + def check_type params[:enterprise].delete :type unless current_api_user.admin? end diff --git a/app/jobs/update_account_invoices.rb b/app/jobs/update_account_invoices.rb index 669c708757..f042ddb9ef 100644 --- a/app/jobs/update_account_invoices.rb +++ b/app/jobs/update_account_invoices.rb @@ -37,9 +37,7 @@ class UpdateAccountInvoices if billable_periods.any? oldest_enterprise = billable_periods.first.enterprise address = oldest_enterprise.address.dup - first, _space, last = (oldest_enterprise.contact || "").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 diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb index 6ce24e320e..350a247d73 100644 --- a/app/mailers/enterprise_mailer.rb +++ b/app/mailers/enterprise_mailer.rb @@ -7,7 +7,7 @@ class EnterpriseMailer < Spree::BaseMailer subject = t('enterprise_mailer.welcome.subject', enterprise: @enterprise.name, sitename: Spree::Config[:site_name]) - mail(:to => enterprise.email, + mail(:to => enterprise.contact.email, :from => from_address, :subject => subject) end diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index a66c2cada1..70690970af 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -13,11 +13,11 @@ class ProducerMailer < Spree::BaseMailer subject = "[#{Spree::Config.site_name}] #{I18n.t('producer_mailer.order_cycle.subject', producer: producer.name)}" if has_orders? order_cycle, producer - mail(to: @producer.email, + mail(to: @producer.contact.email, from: from_address, subject: subject, - reply_to: @coordinator.email, - cc: @coordinator.email) + reply_to: @coordinator.contact.email, + cc: @coordinator.contact.email) end end diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb index 13f014d5a0..a4b2db8b70 100644 --- a/app/mailers/spree/order_mailer_decorator.rb +++ b/app/mailers/spree/order_mailer_decorator.rb @@ -17,14 +17,14 @@ Spree::OrderMailer.class_eval do mail(:to => @order.email, :from => from_address, :subject => subject, - :reply_to => @order.distributor.email) + :reply_to => @order.distributor.contact.email) end def confirm_email_for_shop(order, resend = false) find_order(order) # Finds an order instance from an id subject = (resend ? "[#{t(:resend).upcase}] " : '') subject += "#{Spree::Config[:site_name]} #{t('order_mailer.confirm_email.subject')} ##{@order.number}" - mail(:to => @order.distributor.email, + mail(:to => @order.distributor.contact.email, :from => from_address, :subject => subject) end @@ -36,7 +36,7 @@ Spree::OrderMailer.class_eval do mail(:to => @order.email, :from => from_address, :subject => subject, - :reply_to => @order.distributor.email) + :reply_to => @order.distributor.contact.email) end def find_order(order) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 3d0f674666..37539dff23 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -33,6 +33,7 @@ class Enterprise < ActiveRecord::Base has_many :enterprise_roles, :dependent => :destroy has_many :users, through: :enterprise_roles belongs_to :owner, class_name: 'Spree::User', foreign_key: :owner_id, inverse_of: :owned_enterprises + belongs_to :contact, class_name: 'Spree::User', foreign_key: :contact_id, inverse_of: :contact_enterprises has_and_belongs_to_many :payment_methods, join_table: 'distributors_payment_methods', class_name: 'Spree::PaymentMethod', foreign_key: 'distributor_id' has_many :distributor_shipping_methods, foreign_key: :distributor_id has_many :shipping_methods, through: :distributor_shipping_methods @@ -69,7 +70,6 @@ class Enterprise < ActiveRecord::Base validate :name_is_unique validates :sells, presence: true, inclusion: {in: SELLS} validates :address, presence: true, associated: true - validates :email, presence: true validates_presence_of :owner validates :permalink, uniqueness: true, presence: true validate :shopfront_taxons @@ -78,11 +78,11 @@ class Enterprise < ActiveRecord::Base before_validation :initialize_permalink, if: lambda { permalink.nil? } before_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? && !owner_id.nil? } - before_validation :ensure_email_set before_validation :set_unused_address_fields after_validation :geocode_address after_touch :touch_distributors + before_create :set_default_contact after_create :relate_to_owners_enterprises after_create :send_welcome_email @@ -179,7 +179,7 @@ class Enterprise < ActiveRecord::Base end def activated? - owner.confirmed? && sells != 'unspecified' + contact.confirmed? && sells != 'unspecified' end def set_producer_property(property_name, property_value) @@ -377,16 +377,16 @@ class Enterprise < ActiveRecord::Base users << owner unless users.include?(owner) || owner.admin? end - def ensure_email_set - self.email = owner.email if email.blank? && owner.present? - end - def enforce_ownership_limit unless owner.can_own_more_enterprises? errors.add(:owner, I18n.t(:enterprise_owner_error, email: owner.email, enterprise_limit: owner.enterprise_limit )) end end + def set_default_contact + self.contact_id = self.owner_id if self.contact_id.nil? + end + def relate_to_owners_enterprises # When a new producer is created, it grants permissions to all pre-existing hubs # When a new hub is created, diff --git a/app/models/spree/user_decorator.rb b/app/models/spree/user_decorator.rb index 092afa0f6b..92a020d20e 100644 --- a/app/models/spree/user_decorator.rb +++ b/app/models/spree/user_decorator.rb @@ -6,6 +6,7 @@ Spree.user_class.class_eval do has_many :enterprise_roles, :dependent => :destroy has_many :enterprises, through: :enterprise_roles has_many :owned_enterprises, class_name: 'Enterprise', foreign_key: :owner_id, inverse_of: :owner + has_many :contact_enterprises, class_name: 'Enterprise', foreign_key: :contact_id, inverse_of: :contact has_many :owned_groups, class_name: 'EnterpriseGroup', foreign_key: :owner_id, inverse_of: :owner has_many :account_invoices has_many :billable_periods, foreign_key: :owner_id, inverse_of: :owner diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index c9b4c50aa1..20592c43de 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -1,12 +1,13 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category, :payment_method_ids, :shipping_method_ids - attributes :producer_profile_only, :email, :long_description, :permalink + attributes :producer_profile_only, :long_description, :permalink attributes :preferred_shopfront_message, :preferred_shopfront_closed_message, :preferred_shopfront_taxon_order, :preferred_shopfront_order_cycle_order attributes :preferred_product_selection_from_inventory_only - attributes :owner, :users, :tag_groups, :default_tag_group + attributes :owner, :contact, :users, :tag_groups, :default_tag_group attributes :require_login, :allow_guest_orders, :allow_order_changes has_one :owner, serializer: Api::Admin::UserSerializer + has_one :contact, serializer: Api::Admin::UserSerializer has_many :users, serializer: Api::Admin::UserSerializer def tag_groups diff --git a/app/views/admin/enterprises/_new_form.html.haml b/app/views/admin/enterprises/_new_form.html.haml index f04e55acd6..3ca2c6c8a9 100644 --- a/app/views/admin/enterprises/_new_form.html.haml +++ b/app/views/admin/enterprises/_new_form.html.haml @@ -44,11 +44,6 @@   = f.label :sells, t('admin.enterprises.form.primary_details.any'), value: "any" -.row - .alpha.three.columns - = f.label :contact, t('.contact_name') - .omega.nine.columns - = f.text_field :contact, { placeholder: t('admin.enterprises.form.contact.name_placeholder')} .row .alpha.three.columns = f.label :email_address, t('admin.enterprises.form.contact.email_address') diff --git a/app/views/admin/enterprises/form/_contact.html.haml b/app/views/admin/enterprises/form/_contact.html.haml index 1a7fa792f1..12b0c562c0 100644 --- a/app/views/admin/enterprises/form/_contact.html.haml +++ b/app/views/admin/enterprises/form/_contact.html.haml @@ -1,11 +1,8 @@ -.row - .alpha.three.columns - = f.label :contact, t('.name') - .omega.eight.columns - = f.text_field :contact, { placeholder: t('.name_placeholder') } .row .alpha.three.columns = f.label :email_address, t('.email_address') + %div{'ofn-with-tip' => t('.email_address_tip')} + %a= t('admin.whats_this') .omega.eight.columns = f.text_field :email_address, { placeholder: t('.email_address_placeholder') } .row diff --git a/app/views/admin/enterprises/form/_users.html.haml b/app/views/admin/enterprises/form/_users.html.haml index eb0081a923..7d0e137509 100644 --- a/app/views/admin/enterprises/form/_users.html.haml +++ b/app/views/admin/enterprises/form/_users.html.haml @@ -14,23 +14,26 @@ - else = owner_email -.row - .three.columns.alpha - = f.label :email, t('.notifications') - - if full_permissions - %span.required * - .with-tip{'data-powertip' => t('.notifications_tip')} - %a= t('admin.whats_this') - .eight.columns.omega - - if full_permissions - = f.text_field :email, { placeholder: t('.notifications_placeholder'), "ng-model" => "Enterprise.email" } - - else - = @enterprise.email -.row{ ng: { hide: "pristineEmail == null || pristineEmail == Enterprise.email"} } - .alpha.three.columns -   - .omega.eight.columns - = t('.notifications_note') + +-# TODO: add contact field, possibly re-use some of these tooltip keys + +-#.row +-# .three.columns.alpha +-# = f.label :email, t('.notifications') +-# - if full_permissions +-# %span.required * +-# .with-tip{'data-powertip' => t('.notifications_tip')} +-# %a= t('admin.whats_this') +-# .eight.columns.omega +-# - if full_permissions +-# = f.text_field :email, { placeholder: t('.notifications_placeholder'), "ng-model" => "Enterprise.email" } +-# - else +-# = @enterprise.email +-#.row{ ng: { hide: "pristineEmail == null || pristineEmail == Enterprise.email"} } +-# .alpha.three.columns +-#   +-# .omega.eight.columns +-# = t('.notifications_note') .row .three.columns.alpha diff --git a/app/views/enterprise_mailer/welcome.html.haml b/app/views/enterprise_mailer/welcome.html.haml index ad4a53a297..d929c1167b 100644 --- a/app/views/enterprise_mailer/welcome.html.haml +++ b/app/views/enterprise_mailer/welcome.html.haml @@ -1,5 +1,5 @@ %h3 - = "#{t(:email_welcome)}, #{@enterprise.contact}!" + = "#{t(:email_welcome)}!" %p.lead = t :email_confirmed %strong diff --git a/app/views/producer_mailer/order_cycle_report.html.haml b/app/views/producer_mailer/order_cycle_report.html.haml index b69dde8e66..cc78f43ecd 100644 --- a/app/views/producer_mailer/order_cycle_report.html.haml +++ b/app/views/producer_mailer/order_cycle_report.html.haml @@ -71,4 +71,4 @@ %p #{@coordinator.phone} %p - #{@coordinator.email} + #{@coordinator.contact.email} diff --git a/app/views/producer_mailer/order_cycle_report.text.haml b/app/views/producer_mailer/order_cycle_report.text.haml index 1fd956a795..c322c3cac5 100644 --- a/app/views/producer_mailer/order_cycle_report.text.haml +++ b/app/views/producer_mailer/order_cycle_report.text.haml @@ -24,4 +24,4 @@ Orders summary #{@coordinator.name} #{@coordinator.address.address1}, #{@coordinator.address.city}, #{@coordinator.address.zipcode} #{@coordinator.phone} -#{@coordinator.email} +#{@coordinator.contact.email} diff --git a/app/views/registration/steps/_contact.html.haml b/app/views/registration/steps/_contact.html.haml index dd282f4ca3..cf8bb510a8 100644 --- a/app/views/registration/steps/_contact.html.haml +++ b/app/views/registration/steps/_contact.html.haml @@ -12,14 +12,8 @@ .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', required: true, placeholder: "{{'enterprise.registration.modal.steps.contact.contact_field_placeholder' | t}}", ng: { model: 'enterprise.contact' } } - %span.error.small-12.columns{ ng: { show: "contact.contact.$error.required && submitted" } } - {{'enterprise.registration.modal.steps.contact.contact_field_required' | t}} - .row - .small-12.columns.field - %label{ for: 'enterprise_email_address' } {{'enterprise.registration.modal.steps.contact.email_field' | t}}: - %input.chunky.small-12.columns{ id: 'enterprise_email_address', name: 'email_address', type: 'email', placeholder: "{{'enterprise.registration.modal.steps.contact.email_field_placeholder' | t}}", ng: { model: 'enterprise.email_address' } } + %label{ for: 'enterprise_email_address' } {{'admin.enterprises.form.contact.email_address' | t}}: + %input.chunky.small-12.columns{ id: 'enterprise_email_address', name: 'email_address', type: 'email', placeholder: t('admin.enterprises.form.contact.email_address_placeholder'), ng: { model: 'enterprise.email_address' } } .row .small-12.columns.field %label{ for: 'enterprise_phone' } {{'enterprise.registration.modal.steps.contact.phone_field' | t}}: diff --git a/app/views/registration/steps/_finished.html.haml b/app/views/registration/steps/_finished.html.haml index bae5397a29..96ed600147 100644 --- a/app/views/registration/steps/_finished.html.haml +++ b/app/views/registration/steps/_finished.html.haml @@ -9,8 +9,4 @@ %p {{'registration_finished_login' | t}} .row .small-12.columns.text-center - %h4{ "ng-bind" => "'registration_finished_activate' | t:{enterprise: enterprise.name}" } - - %p{ "ng-bind-html" => "'registration_finished_activate_instruction_html' | t:{email: enterprise.email}"} - %a.button.primary{ type: "button", href: "/" } {{'registration_finished_action' | t}} > diff --git a/app/views/spree/admin/orders/invoice.html.haml b/app/views/spree/admin/orders/invoice.html.haml index 8c359d19da..0982ccc21f 100644 --- a/app/views/spree/admin/orders/invoice.html.haml +++ b/app/views/spree/admin/orders/invoice.html.haml @@ -25,7 +25,7 @@ %br = @order.distributor.address.full_address %br - = @order.distributor.email + = @order.distributor.contact.email %td{width: "10%" }   %td{ :align => "right" } diff --git a/app/views/spree/admin/orders/ticket.html.haml b/app/views/spree/admin/orders/ticket.html.haml index 22e9799754..b0cd4ecc7a 100644 --- a/app/views/spree/admin/orders/ticket.html.haml +++ b/app/views/spree/admin/orders/ticket.html.haml @@ -18,7 +18,7 @@ '\x0A', '#{j(@order.distributor.address.address_part1)}' + '\x0A', // text and line break '#{j(@order.distributor.address.address_part2)}' + '\x0A', - '#{j(@order.distributor.email)}' + '\x0A', + '#{j(@order.distributor.contact.email)}' + '\x0A', '\x0A', // line break '\x1B' + '\x61' + '\x32', // right align '#{j(l(Time.zone.now.to_date))}' + '\x0A', diff --git a/app/views/spree/order_mailer/_signoff.html.haml b/app/views/spree/order_mailer/_signoff.html.haml index 669cf4b9ad..53df2fa30b 100644 --- a/app/views/spree/order_mailer/_signoff.html.haml +++ b/app/views/spree/order_mailer/_signoff.html.haml @@ -2,14 +2,14 @@ %p.callout = t :email_confirm_customer_signoff %br - #{@order.distributor.contact} + #{@order.distributor.contact_name} %br %br = @order.distributor.name %br = @order.distributor.phone || "" %br - %a{:href => "mailto:#{@order.distributor.email}", :target => "_blank"} - = @order.distributor.email + %a{:href => "mailto:#{@order.distributor.contact.email}", :target => "_blank"} + = @order.distributor.contact.email %br = @order.distributor.website || "" diff --git a/app/views/spree/order_mailer/confirm_email_for_shop.html.haml b/app/views/spree/order_mailer/confirm_email_for_shop.html.haml index 5799f1e5c2..3a0df14697 100644 --- a/app/views/spree/order_mailer/confirm_email_for_shop.html.haml +++ b/app/views/spree/order_mailer/confirm_email_for_shop.html.haml @@ -4,8 +4,8 @@ %table.column{:align => "left"} %tr %td - %h3 - = t :email_confirm_shop_greeting, name: @order.distributor.contact + %h3 + = t :email_confirm_shop_greeting, name: @order.distributor.contact_name %h4 = t :email_confirm_shop_order_html, distributor: @order.distributor.name %table.column{:align => "left"} diff --git a/app/views/spree/orders/order_cycle_expired.html.haml b/app/views/spree/orders/order_cycle_expired.html.haml index 66bb134b7a..6f69341794 100644 --- a/app/views/spree/orders/order_cycle_expired.html.haml +++ b/app/views/spree/orders/order_cycle_expired.html.haml @@ -10,7 +10,7 @@ %p %strong = t :orders_oc_expired_email - = current_distributor.email + = current_distributor.contact.email %br/ %strong = t :orders_oc_expired_phone diff --git a/config/locales/en.yml b/config/locales/en.yml index a829c7bb0e..b566878a54 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -444,8 +444,9 @@ en: contact: name: Name name_placeholder: eg. Gustav Plum - email_address: Email Address - email_address_placeholder: eg. gustav@truffles.com + email_address: Public Email Address + email_address_placeholder: eg. inquiries@fresh-food.com + email_address_tip: "This email address will be displayed in your public profile" phone: Phone phone_placeholder: eg. 98 7654 3210 website: Website diff --git a/lib/tasks/enterprises.rake b/lib/tasks/enterprises.rake index c9206b3bd1..f974e4875e 100644 --- a/lib/tasks/enterprises.rake +++ b/lib/tasks/enterprises.rake @@ -20,11 +20,11 @@ namespace :openfoodnetwork do end def enterprise_header - ['name', 'description', 'long_description', 'is_primary_producer', 'is_distributor', 'contact', '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', '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.contact, 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] + [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] end end end diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index e8af9f5864..c592fce4f3 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -20,7 +20,7 @@ module Admin describe "creating an enterprise" do let(:country) { Spree::Country.find_by_name 'Australia' } let(:state) { Spree::State.find_by_name 'Victoria' } - let(:enterprise_params) { {enterprise: {name: 'zzz', permalink: 'zzz', is_primary_producer: '0', email: "bob@example.com", address_attributes: {address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id}}} } + let(:enterprise_params) { {enterprise: {name: 'zzz', permalink: 'zzz', is_primary_producer: '0', address_attributes: {address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id}}} } it "grants management permission if the current user is an enterprise user" do controller.stub spree_current_user: distributor_manager diff --git a/spec/factories.rb b/spec/factories.rb index 603e48d351..600d0aaa65 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -152,7 +152,6 @@ FactoryGirl.define do sells 'any' description 'enterprise' long_description '

Hello, world!

This is a paragraph.

' - email 'enterprise@example.com' address { FactoryGirl.create(:address) } end diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index d50cffd80f..d0c537731a 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -45,7 +45,6 @@ feature %q{ select2_search admin.email, from: 'Owner' select2_search admin.email, from: 'Owner' - fill_in 'enterprise_contact', :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' @@ -139,7 +138,6 @@ feature %q{ check "enterprise_shipping_method_ids_#{shipping_method.id}" click_link "Contact" - fill_in 'enterprise_contact', :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' diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index a70510aa7c..a192b672c2 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -54,7 +54,6 @@ 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,7 +67,7 @@ feature "Registration", js: true do expect(e.address.address1).to eq "123 Abc Street" expect(e.sells).to eq "unspecified" expect(e.is_primary_producer).to eq true - expect(e.contact).to eq "Saskia Munroe" + expect(e.contact_id).to eq e.owner_id # Filling in about fill_in 'enterprise_description', with: 'Short description' @@ -102,7 +101,6 @@ feature "Registration", js: true do perform_and_ensure(:click_button, "Continue", lambda { page.has_content? 'Finished!' }) # Done - expect(page).to have_content "We've sent a confirmation email to #{user.email} if it hasn't been activated before." e.reload expect(e.website).to eq "www.shop.com" expect(e.facebook).to eq "FaCeBoOk" diff --git a/spec/jobs/update_account_invoices_spec.rb b/spec/jobs/update_account_invoices_spec.rb index 0f0a78b505..1487a4a6c0 100644 --- a/spec/jobs/update_account_invoices_spec.rb +++ b/spec/jobs/update_account_invoices_spec.rb @@ -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(contact: "Firstname Lastname Something Else", phone: '12345') + june_billable_period1.enterprise.update_attributes(phone: '12345') updater.update(june_account_invoice) end @@ -175,8 +175,6 @@ 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 @@ -354,7 +352,7 @@ describe UpdateAccountInvoices do before do Spree::Config.set({ accounts_distributor_id: accounts_distributor.id }) - july_billable_period2.enterprise.update_attributes(contact: 'Anna Karenina', phone: '3433523') + july_billable_period2.enterprise.update_attributes(phone: '3433523') end context "when no invoice_order currently exists" do @@ -377,8 +375,6 @@ 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 @@ -421,8 +417,6 @@ 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 diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb index 18e864f7cd..bade27fb90 100644 --- a/spec/mailers/order_mailer_spec.rb +++ b/spec/mailers/order_mailer_spec.rb @@ -34,7 +34,7 @@ describe Spree::OrderMailer do it "sets a reply-to of the enterprise email" do Spree::OrderMailer.confirm_email_for_customer(@order1.id).deliver - ActionMailer::Base.deliveries.first.reply_to.should == [@distributor.email] + ActionMailer::Base.deliveries.first.reply_to.should == [@distributor.contact.email] end end @@ -42,7 +42,7 @@ describe Spree::OrderMailer do it "sends an email to the shop owner when given an order" do Spree::OrderMailer.confirm_email_for_shop(@order1.id).deliver ActionMailer::Base.deliveries.count.should == 1 - ActionMailer::Base.deliveries.first.to.should == [@distributor.email] + ActionMailer::Base.deliveries.first.to.should == [@distributor.contact.email] end it "sends an email even if a footer_email is given" do diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index 0ae398dd27..553cd571e2 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -59,16 +59,16 @@ describe ProducerMailer do ActionMailer::Base.deliveries.count.should == 1 end - it "sets a reply-to of the enterprise email" do - mail.reply_to.should == [s1.email] + it "sets a reply-to of the oc coordinator's email" do + expect(mail.reply_to).to eq [order_cycle.coordinator.contact.email] end it "includes receival instructions" do mail.body.encoded.should include 'Outside shed.' end - it "cc's the enterprise" do - mail.cc.should == [s1.email] + it "cc's the oc coordinator" do + expect(mail.cc).to eq [order_cycle.coordinator.contact.email] end it "contains an aggregated list of produce" do diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index e122fadf7b..e678831daa 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -10,7 +10,7 @@ describe Enterprise do it "sends a welcome email" do expect do - create(:enterprise, owner: user, email: enterprise.email) + create(:enterprise, owner: user) end.to enqueue_job WelcomeEnterpriseJob end end @@ -145,11 +145,9 @@ describe Enterprise do enterprise.should be_valid end - it "takes the owner's email address as default email" do - enterprise.email = nil - enterprise.should be_valid - enterprise.email.should be_present - enterprise.email.should eq owner.email + it "sets the enterprise contact to the owner by default" do + enterprise.contact.should be_present + enterprise.contact.should eq enterprise.owner end end @@ -218,13 +216,16 @@ describe Enterprise do end describe "activated" do - let!(:inactive_enterprise) { create(:enterprise, sells: "unspecified") ;} + let!(:unconfirmed_user) { create(:user, confirmed_at: nil, enterprise_limit: 2) } + let!(:inactive_enterprise1) { create(:enterprise, sells: "unspecified", owner: unconfirmed_user) } + let!(:inactive_enterprise2) { create(:enterprise, sells: "none", owner: unconfirmed_user) } let!(:active_enterprise) { create(:enterprise, sells: "none") } - it "finds enterprises that have a sells property other than 'unspecified'" do + it "finds enterprises that have a sells property other than 'unspecified' and have a confirmed user" do activated_enterprises = Enterprise.activated expect(activated_enterprises).to include active_enterprise - expect(activated_enterprises).to_not include inactive_enterprise + expect(activated_enterprises).to_not include inactive_enterprise1 + expect(activated_enterprises).to_not include inactive_enterprise2 end end