Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Make BusinessAddress a real subclass, shared with company locations

Damian Legawiec1f2e430eab21
diff --git a/docs/plans/6.0-multi-vendor-marketplace.md b/docs/plans/6.0-multi-vendor-marketplace.md
index b1111849fa..60d31f3b00 100644
--- a/docs/plans/6.0-multi-vendor-marketplace.md
+++ b/docs/plans/6.0-multi-vendor-marketplace.md
@@ -241,7 +241,7 @@ Core already models exactly this. `Spree::TaxIdentifier` (from `6.0-tax-provider
**No per-seller tax rate.** Adding one is the legacy `platform_fee_tax_rate` column this plan already rejected (Resolved Decisions, 2026-06-16): the seller supplies tax *identity*, and the commission tax *rate* resolves through `CommissionRate` + the `TaxProvider` so it stays jurisdiction-correct.
-**One `Address` subclass, sharing the table.** The legacy module subclassed `BillingAddress`/`ReturnsAddress` to override `require_name?` (a company address has no first and last name) and `show_company_address_field?`. Returns no longer need an address subclass at all — they route to a stock location — so only the billing half survives, as `Spree::BusinessAddress`. It is **not** STI: `spree_addresses` has no `type` column and gains none, because that would mean altering the table every order, customer and company writes to in order to encode a fact the owning association already states. The subclass reads the same rows and overrides the three predicates (`require_name?` false, `require_company?` true, `show_company_address_field?` true), which is where those rules belong — the alternative tried first was a `before_validation` flag on the seller, and a validation rule that has to be switched on per record is a class.
+**One `Address` subclass, real STI, universal (2026-08-22 — supersedes the no-type-column position taken earlier the same day).** The legacy module subclassed `BillingAddress`/`ReturnsAddress` to override `require_name?` (a company address has no first and last name) and `show_company_address_field?`. Returns no longer need an address subclass at all — they route to a stock location — so only the billing half survives, as `Spree::BusinessAddress`, and it is not seller-only: company locations' addresses are business addresses too, and B2B checkout will put one on a cart. That is what settled STI over table-sharing — the rules must travel with the row. A company address copied onto a cart's base-typed `bill_address` loads back as a `BusinessAddress` and validates as one (company required, no personal name) without checkout knowing anything about it, which a class chosen by the owning association cannot do. `spree_addresses` gains a `type` column (nullable; plain rows stay NULL and load as `Spree::Address`); `empty?` excludes it, and value comparison/dedup keep it — same postal facts under different rules are different addresses, and `check` never merges a business address into a personal twin. A `CompanyLocation` stamps its own company's name onto an address payload that lacks one, so API clients aren't made to repeat what the branch already knows.
**Supersedes** the `belongs_to :returns_address` line in the Seller model sketch below, and the `Spree::SellerRequirements::ReturnsAddress` checklist kind becomes "has a returns location".
@@ -743,7 +743,7 @@ Even before this lands, work touching adjacent areas should:
- **Tax provider (`6.0-tax-provider.md`)** and **Delivery rate provider (`6.0-delivery-rate-provider.md`)**: the `PayoutProvider` follows the same pluggable-strategy shape — keep the provider-registration convention consistent so all three (tax, delivery rate, payout) register and resolve the same way.
- **Admin API (`6.0-admin-api.md`)**: the `Seller` prefix is `sel_`. The "Marketplace (new in 6.0)" endpoint group there is the *operator's* API surface — keep it in sync. Seller users never call the Admin API (Decision 10).
- **Auth + RBAC (`6.0-platform-auth.md`, `6.0-admin-rbac.md`)**: no third principal — never add a `SellerUser`/`Spree.seller_user_class`; seller staff are `Spree.admin_user_class`. Never derive back-office membership from `store_id` alone — match `RoleUser.resource_type` (`Ability#staff_roles` and `RoleGrantGuard` already do; the membership check must follow). New login surfaces get their own strategy registry and JWT audience; refresh tokens must carry the audience they were minted for. Catalog resources that sellers may hold must be marked seller-grantable at `register_resource`; `settings`/`staff`/`api_keys` never are. Seller-branch controllers scope-fetch through `current_seller` and never subclass admin controllers.
-- **Seller addresses (Decision 12)**: do not add a `returns_address` back, and do not give a seller a tax *rate* column — identity (`legal_name`, `registration_number`, a `TaxIdentifier`) is the seller's, the rate is `CommissionRate` + `TaxProvider`. A billing address is a `Spree::BusinessAddress` (table-sharing subclass, never STI — `spree_addresses` gains no `type` column). Code reading a seller's returns destination goes through `Seller#returns_location`, never a stored address FK. `StockLocation` name-uniqueness and its `default` flag are per-owner, so new code must not assume one default per store.
+- **Seller addresses (Decision 12)**: do not add a `returns_address` back, and do not give a seller a tax *rate* column — identity (`legal_name`, `registration_number`, a `TaxIdentifier`) is the seller's, the rate is `CommissionRate` + `TaxProvider`. A billing address is a `Spree::BusinessAddress` (real STI since 2026-08-22; company locations' addresses are the same class). Code reading a seller's returns destination goes through `Seller#returns_location`, never a stored address FK. `StockLocation` name-uniqueness and its `default` flag are per-owner, so new code must not assume one default per store.
- Do **not** revive the legacy commission model's shape (label-based rows + denormalized fee totals on the order), do **not** model commission as a polymorphic `Adjustment`, and do **not** write commission as a `Spree::Fee` (fees are buyer-facing and roll into order totals — Decision 2) — 6.0 uses the off-order `Spree::CommissionLine` ledger. Do **not** put the fund ledger in a payment-gateway namespace (the legacy gateway-namespaced-transfer mistake) nor collapse transfer and payout into one model — `Spree::SellerTransfer` (on-fulfillment) and `Spree::SellerPayout` (scheduled) are both core and provider-agnostic.
## Resolved Decisions
@@ -794,7 +794,7 @@ Even before this lands, work touching adjacent areas should:
- **Fund ledger → two levels: `Spree::SellerTransfer` (per-order, on-fulfillment) + `Spree::SellerPayout` (per-interval settlement), both generic in core + pluggable `PayoutProvider` (system no-op in core; basic StripeConnect with the monorepo Stripe gateway per the 2026-07-15 amendment, extended by Enterprise with the money operations)** (RESOLVED 2026-06-25). See Decision 9. Transfer credits the seller balance on fulfillment; payout sweeps unsettled transfers into a scheduled bank settlement (transfers `belong_to` their payout — auditable). `seller.balance(currency) = Σ completed transfers − Σ completed payouts` per currency. Splits the legacy gateway-namespaced transfer ledger (which conflated the two and outsourced settlement to Stripe) into core ledger + provider execution along the OSS/Enterprise seam.
- **Commission tax → one scalar on the line, in TaxLine's vocabulary** (RESOLVED 2026-08-17). `tax_amount` + `tax_rate` + `taxability_reason` + the seller's `country_code`/`state_code` on `Spree::CommissionLine`, with `Spree::CommissionTax` as the value object the resolver returns. Reusing `Spree::TaxLine` itself was rejected: its rows sum into the order total and are exposed on the buyer-facing `/orders/:id/tax_lines`, so a commission row there would overcharge the shopper and leak settlement data. Same shape, opposite side of the ledger — so the words are shared and the rows are not. See Decision 3.
- **Commission VAT base → net item price, VAT added on top of the fee** (RESOLVED 2026-06-25). For EU, commission is computed on the seller's **net (ex-VAT)** item price; the commission `tax_amount` (Decision 3) is then applied **on top of the commission** as a separate B2B service supply — the marketplace fee is a distinct taxable event from the consumer's item sale, so the two VATs never mix. The base toggle stays available for non-EU/edge merchants who genuinely want a gross base, but the EU default is net-base + fee-VAT. Shipped as **`tax_inclusive`** (2026-08-17), matching `Spree::Market#tax_inclusive` rather than the surveyed industry's `include_tax` — the flag says the commission base is tax-inclusive, which is the same adjective the rest of Spree already uses for a price that carries its tax. This makes the marketplace's commission invoice to the seller stand on its own (correct for EU invoicing + remittance).
-- **Seller addresses → a stock location + a business identity** (RESOLVED 2026-08-20). `returns_address` is dropped: returns route to a seller-owned `StockLocation` (default provisioned at creation) so received goods restock where the catalog can see them, which also requires `StockLocation` name-uniqueness and the `default` flag to become per-owner rather than per-store. Billing becomes a `Spree::BusinessAddress`, while the parts that are not an address at all become `legal_name` + `registration_number` on the seller and a `Spree::TaxIdentifier` owned by it — reusing the validation/evidence rails the tax plan already built, because EU reverse charge on the commission invoice needs a verified number with retained evidence. No per-seller tax rate (that stays `CommissionRate` + `TaxProvider`) and no `Address` **STI** — `Spree::BusinessAddress` shares `spree_addresses` and the table gains no `type` column. See Decision 12.
+- **Seller addresses → a stock location + a business identity** (RESOLVED 2026-08-20). `returns_address` is dropped: returns route to a seller-owned `StockLocation` (default provisioned at creation) so received goods restock where the catalog can see them, which also requires `StockLocation` name-uniqueness and the `default` flag to become per-owner rather than per-store. Billing becomes a `Spree::BusinessAddress`, while the parts that are not an address at all become `legal_name` + `registration_number` on the seller and a `Spree::TaxIdentifier` owned by it — reusing the validation/evidence rails the tax plan already built, because EU reverse charge on the commission invoice needs a verified number with retained evidence. No per-seller tax rate (that stays `CommissionRate` + `TaxProvider`); `Spree::BusinessAddress` is a real STI subclass since 2026-08-22 (`spree_addresses` gained `type`), shared with company locations and ready for B2B checkout. See Decision 12.
- **Store-credit/gift-card payout → payment-source-agnostic** (RESOLVED 2026-06-25). The `SellerTransfer` amount (which rolls up into the payout) is `(seller's sale value) − (commission owed)`, **independent of how the customer paid**. Store credit / gift cards are the platform's funding concern, not the seller's — the seller is owed their full cut of the sale regardless. This **drops the legacy store-credit dual-basis** from the amount calculation; that branch existed only to reconcile the old store-credit funding model and does not belong in the payout basis. (The platform still tracks its own store-credit liability separately — that's orthogonal to what the seller receives.)
- **Commission precedence → an operator-ordered list** (RESOLVED 2026-06-25 as integer priority; **reshaped 2026-08-17 to `acts_as_list`, shipped**). `CommissionRate` carries `position` (`acts_as_list scope: :store_id, add_new_at: :top`) and resolution walks it top-down, first match wins (Decision 4). The list on screen is the precedence, so reordering is dragging rather than assigning numbers; new rates land at the top so they take effect on creation instead of behind the catch-all. `Spree::Seeds::CommissionRates` puts one disabled marketplace-wide rate at the bottom, which yields the product > category > seller order merchants asked for without hardcoding a ladder. No specificity inference — a rate can name all three dimensions at once, so there is nothing to infer from.
- **Commission rate currency → required for fixed, ignored for percentage** (RESOLVED 2026-06-25). A `kind: 'fixed'` rate **must** carry a `currency` (a flat "2" is meaningless without one); a `kind: 'percentage'` rate ignores currency (10% applies in any currency). Enforced by a model validation: `validates :currency, presence: true, if: -> { kind == 'fixed' }`. See the `CommissionRate` model.
diff --git a/docs/plans/decisions.md b/docs/plans/decisions.md
index 975559ac8a..5262204ecd 100644
--- a/docs/plans/decisions.md
+++ b/docs/plans/decisions.md
@@ -1,3 +1,13 @@
+## 2026-08-22: BusinessAddress is real STI, and it is universal
+
+**Context:** `Spree::BusinessAddress` began the day as a table-sharing subclass of `Spree::Address` — no `type` column, the class chosen by whichever association loaded it — serving only the seller's billing address. But company locations carry the same kind of address, and B2B checkout will put one on a cart, where the loading associations (`bill_address`/`ship_address`) are base-typed and cannot choose the class.
+
+**Decision:** `spree_addresses` gains a nullable `type` column and the subclass becomes real STI. The rules now travel with the row: an address copied from a company location onto a cart loads back as a `BusinessAddress` and validates as one — company required, no personal name — without checkout knowing anything about it. `CompanyLocation`'s two addresses are typed `BusinessAddress`; the seller's billing address already was. Plain rows keep a NULL type and load as `Spree::Address`. Three consequences inside `Address` itself: `empty?` excludes `type` (a subclass row always carries it), while value comparison and `check`'s dedup keep it — the same postal facts under different validation rules are different addresses, and a business address must never merge into a personal twin another reference depends on. `CompanyLocation` stamps its own company's name onto an address payload lacking one, so the API contract does not start demanding data the branch already knows — deliberately not mirrored on `Seller`, whose billing address is the addressee of a commission invoice and must be stated rather than guessed from a trading name. The migration backfills `type` for rows already referenced by sellers and company locations — without that, a NULL-typed row behind a subclass-typed association reads back as nil, because the STI default scope filters on `type`.
+
+**Rejected:** keeping table-sharing (the class cannot survive a copy onto a base-typed association, which is exactly the B2B checkout path); a storefront "buying as a company" flag on cart address writes (a Store API design question for when B2B checkout actually lands, not schema work).
+
+**Consequences:** callers create the right class — the `becomes` coercion on `Seller#billing_address=` is gone and assigning a plain `Address` record to a typed association raises; the `:business_address` factory is the spec-side answer. Nested attribute writes were already correct: a typed `belongs_to` builds through its reflection, so Hash payloads need nothing. `StockLocation#address` stays a plain `Address` — it is a transient warehouse address for rate quotes and labels, never validated as a business one. No serializer exposes `type`.
+
## 2026-08-22: The tax identifier's owner is polymorphic
**Context:** `Spree::TaxIdentifier` carried one nullable FK per owner — customer, company, cart, order — with an `exactly_one_owner` validator holding the rule together, following the dual-FK convention from the Cart/Order split. The marketplace work added a fifth owner (Seller, per `6.0-multi-vendor-marketplace.md` Decision 12), which made the shape hard to defend: five columns, three near-identical per-owner uniqueness validations, and an `owner` method that was a five-way `||` chain.
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/company_locations_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/company_locations_controller_spec.rb
index 3f3ad0bbeb..cfd37ad39e 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/company_locations_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/company_locations_controller_spec.rb
@@ -36,7 +36,7 @@ RSpec.describe Spree::Api::V3::Admin::CompanyLocationsController, type: :control
end
context 'with an address already on file' do
- let!(:existing) { create(:address, address1: 'Alte Str 1', city: 'Berlin') }
+ let!(:existing) { create(:business_address, address1: 'Alte Str 1', city: 'Berlin') }
before { location.update!(billing_address: existing) }
@@ -75,7 +75,7 @@ RSpec.describe Spree::Api::V3::Admin::CompanyLocationsController, type: :control
describe 'DELETE #destroy' do
it 'removes the branch and the address it owned' do
- location.update!(billing_address: create(:address))
+ location.update!(billing_address: create(:business_address))
expect { delete :destroy, params: { id: location.prefixed_id }, as: :json }.
to change(Spree::Address, :count).by(-1)
diff --git a/spree/core/app/models/spree/address.rb b/spree/core/app/models/spree/address.rb
index 2dbe028e78..cfdd9c6b1b 100644
--- a/spree/core/app/models/spree/address.rb
+++ b/spree/core/app/models/spree/address.rb
@@ -27,6 +27,11 @@ module Spree
# those attributes depending of the logic of their applications
ADDRESS_FIELDS = %w(firstname lastname company address1 address2 city state zipcode country phone)
EXCLUDED_KEYS_FOR_COMPARISON = %w(id updated_at created_at deleted_at label customer_id metadata)
+ # Blankness is about what somebody typed, so bookkeeping columns and the
+ # STI type are ignored. Comparison and dedup deliberately keep `type`: the
+ # same postal facts under different validation rules are different
+ # addresses, and a business one must never merge into a personal twin.
+ EXCLUDED_KEYS_FOR_BLANKNESS = %w(id type created_at updated_at country_id country_code).freeze
if defined?(Spree::Security::Addresses)
include Spree::Security::Addresses
end
@@ -234,7 +239,7 @@ module Spree
# A country alone doesn't make an address — a new one is pre-filled with the
# store's default, so both the code and the association are ignored here.
def empty?
- attributes.except('id', 'created_at', 'updated_at', 'country_id', 'country_code').all? { |_, v| v.nil? }
+ attributes.except(*EXCLUDED_KEYS_FOR_BLANKNESS).all? { |_, v| v.nil? }
end
# Generates an address hash for payment gateway options
diff --git a/spree/core/app/models/spree/business_address.rb b/spree/core/app/models/spree/business_address.rb
index bea06e8615..b9bea33e80 100644
--- a/spree/core/app/models/spree/business_address.rb
+++ b/spree/core/app/models/spree/business_address.rb
@@ -1,9 +1,11 @@
module Spree
- # A seller's billing address, as a commission invoice must address it: no
- # person to name, and the company is the part that cannot be left out.
+ # The address of a business entity — a seller's billing address, a company
+ # location's branch. No person to name, and the company is the part that
+ # cannot be left out.
#
- # Shares `spree_addresses` rather than being STI — the table has no `type`
- # column, and the owning association already says which kind this is.
+ # STI rather than a class picked by the owning association, so the rules
+ # travel with the row: copied onto a base-typed association such as a cart's
+ # bill_address, it still loads and validates as a business address.
class BusinessAddress < Spree::Address
def require_name?
false
diff --git a/spree/core/app/models/spree/company_location.rb b/spree/core/app/models/spree/company_location.rb
index f231f4250b..8d45724eb6 100644
--- a/spree/core/app/models/spree/company_location.rb
+++ b/spree/core/app/models/spree/company_location.rb
@@ -13,17 +13,19 @@ module Spree
include Spree::HasExternalReferences
belongs_to :company, class_name: 'Spree::Company', inverse_of: :company_locations
- belongs_to :billing_address, class_name: 'Spree::Address', optional: true, dependent: :destroy
- belongs_to :shipping_address, class_name: 'Spree::Address', optional: true, dependent: :destroy
+ belongs_to :billing_address, class_name: 'Spree::BusinessAddress', optional: true, dependent: :destroy
+ belongs_to :shipping_address, class_name: 'Spree::BusinessAddress', optional: true, dependent: :destroy
# update_only, so editing one field of an existing address changes that
# row instead of building a replacement and orphaning the old one.
accepts_nested_attributes_for :billing_address, update_only: true
accepts_nested_attributes_for :shipping_address, update_only: true
+ ADDRESS_ASSOCIATIONS = %i[billing_address shipping_address].freeze
+
# The API reads and writes these under the same name, so the writer takes
# either a record or the nested hash a client sends.
- %i[billing_address shipping_address].each do |name|
+ ADDRESS_ASSOCIATIONS.each do |name|
define_method(:"#{name}=") do |value|
value.is_a?(Hash) || value.is_a?(ActionController::Parameters) ? send(:"#{name}_attributes=", value) : super(value)
end
@@ -33,11 +35,33 @@ module Spree
inverse_of: :company_location
has_many :customers, through: :company_contacts, source: :customer
+ # A business address insists on its company line, but the branch already
+ # knows whose it is — so a payload without one gets the owning company's
+ # name stamped in, as a snapshot the invoice can print even if the
+ # company later renames. Only when an address is actually being written:
+ # otherwise every unrelated save would load both of them to ask.
+ before_validation :default_address_company, if: :address_being_written?
+
validates :name, presence: true
delegate :store, :store_id, to: :company
self.whitelisted_ransackable_attributes = %w[name]
self.whitelisted_ransackable_associations = %w[external_references]
+
+ private
+
+ def address_being_written?
+ ADDRESS_ASSOCIATIONS.any? do |name|
+ association(name).loaded? || public_send(:"#{name}_id_changed?")
+ end
+ end
+
+ def default_address_company
+ ADDRESS_ASSOCIATIONS.each do |name|
+ address = public_send(name)
+ address.company = company&.name if address && address.company.blank?
+ end
+ end
end
end
diff --git a/spree/core/app/models/spree/seller.rb b/spree/core/app/models/spree/seller.rb
index 85b3f2be44..749d589fac 100644
--- a/spree/core/app/models/spree/seller.rb
+++ b/spree/core/app/models/spree/seller.rb
@@ -75,19 +75,11 @@ module Spree
# The API reads and writes this under one name, so the writer takes the
# attributes a client sends as well as a record. Never an id: an address
# carries no store of its own, so binding one by id would reach another
- # store's rows. A plain Spree::Address is accepted too — the two share
- # `spree_addresses` and differ only in which fields they insist on, so a
- # valid row should not be refused over its Ruby class.
+ # store's rows.
def billing_address=(value)
- case value
- when Hash, ActionController::Parameters
- super(Spree::BusinessAddress.new) if billing_address.nil?
- self.billing_address_attributes = value
- when Spree::Address
- super(value.becomes(Spree::BusinessAddress))
- else
- super
- end
+ return super unless value.is_a?(Hash) || value.is_a?(ActionController::Parameters)
+
+ self.billing_address_attributes = value
end
# Where this seller keeps stock, and so where their returns land. Released
diff --git a/spree/core/db/migrate/20260822000001_add_type_to_spree_addresses.rb b/spree/core/db/migrate/20260822000001_add_type_to_spree_addresses.rb
new file mode 100644
index 0000000000..38bcec4a3f
--- /dev/null
+++ b/spree/core/db/migrate/20260822000001_add_type_to_spree_addresses.rb
@@ -0,0 +1,24 @@
+class AddTypeToSpreeAddresses < ActiveRecord::Migration[8.1]
+ def up
+ add_column :spree_addresses, :type, :string
+ add_index :spree_addresses, :type
+
+ # Rows already referenced as business addresses must carry the type, or
+ # the subclass-typed associations read them back as nil — STI filters on
+ # it. Both referencing tables are born in 6.0, so this touches no
+ # released data and needs no batching.
+ business_addresses = Class.new(ActiveRecord::Base) { self.table_name = 'spree_addresses' }
+ sellers = Class.new(ActiveRecord::Base) { self.table_name = 'spree_sellers' }
+ company_locations = Class.new(ActiveRecord::Base) { self.table_name = 'spree_company_locations' }
+
+ ids = sellers.where.not(billing_address_id: nil).pluck(:billing_address_id) +
+ company_locations.where.not(billing_address_id: nil).pluck(:billing_address_id) +
+ company_locations.where.not(shipping_address_id: nil).pluck(:shipping_address_id)
+
+ business_addresses.where(id: ids.uniq).update_all(type: 'Spree::BusinessAddress')
+ end
+
+ def down
+ remove_column :spree_addresses, :type
+ end
+end
diff --git a/spree/core/lib/spree/testing_support/factories/address_factory.rb b/spree/core/lib/spree/testing_support/factories/address_factory.rb
index 6941078c6f..a9dfd71b89 100644
--- a/spree/core/lib/spree/testing_support/factories/address_factory.rb
+++ b/spree/core/lib/spree/testing_support/factories/address_factory.rb
@@ -39,8 +39,7 @@ FactoryBot.define do
zipcode { Spree::TestingSupport::CountryPool.postal_code_for(country&.iso) }
# An address addressed to a company rather than a person — a seller's
- # billing address. Shares the table with its parent, so the only
- # difference is which fields it asks for.
+ # billing address, a company location's branch.
factory :business_address, class: Spree::BusinessAddress do
firstname { nil }
lastname { nil }
diff --git a/spree/core/spec/models/spree/base_spec.rb b/spree/core/spec/models/spree/base_spec.rb
index 0e747d901b..859dbd6642 100644
--- a/spree/core/spec/models/spree/base_spec.rb
+++ b/spree/core/spec/models/spree/base_spec.rb
@@ -54,12 +54,12 @@ describe Spree::Base do
expect(Spree.customer_class.json_api_columns).to include('email')
end
- it { expect(Spree::Address.json_api_columns).to contain_exactly('address1', 'address2', 'alternative_phone', 'city', 'company', 'country_code', 'created_at', 'deleted_at', 'firstname', 'label', 'lastname', 'phone', 'state_code', 'state_name', 'updated_at', 'zipcode', 'metadata', 'quick_checkout', 'latitude', 'longitude') }
+ it { expect(Spree::Address.json_api_columns).to contain_exactly('address1', 'address2', 'alternative_phone', 'city', 'company', 'country_code', 'created_at', 'deleted_at', 'firstname', 'label', 'lastname', 'phone', 'state_code', 'state_name', 'type', 'updated_at', 'zipcode', 'metadata', 'quick_checkout', 'latitude', 'longitude') }
it { expect(Spree::Address.json_api_columns).not_to include('country_id') }
end
describe '.json_api_permitted_attributes' do
- it { expect(Spree::Address.json_api_permitted_attributes).to contain_exactly('firstname', 'lastname', 'address1', 'address2', 'city', 'zipcode', 'phone', 'country_code', 'state_code', 'state_name', 'alternative_phone', 'company', 'country_id', 'state_id', 'created_at', 'updated_at', 'customer_id', 'deleted_at', 'label', 'metadata', 'quick_checkout', 'latitude', 'longitude') }
+ it { expect(Spree::Address.json_api_permitted_attributes).to contain_exactly('firstname', 'lastname', 'address1', 'address2', 'city', 'zipcode', 'phone', 'country_code', 'state_code', 'state_name', 'alternative_phone', 'company', 'country_id', 'state_id', 'created_at', 'updated_at', 'customer_id', 'deleted_at', 'label', 'metadata', 'quick_checkout', 'latitude', 'longitude', 'type') }
end
describe '.additional_permitted_attributes' do
diff --git a/spree/core/spec/models/spree/company_location_spec.rb b/spree/core/spec/models/spree/company_location_spec.rb
index 7588aba29b..08bf01dba5 100644
--- a/spree/core/spec/models/spree/company_location_spec.rb
+++ b/spree/core/spec/models/spree/company_location_spec.rb
@@ -16,7 +16,7 @@ describe Spree::CompanyLocation, type: :model do
describe 'addresses' do
it 'creates them inline from nested attributes' do
location = create(:company_location, company: company,
- billing_address_attributes: build(:address).attributes.except('id', 'created_at', 'updated_at'))
+ billing_address_attributes: build(:address).attributes.except('id', 'type', 'created_at', 'updated_at'))
expect(location.billing_address).to be_present
end
@@ -25,8 +25,8 @@ describe Spree::CompanyLocation, type: :model do
# shared is taken away.
it 'destroys its own address rows with it' do
location = create(:company_location, company: company,
- billing_address: create(:address),
- shipping_address: create(:address))
+ billing_address: create(:business_address),
+ shipping_address: create(:business_address))
expect { location.destroy }.to change(Spree::Address, :count).by(-2)
end
diff --git a/spree/core/spec/services/spree/commissions/resolve_tax_rate_spec.rb b/spree/core/spec/services/spree/commissions/resolve_tax_rate_spec.rb
index e39447a729..8017dfeb71 100644
--- a/spree/core/spec/services/spree/commissions/resolve_tax_rate_spec.rb
+++ b/spree/core/spec/services/spree/commissions/resolve_tax_rate_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
RSpec.describe Spree::Commissions::ResolveTaxRate do
let(:store) { @default_store }
- let(:billing_address) { create(:address, country_iso: 'DE') }
+ let(:billing_address) { create(:business_address, country_iso: 'DE') }
let(:seller) { create(:seller, :approved, store: store, billing_address: billing_address) }
let(:order) { create(:order, store: store) }
let(:rate) { create(:commission_rate, store: store) }