diff --git a/app/models/customer.rb b/app/models/customer.rb index 6e5468fed1..c0dbf6d8a7 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -10,20 +10,22 @@ class Customer < ApplicationRecord include SetUnusedAddressFields + self.belongs_to_required_by_default = true + acts_as_taggable searchable_attributes :first_name, :last_name, :email, :code - belongs_to :enterprise, optional: false - belongs_to :user, class_name: "Spree::User" + belongs_to :enterprise + belongs_to :user, class_name: "Spree::User", optional: true has_many :orders, class_name: "Spree::Order" before_destroy :update_orders_and_delete_canceled_subscriptions - belongs_to :bill_address, class_name: "Spree::Address" + belongs_to :bill_address, class_name: "Spree::Address", optional: true alias_attribute :billing_address, :bill_address accepts_nested_attributes_for :bill_address - belongs_to :ship_address, class_name: "Spree::Address" + belongs_to :ship_address, class_name: "Spree::Address", optional: true alias_attribute :shipping_address, :ship_address accepts_nested_attributes_for :ship_address diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index 1b4f93cf02..8cf26c69d0 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -3,6 +3,11 @@ require 'spec_helper' describe Customer, type: :model do + it { is_expected.to belong_to(:enterprise).required } + it { is_expected.to belong_to(:user).optional } + it { is_expected.to belong_to(:bill_address).optional } + it { is_expected.to belong_to(:ship_address).optional } + describe 'an existing customer' do let(:customer) { create(:customer) }