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.

-- Remove NOT NULL constraint from spree_policies.name to support Mobility translations (#13463)

Muhammad Ibtisam Hussain8a5d757d02c4
diff --git a/core/app/models/spree/policy.rb b/core/app/models/spree/policy.rb
index 569f891c7b..8e56c441d7 100644
--- a/core/app/models/spree/policy.rb
+++ b/core/app/models/spree/policy.rb
@@ -36,7 +36,7 @@ module Spree
#
# Scopes
#
- scope :with_body, -> { joins(:rich_text_body).distinct }
+ scope :with_body, -> { joins(:rich_text_body).distinct }
scope :without_body, -> { where.missing(:rich_text_body) }
scope :with_matching_name, ->(name_to_match) do
value = name_to_match.to_s.strip.downcase
diff --git a/core/db/migrate/20260117140831_remove_not_null_constraint_from_policy_name.rb b/core/db/migrate/20260117140831_remove_not_null_constraint_from_policy_name.rb
new file mode 100644
index 0000000000..6003b2f339
--- /dev/null
+++ b/core/db/migrate/20260117140831_remove_not_null_constraint_from_policy_name.rb
@@ -0,0 +1,5 @@
+class RemoveNotNullConstraintFromPolicyName < ActiveRecord::Migration[7.2]
+ def change
+ change_column_null :spree_policies, :name, true
+ end
+end
diff --git a/core/spec/models/spree/policy_spec.rb b/core/spec/models/spree/policy_spec.rb
index ccd31beb45..fb9301b093 100644
--- a/core/spec/models/spree/policy_spec.rb
+++ b/core/spec/models/spree/policy_spec.rb
@@ -69,6 +69,26 @@ RSpec.describe Spree::Policy, type: :model do
expect(policy.body.to_plain_text).to eq('Política de Privacidad')
end
end
+
+ context 'when always_use_translations is enabled' do
+ before do
+ @original_setting = Spree::Config.always_use_translations
+ Spree::Config.always_use_translations = true
+ end
+
+ after do
+ Spree::Config.always_use_translations = @original_setting
+ end
+
+ it 'allows creating policies with translations' do
+ I18n.with_locale(:es) do
+ policy = create(:policy, owner: store, name: 'Política de Privacidad')
+
+ expect(policy).to be_persisted
+ expect(policy.name).to eq('Política de Privacidad')
+ end
+ end
+ end
end
describe 'Scopes' do