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 issue with Rails 5.2 and Active Record Store _change? method not available.
Matthew Kennedy5565e6716ee1
diff --git a/core/app/models/spree/cms/sections/image_gallery.rb b/core/app/models/spree/cms/sections/image_gallery.rbindex d6b0849133..8c47305e63 100644--- a/core/app/models/spree/cms/sections/image_gallery.rb+++ b/core/app/models/spree/cms/sections/image_gallery.rb@@ -1,6 +1,7 @@module Spree::Cms::Sectionsclass ImageGallery < Spree::CmsSectionafter_initialize :default_values+ before_save :reset_link_attributesLINKED_RESOURCE_TYPE = ['Spree::Taxon', 'Spree::Product'].freezeLAYOUT_OPTIONS = ['Default', 'Reversed'].freeze@@ -22,6 +23,22 @@ module Spree::Cms::Sectionsprivate+ def reset_link_attributes+ return if Rails::VERSION::STRING < '6.0'++ if link_type_one_changed?+ self.link_one = nil+ end++ if link_type_two_changed?+ self.link_two = nil+ end++ if link_type_three_changed?+ self.link_three = nil+ end+ end+def default_valuesself.layout_style ||= 'Default'self.fit ||= 'Container'diff --git a/core/app/models/spree/cms/sections/side_by_side_images.rb b/core/app/models/spree/cms/sections/side_by_side_images.rbindex 4b5b2cd617..bcc5e88d34 100644--- a/core/app/models/spree/cms/sections/side_by_side_images.rb+++ b/core/app/models/spree/cms/sections/side_by_side_images.rb@@ -17,6 +17,8 @@ module Spree::Cms::Sectionsprivatedef reset_link_attributes+ return if Rails::VERSION::STRING < '6.0'+if link_type_one_changed?self.link_one = nilenddiff --git a/core/spec/models/spree/cms/sections/image_gallery_spec.rb b/core/spec/models/spree/cms/sections/image_gallery_spec.rbindex 6998aaffa5..0f7985e7c6 100644--- a/core/spec/models/spree/cms/sections/image_gallery_spec.rb+++ b/core/spec/models/spree/cms/sections/image_gallery_spec.rb@@ -58,25 +58,32 @@ describe Spree::Cms::Sections::ImageGallery, type: :model doendend- context 'when changing the link types for links one two and three' do- let!(:image_gallery_section) { create(:cms_image_gallery_section, cms_page: homepage) }+ if Rails::VERSION::STRING >= '6.1'+ context 'when changing the link types for links one two and three' do+ let!(:image_gallery_section) { create(:cms_image_gallery_section, cms_page: homepage) }- before do- section = Spree::CmsSection.find(image_gallery_section.id)+ before do+ section = Spree::CmsSection.find(image_gallery_section.id)- section.content[:link_type_one] = 'Spree::Product'- section.content[:link_type_two] = 'Spree::Product'- section.content[:link_type_three] = 'Spree::Product'- section.save!- section.reload- end+ section.content[:link_type_one] = 'Spree::Product'+ section.content[:link_type_two] = 'Spree::Product'+ section.content[:link_type_three] = 'Spree::Product'- it 'link_one, link_two and link_three are reset to nil' do- section = Spree::CmsSection.find(image_gallery_section.id)+ section.content[:link_one] = 'Shirt 1'+ section.content[:link_two] = 'Shirt 2'+ section.content[:link_three] = 'Shirt 3'++ section.save!+ section.reload+ end++ it 'link_one, link_two and link_three are reset to nil' do+ section = Spree::CmsSection.find(image_gallery_section.id)- expect(section.link_one).to be nil- expect(section.link_two).to be nil- expect(section.link_three).to be nil+ expect(section.link_one).to be nil+ expect(section.link_two).to be nil+ expect(section.link_three).to be nil+ endendendenddiff --git a/core/spec/models/spree/cms/sections/side_by_side_images_spec.rb b/core/spec/models/spree/cms/sections/side_by_side_images_spec.rbindex 7c4030bb53..6059b2f207 100644--- a/core/spec/models/spree/cms/sections/side_by_side_images_spec.rb+++ b/core/spec/models/spree/cms/sections/side_by_side_images_spec.rb@@ -46,20 +46,29 @@ describe Spree::Cms::Sections::SideBySideImages, type: :model doendend- context 'when changing the link types for links one and two' do- let!(:side_by_side_images_section) { create(:cms_side_by_side_images_section, cms_page: homepage) }+ if Rails::VERSION::STRING >= '6.1'+ context 'when changing the link types for links one and two' do+ let!(:side_by_side_images_section) { create(:cms_side_by_side_images_section, cms_page: homepage) }- before do- section = Spree::CmsSection.find(side_by_side_images_section.id)+ before do+ section = Spree::CmsSection.find(side_by_side_images_section.id)- section.content[:link_type_two] = 'Spree::Product'- section.save!- section.reload- end+ section.content[:link_type_one] = 'Spree::Product'+ section.content[:link_type_two] = 'Spree::Product'- it 'link_one and link_two are reset to nil' do- section = Spree::CmsSection.find(side_by_side_images_section.id)- expect(section.link_two).to be nil+ section.content[:link_one] = 'Shirt 1'+ section.content[:link_two] = 'Shirt 2'++ section.save!+ section.reload+ end++ it 'link_one and link_two are reset to nil' do+ section = Spree::CmsSection.find(side_by_side_images_section.id)++ expect(section.link_one).to be nil+ expect(section.link_two).to be nil+ endendendend