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.

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.rb
index 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::Sections
class ImageGallery < Spree::CmsSection
after_initialize :default_values
+ before_save :reset_link_attributes
LINKED_RESOURCE_TYPE = ['Spree::Taxon', 'Spree::Product'].freeze
LAYOUT_OPTIONS = ['Default', 'Reversed'].freeze
@@ -22,6 +23,22 @@ module Spree::Cms::Sections
private
+ 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_values
self.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.rb
index 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::Sections
private
def reset_link_attributes
+ return if Rails::VERSION::STRING < '6.0'
+
if link_type_one_changed?
self.link_one = nil
end
diff --git a/core/spec/models/spree/cms/sections/image_gallery_spec.rb b/core/spec/models/spree/cms/sections/image_gallery_spec.rb
index 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 do
end
end
- 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
+ end
end
end
end
diff --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.rb
index 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 do
end
end
- 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
+ end
end
end
end