Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only default to activestorage adapter if Rails version is supported #4563

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require "spree/core/search/variant"
require 'spree/preferences/configuration'
require 'spree/core/environment'
require 'spree/rails_compatibility'

module Spree
class AppConfiguration < Preferences::Configuration
Expand Down Expand Up @@ -497,7 +498,7 @@ def payment_canceller
# @!attribute [rw] image_attachment_module
# @return [Module] a module that can be included into Spree::Image to allow attachments
# Enumerable of images adhering to the present_image_class interface
class_name_attribute :image_attachment_module, default: 'Spree::Image::ActiveStorageAttachment'
class_name_attribute :image_attachment_module, default: Spree::RailsCompatibility.default_image_attachment_module

# @!attribute [rw] allowed_image_mime_types
#
Expand Down Expand Up @@ -555,7 +556,7 @@ def payment_canceller
# @!attribute [rw] taxon_attachment_module
# @return [Module] a module that can be included into Spree::Taxon to allow attachments
# Enumerable of taxons adhering to the present_taxon_class interface
class_name_attribute :taxon_attachment_module, default: 'Spree::Taxon::ActiveStorageAttachment'
class_name_attribute :taxon_attachment_module, default: Spree::RailsCompatibility.default_taxon_attachment_module

# Configures the absolute path that contains the Solidus engine
# migrations. This will be checked at app boot to confirm that all Solidus
Expand Down
24 changes: 24 additions & 0 deletions core/lib/spree/rails_compatibility.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'rails/gem_version'

module Spree
# Supported Rails versions compatibility
#
Expand Down Expand Up @@ -48,6 +50,28 @@ def self.raise_on_missing_translations(value)
end
end

# Set default image attachment adapter
#
# TODO: Remove when deprecating Rails 6.0
def self.default_image_attachment_module
if version_gte?("6.1")
"Spree::Image::ActiveStorageAttachment"
else
"Spree::Image::PaperclipAttachment"
end
end

# Set default taxon attachment adapter
#
# TODO: Remove when deprecating Rails 6.0
def self.default_taxon_attachment_module
if version_gte?("6.1")
"Spree::Taxon::ActiveStorageAttachment"
else
"Spree::Taxon::PaperclipAttachment"
end
end

# Set current host for ActiveStorage in a controller
#
# Changed from `#host` to including a module in Rails 6
Expand Down