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
fix(core): backfill ActionText descriptions in taxon→category migration
Łukasz Adamczykc77b16dcae0a
diff --git a/spree/core/lib/tasks/categories_and_collections.rake b/spree/core/lib/tasks/categories_and_collections.rakeindex 36031b6ee6..f1858efc6d 100644--- a/spree/core/lib/tasks/categories_and_collections.rake+++ b/spree/core/lib/tasks/categories_and_collections.rake@@ -152,6 +152,9 @@ namespace :spree do[Spree::Metafield, :resource_type, 'Spree::Taxon', 'Spree::Category'],[Spree::MetafieldDefinition, :resource_type, 'Spree::Taxon', 'Spree::Category'],[ActiveStorage::Attachment, :record_type, 'Spree::Taxon', 'Spree::Category'],+ # description is an ActionText field (translates :description, backend: :action_text);+ # surviving categories keep their rich-text description without this.+ [ActionText::RichText, :record_type, 'Spree::Taxon', 'Spree::Category'],[FriendlyId::Slug, :sluggable_type, 'Spree::Taxon', 'Spree::Category'],[Spree::PromotionRule, :type, 'Spree::Promotion::Rules::Taxon', 'Spree::Promotion::Rules::Category']].each do |model, column, from, to|diff --git a/spree/core/spec/lib/tasks/categories_and_collections_spec.rb b/spree/core/spec/lib/tasks/categories_and_collections_spec.rbindex 1fcce8f9ba..13c8ad9b63 100644--- a/spree/core/spec/lib/tasks/categories_and_collections_spec.rb+++ b/spree/core/spec/lib/tasks/categories_and_collections_spec.rb@@ -94,6 +94,23 @@ describe 'spree:migrate_taxons_to_categories_and_collections' doendend+ describe 'ActionText descriptions on surviving categories' do+ let(:taxonomy) { create(:taxonomy, store: store) }+ let!(:category) do+ create(:taxon, taxonomy: taxonomy, store: store).tap do |c|+ c.update!(description: '<div>Kept description</div>')+ # simulate a pre-6.0 row still typed as Spree::Taxon+ ActionText::RichText.where(record_id: c.id, name: 'description').update_all(record_type: 'Spree::Taxon')+ end+ end++ it 'backfills record_type so the rich-text description survives the rename' do+ subject.invoke++ expect(category.reload.description.to_plain_text).to eq('Kept description')+ end+ end+describe 'idempotency' dolet(:taxonomy) { create(:taxonomy, store: store) }let!(:category) { create(:automatic_taxon, taxonomy: taxonomy, store: store) }