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.

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.rb
index 6f64abfee2..078f1287f7 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -59,6 +59,7 @@ module Spree
validates :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 v5
if !ENV['SPREE_DISABLE_DB_CONNECTION'] &&
diff --git a/core/app/models/spree/tax_rate.rb b/core/app/models/spree/tax_rate.rb
index d2d6efc1d6..3b11a728f0 100644
--- a/core/app/models/spree/tax_rate.rb
+++ b/core/app/models/spree/tax_rate.rb
@@ -13,7 +13,7 @@ module Spree
with_options presence: true do
validates :amount, numericality: { allow_nil: true }
- validates :tax_category
+ validates :tax_category, :name
end
scope :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.rb
index 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 do
factory :tax_rate, class: Spree::TaxRate do
+ name { "TaxRate - #{rand(999_999)}" }
zone
tax_category
amount { 0.1 }
diff --git a/core/spec/models/spree/tax_rate_spec.rb b/core/spec/models/spree/tax_rate_spec.rb
index 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 do
context 'when no rate zones match the tax zone' do
before do
- Spree::TaxRate.create(amount: 1, zone: create(:zone))
+ Spree::TaxRate.create(name: 'Tax Rate #1', amount: 1, zone: create(:zone))
end
context 'when there is no default tax zone' do
@@ -30,6 +30,7 @@ describe Spree::TaxRate, type: :model do
it 'returns the rate that matches the rate zone' do
rate = Spree::TaxRate.create(
+ name: 'Tax Rate #1',
amount: 1,
zone: @zone,
tax_category: tax_category,
@@ -42,6 +43,7 @@ describe Spree::TaxRate, type: :model do
it 'returns all rates that match the rate zone' do
rate1 = 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 do
sub_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 do
let(: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 do
context "when order's zone is neither the default zone, or included in the default zone, but matches the rate's zone" do
before do
new_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 do
it 'applies adjustments when a tax zone is present' do
expect(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}%")
end
end
diff --git a/core/spec/services/spree/cart/add_item_spec.rb b/core/spec/services/spree/cart/add_item_spec.rb
index 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 Spree
let!(:category) { Spree::TaxCategory.create name: 'Taxable Foo' }
let!(:rate) do
Spree::TaxRate.create(
+ name: 'Tax Rate 1',
amount: 0.25,
included_in_price: true,
calculator: Spree::Calculator::DefaultTax.create,