Require Enterprise.belongs_to by default

And remove a duplicate spec.
This commit is contained in:
Maikel Linke
2023-06-16 15:23:10 +10:00
parent 60212f92c3
commit 87ccfc94ef
2 changed files with 7 additions and 12 deletions

View File

@@ -10,6 +10,8 @@ class Enterprise < ApplicationRecord
WHITE_LABEL_LOGO_SIZES = [:default, :mobile].freeze
VALID_INSTAGRAM_REGEX = %r{\A[a-zA-Z0-9._]{1,30}([^/-]*)\z}
self.belongs_to_required_by_default = true
searchable_attributes :sells, :is_primary_producer, :name
searchable_associations :properties
searchable_scopes :is_primary_producer, :is_distributor, :is_hub, :activated, :visible,
@@ -44,7 +46,7 @@ class Enterprise < ApplicationRecord
dependent: :destroy
has_many :distributed_orders, class_name: 'Spree::Order', foreign_key: 'distributor_id'
belongs_to :address, class_name: 'Spree::Address'
belongs_to :business_address, class_name: 'Spree::Address', dependent: :destroy
belongs_to :business_address, optional: true, class_name: 'Spree::Address', dependent: :destroy
has_many :enterprise_fees
has_many :enterprise_roles, dependent: :destroy
has_many :users, through: :enterprise_roles
@@ -108,8 +110,7 @@ class Enterprise < ApplicationRecord
validates :name, presence: true
validate :name_is_unique
validates :sells, presence: true, inclusion: { in: SELLS }
validates :address, presence: true, associated: true
validates :owner, presence: true
validates :address, associated: true
validates :permalink, uniqueness: true, presence: true
validate :shopfront_taxons
validate :shopfront_producers

View File

@@ -19,11 +19,11 @@ describe Enterprise do
end
describe "associations" do
it { is_expected.to belong_to(:owner) }
it { is_expected.to belong_to(:owner).required }
it { is_expected.to have_many(:supplied_products) }
it { is_expected.to have_many(:distributed_orders) }
it { is_expected.to belong_to(:address) }
it { is_expected.to belong_to(:business_address) }
it { is_expected.to belong_to(:address).required }
it { is_expected.to belong_to(:business_address).optional }
it { is_expected.to have_many(:vouchers) }
it "destroys enterprise roles upon its own demise" do
@@ -125,12 +125,6 @@ describe Enterprise do
is_expected.to validate_uniqueness_of(:permalink)
end
it "requires an owner" do
enterprise = build_stubbed(:enterprise, owner: nil)
expect(enterprise).not_to be_valid
expect(enterprise.errors[:owner].first).to eq "can't be blank"
end
describe "name uniqueness" do
let(:owner) { create(:user, email: 'owner@example.com') }
let!(:enterprise) { create(:enterprise, name: 'Enterprise', owner: owner) }