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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Validate presence of name on tax rate. (#11548)
Matthew Kennedycbfebe33d343
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex 6f64abfee2..078f1287f7 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -59,6 +59,7 @@ module Spreevalidates :digital_asset_authorized_clicks, numericality: { only_integer: true, greater_than: 0 }validates :digital_asset_authorized_days, numericality: { only_integer: true, greater_than: 0 }validates :code, uniqueness: { conditions: -> { with_deleted } }+ validates :mail_from_address, email: { allow_blank: false }# FIXME: we should remove this condition in v5if !ENV['SPREE_DISABLE_DB_CONNECTION'] &&diff --git a/core/app/models/spree/tax_rate.rb b/core/app/models/spree/tax_rate.rbindex d2d6efc1d6..3b11a728f0 100644--- a/core/app/models/spree/tax_rate.rb+++ b/core/app/models/spree/tax_rate.rb@@ -13,7 +13,7 @@ module Spreewith_options presence: true dovalidates :amount, numericality: { allow_nil: true }- validates :tax_category+ validates :tax_category, :nameendscope :by_zone, ->(zone) { where(zone_id: zone.id) }diff --git a/core/lib/spree/testing_support/factories/tax_rate_factory.rb b/core/lib/spree/testing_support/factories/tax_rate_factory.rbindex bcd9ace468..9a58ebbb3c 100644--- a/core/lib/spree/testing_support/factories/tax_rate_factory.rb+++ b/core/lib/spree/testing_support/factories/tax_rate_factory.rb@@ -1,5 +1,6 @@FactoryBot.define dofactory :tax_rate, class: Spree::TaxRate do+ name { "TaxRate - #{rand(999_999)}" }zonetax_categoryamount { 0.1 }diff --git a/core/spec/models/spree/tax_rate_spec.rb b/core/spec/models/spree/tax_rate_spec.rbindex 68f4a6e99f..e890278d45 100644--- a/core/spec/models/spree/tax_rate_spec.rb+++ b/core/spec/models/spree/tax_rate_spec.rb@@ -14,7 +14,7 @@ describe Spree::TaxRate, type: :model docontext 'when no rate zones match the tax zone' dobefore do- Spree::TaxRate.create(amount: 1, zone: create(:zone))+ Spree::TaxRate.create(name: 'Tax Rate #1', amount: 1, zone: create(:zone))endcontext 'when there is no default tax zone' do@@ -30,6 +30,7 @@ describe Spree::TaxRate, type: :model doit 'returns the rate that matches the rate zone' dorate = Spree::TaxRate.create(+ name: 'Tax Rate #1',amount: 1,zone: @zone,tax_category: tax_category,@@ -42,6 +43,7 @@ describe Spree::TaxRate, type: :model doit 'returns all rates that match the rate zone' dorate1 = Spree::TaxRate.create(+ name: 'Tax Rate #1',amount: 1,zone: @zone,tax_category: tax_category,@@ -49,6 +51,7 @@ describe Spree::TaxRate, type: :model do)rate2 = Spree::TaxRate.create(+ name: 'Tax Rate #2',amount: 2,zone: @zone,tax_category: tax_category,@@ -65,6 +68,7 @@ describe Spree::TaxRate, type: :model dosub_zone.zone_members.create(zoneable: create(:state, country: country))allow(order).to receive_messages tax_zone: sub_zone@rate = Spree::TaxRate.create(+ name: 'Tax Rate #1',amount: 1,zone: @zone,tax_category: tax_category,@@ -88,7 +92,8 @@ describe Spree::TaxRate, type: :model dolet(:included_in_price) { false }let!(:rate) do- Spree::TaxRate.create(amount: 1,+ Spree::TaxRate.create(name: 'Tax Rate #1',+ amount: 1,zone: @zone,tax_category: tax_category,calculator: calculator,@@ -367,12 +372,14 @@ describe Spree::TaxRate, type: :model do@category = Spree::TaxCategory.create name: 'Taxable Foo'@category2 = Spree::TaxCategory.create(name: 'Non Taxable')@rate1 = Spree::TaxRate.create(+ name: 'Tax Rate #1',amount: 0.10,calculator: Spree::Calculator::DefaultTax.create,tax_category: @category,zone: @zone)@rate2 = Spree::TaxRate.create(+ name: 'Tax Rate #2',amount: 0.05,calculator: Spree::Calculator::DefaultTax.create,tax_category: @category,@@ -422,6 +429,7 @@ describe Spree::TaxRate, type: :model docontext "when order's zone is neither the default zone, or included in the default zone, but matches the rate's zone" dobefore donew_rate = Spree::TaxRate.create(+ name: 'New Tax Rate',amount: 0.2,included_in_price: true,calculator: Spree::Calculator::DefaultTax.create,@@ -501,7 +509,7 @@ describe Spree::TaxRate, type: :model doit 'applies adjustments when a tax zone is present' doexpect(line_item.adjustments.count).to eq(2)line_item.adjustments.each do |adjustment|- expect(adjustment.label).to eq("#{adjustment.source.tax_category.name} #{adjustment.source.amount * 100}%")+ expect(adjustment.label).to eq("#{adjustment.source.name} #{adjustment.source.amount * 100}%")endenddiff --git a/core/spec/services/spree/cart/add_item_spec.rb b/core/spec/services/spree/cart/add_item_spec.rbindex 620af56bde..776243ba37 100644--- a/core/spec/services/spree/cart/add_item_spec.rb+++ b/core/spec/services/spree/cart/add_item_spec.rb@@ -100,6 +100,7 @@ module Spreelet!(:category) { Spree::TaxCategory.create name: 'Taxable Foo' }let!(:rate) doSpree::TaxRate.create(+ name: 'Tax Rate 1',amount: 0.25,included_in_price: true,calculator: Spree::Calculator::DefaultTax.create,