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
Remove more dead code (#13681)
Damian Legawiec4fad19565d41
diff --git a/spree/core/app/helpers/spree/base_helper.rb b/spree/core/app/helpers/spree/base_helper.rbindex 9834c7c919..8a961cc243 100644--- a/spree/core/app/helpers/spree/base_helper.rb+++ b/spree/core/app/helpers/spree/base_helper.rb@@ -68,30 +68,10 @@ module Spreeendend- def spree_favicon_path- Spree::Deprecation.warn('BaseHelper#spree_favicon_path is deprecated and will be removed in Spree 5.5. Please use Active Storage URL helpers instead.')-- if current_store.favicon.present?- main_app.cdn_image_url(current_store.favicon)- else- url_for('favicon.ico')- end- end-def objectinstance_variable_get('@' + controller_name.singularize)end- def method_missing(method_name, *args, &block)- if image_style = image_style_from_method_name(method_name)- Spree::Deprecation.warn("#{BaseHelper.name}##{method_name} is deprecated and will be removed in Spree 5.5. Please use spree_image_tag instead - https://spreecommerce.org/docs/developer/core-concepts/images-assets#preprocessed-named-variants")- define_image_method(image_style)- send(method_name, *args)- else- super- end- end-def pretty_time(time)return '' if time.blank?@@ -221,36 +201,6 @@ module Spreeprivate- def create_product_image_tag(image, product, options, style)- options[:alt] = image.alt.blank? ? product.name : image.alt- image_tag main_app.cdn_image_url(image.url(style)), options- end-- def define_image_method(style)- self.class.send :define_method, "#{style}_image" do |product, *options|- options = options.first || {}- options[:alt] ||= product.name- image_path = default_image_for_product_or_variant(product)- img = if image_path.present?- create_product_image_tag image_path, product, options, style- else- width = style.to_s.split('x').first.to_i- height = style.to_s.split('x').last.to_i- content_tag(:div, width: width, height: height, style: "background-color: #f0f0f0;")- end-- content_tag(:div, img, class: "admin-product-image-container #{style}-img")- end- end-- # Returns style of image or nil- def image_style_from_method_name(method_name)- style = method_name.to_s.sub(/_image$/, '')- if method_name.to_s.match(/_image$/) && Spree::Image.styles.keys.map(&:to_s).include?(style)- style- end- end-I18N_PLURAL_MANY_COUNT = 2.1def plural_resource_name(resource_class)resource_class.model_name.human(count: I18N_PLURAL_MANY_COUNT)diff --git a/spree/core/app/models/concerns/spree/image_methods.rb b/spree/core/app/models/concerns/spree/image_methods.rbindex 20e6ed623a..7ac3ec1aa6 100644--- a/spree/core/app/models/concerns/spree/image_methods.rb+++ b/spree/core/app/models/concerns/spree/image_methods.rb@@ -3,6 +3,8 @@ module Spreeextend ActiveSupport::Concerndef generate_url(size:, gravity: 'centre', quality: 80, background: [0, 0, 0])+ Spree::Deprecation.warn("ImageMethods#generate_url is deprecated and will be removed in Spree 6.0. Please use active storage variants with cdn_image_url")+return if size.blank?size = size.gsub(/\s+/, '')@@ -18,6 +20,8 @@ module Spreeenddef original_url+ Spree::Deprecation.warn("ImageMethods#original_url is deprecated and will be removed in Spree 6.0. Please use active storage variants with cdn_image_url")+cdn_image_url(attachment)enddiff --git a/spree/core/app/models/spree/ability.rb b/spree/core/app/models/spree/ability.rbindex d9d52970f0..b5ec0f943b 100644--- a/spree/core/app/models/spree/ability.rb+++ b/spree/core/app/models/spree/ability.rb@@ -59,6 +59,8 @@ module Spree# Include any abilities registered by extensions, etc.# this is legacy behaviour and should be removed in Spree 5.0Ability.abilities.merge(abilities_to_register).each do |clazz|+ Spree::Deprecation.warn("Ability merging is deprecated and will be removed in Spree 5.5. Please use Permission Sets")+merge clazz.new(@user)endend@@ -133,6 +135,7 @@ module Spreeenddef apply_admin_permissions(_user, _options)+ Spree::Deprecation.warn("Ability#apply_admin_permissions is deprecated and will be removed in Spree 5.5. Please use Permission Sets")can :manage, :allcannot :cancel, Spree::Ordercan :cancel, Spree::Order, &:allow_cancel?@@ -143,6 +146,8 @@ module Spreeenddef apply_user_permissions(user, _options)+ Spree::Deprecation.warn("Ability#apply_user_permissions is deprecated and will be removed in Spree 5.5. Please use Permission Sets")+can :read, ::Spree::Countrycan :read, ::Spree::OptionTypecan :read, ::Spree::OptionValuediff --git a/spree/core/app/models/spree/image.rb b/spree/core/app/models/spree/image.rbindex 7becca3dca..13295b33a3 100644--- a/spree/core/app/models/spree/image.rb+++ b/spree/core/app/models/spree/image.rb@@ -1,8 +1,10 @@module Spreeclass Image < Asset- include Spree::Image::Configuration::ActiveStorage+ include Spree::Image::Configuration::ActiveStorage # legacy to be removed in Spree 6include Rails.application.routes.url_helpers- include Spree::ImageMethods+ include Spree::ImageMethods # legacy, will be removed in Spree 6++ validates :attachment, attached: true, content_type: Rails.application.config.active_storage.web_image_content_typesafter_commit :touch_product_variants, if: :should_touch_product_variants?, on: :updateafter_commit :update_variant_thumbnail, on: [:create, :destroy]@@ -19,7 +21,10 @@ module Spree# The line below prevents the error.self.inheritance_column = nil+ # @deprecateddef styles+ Spree::Deprecation.warn("Image#styles is deprecated and will be removed in Spree 6.0. Please use active storage variants with cdn_image_url")+self.class.styles.map do |_, size|width, height = size.chop.split('x').map(&:to_i)@@ -32,35 +37,6 @@ module Spreeendend- def style(name)- size = self.class.styles[name]- return unless size-- width, height = size.chop.split('x').map(&:to_i)-- {- url: generate_url(size: size),- size: size,- width: width,- height: height- }- end-- def style_dimensions(name)- size = self.class.styles[name]- width, height = size.chop.split('x').map(&:to_i)-- {- width: width,- height: height- }- end-- def plp_url- Spree::Deprecation.warn "Image#plp_url is deprecated. Use variant(:large) instead."- generate_url(size: self.class.styles[:large])- end-privatedef touch_product_variantsdiff --git a/spree/core/app/models/spree/image/configuration/active_storage.rb b/spree/core/app/models/spree/image/configuration/active_storage.rbindex 59bd0acbd0..e8a5583ef1 100644--- a/spree/core/app/models/spree/image/configuration/active_storage.rb+++ b/spree/core/app/models/spree/image/configuration/active_storage.rb@@ -5,8 +5,6 @@ module Spreeextend ActiveSupport::Concernincluded do- validates :attachment, attached: true, content_type: Rails.application.config.active_storage.web_image_content_types-# Returns image styles derived from Spree::Config.product_image_variant_sizes# Format: { variant_name: 'WxH>' } for API compatibilitydef self.stylesdiff --git a/spree/core/app/models/spree/shipment/emails.rb b/spree/core/app/models/spree/shipment/emails.rbindex d5025649b3..1adf2fb680 100644--- a/spree/core/app/models/spree/shipment/emails.rb+++ b/spree/core/app/models/spree/shipment/emails.rb@@ -2,6 +2,7 @@ module Spreeclass Shipment < Spree.base_classmodule Emailsdef send_shipped_email+ Spree::Deprecation.warn("Shipment#send_shipped_email is deprecated and will be removed in Spree 5.5. Please use events")# you can overwrite this method in your application / extension to send out the confirmation email# or use `spree_emails` gem# YourEmailVendor.deliver_shipment_notification_email(@shipment.id)diff --git a/spree/core/app/models/spree/store_favicon_image.rb b/spree/core/app/models/spree/store_favicon_image.rbdeleted file mode 100644index 71917ea037..0000000000--- a/spree/core/app/models/spree/store_favicon_image.rb+++ /dev/null@@ -1,20 +0,0 @@-module Spree- class StoreFaviconImage < Asset- VALID_CONTENT_TYPES = ['image/png', 'image/x-icon', 'image/vnd.microsoft.icon'].freeze-- validates :attachment,- content_type: VALID_CONTENT_TYPES,- size: { less_than_or_equal_to: 1.megabyte }-- validates :attachment,- if: :is_png?,- dimension: { max: 256..256 },- aspect_ratio: :square-- private-- def is_png?- attachment.content_type.in?('image/png')- end- end-enddiff --git a/spree/core/app/models/spree/store_logo.rb b/spree/core/app/models/spree/store_logo.rbdeleted file mode 100644index 9d796d18a8..0000000000--- a/spree/core/app/models/spree/store_logo.rb+++ /dev/null@@ -1,4 +0,0 @@-module Spree- class StoreLogo < Asset- end-enddiff --git a/spree/core/app/models/spree/store_mailer_logo.rb b/spree/core/app/models/spree/store_mailer_logo.rbdeleted file mode 100644index ac95f4665c..0000000000--- a/spree/core/app/models/spree/store_mailer_logo.rb+++ /dev/null@@ -1,7 +0,0 @@-module Spree- class StoreMailerLogo < Asset- VALID_CONTENT_TYPES = ['image/png', 'image/jpg', 'image/jpeg'].freeze-- validates :attachment, content_type: VALID_CONTENT_TYPES- end-enddiff --git a/spree/core/app/models/spree/taxon.rb b/spree/core/app/models/spree/taxon.rbindex d263ef5c13..e6923e0ca7 100644--- a/spree/core/app/models/spree/taxon.rb+++ b/spree/core/app/models/spree/taxon.rb@@ -38,8 +38,6 @@ module Spreehas_one :store, through: :taxonomyhas_many :classifications, -> { order(:position) }, dependent: :destroy_async, inverse_of: :taxonhas_many :products, through: :classifications- # @deprecated Use Spree::Taxon#image (Active Storage) instead. Will be removed in Spree 5.5.- has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::TaxonImage'has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon', dependent: :destroyhas_many :prototypes, through: :prototype_taxons, class_name: 'Spree::Prototype'@@ -60,7 +58,6 @@ module Spreevalidates :taxonomy, presence: truevalidates :permalink, uniqueness: { case_sensitive: false, scope: [:parent_id, :taxonomy_id] }validates :hide_from_nav, inclusion: { in: [true, false] }- validates_associated :iconvalidate :check_for_root, on: :createvalidate :parent_belongs_to_same_taxonomywith_options length: { maximum: 255 }, allow_blank: true dodiff --git a/spree/core/app/models/spree/taxon_image.rb b/spree/core/app/models/spree/taxon_image.rbdeleted file mode 100644index 1153ec7f23..0000000000--- a/spree/core/app/models/spree/taxon_image.rb+++ /dev/null@@ -1,28 +0,0 @@-module Spree- # @deprecated Use Spree::Taxon#image (Active Storage) instead. Will be removed in Spree 5.5.- class TaxonImage < Asset- include Spree::TaxonImage::Configuration::ActiveStorage- include Rails.application.routes.url_helpers- include Spree::ImageMethods-- after_initialize do- Spree::Deprecation.warn(- 'Spree::TaxonImage is deprecated and will be removed in Spree 5.5. ' \- 'Please use Spree::Taxon#image (Active Storage) instead.'- )- end-- def styles- self.class.styles.map do |_, size|- width, height = size[/(\d+)x(\d+)/].split('x').map(&:to_i)-- {- url: generate_url(size: size),- size: size,- width: width,- height: height- }- end- end- end-enddiff --git a/spree/core/app/models/spree/taxon_image/configuration/active_storage.rb b/spree/core/app/models/spree/taxon_image/configuration/active_storage.rbdeleted file mode 100644index dfcb16d972..0000000000--- a/spree/core/app/models/spree/taxon_image/configuration/active_storage.rb+++ /dev/null@@ -1,26 +0,0 @@-module Spree- class TaxonImage < Asset- module Configuration- module ActiveStorage- extend ActiveSupport::Concern-- included do- validates :attachment, content_type: Rails.application.config.active_storage.web_image_content_types-- default_scope { includes(attachment_attachment: :blob) }-- def self.styles- @styles ||= {- mini: '32x32>',- normal: '128x128>'- }- end-- def default_style- :mini- end- end- end- end- end-enddiff --git a/spree/core/lib/spree/testing_support/factories/favicon_image_factory.rb b/spree/core/lib/spree/testing_support/factories/favicon_image_factory.rbdeleted file mode 100644index 9ba38cba6e..0000000000--- a/spree/core/lib/spree/testing_support/factories/favicon_image_factory.rb+++ /dev/null@@ -1,9 +0,0 @@-FactoryBot.define do- factory :favicon_image, class: Spree::StoreFaviconImage do- transient do- filepath { Spree::Core::Engine.root.join('spec', 'fixtures', 'favicon.ico') }- end-- attachment { Rack::Test::UploadedFile.new(filepath) }- end-enddiff --git a/spree/core/lib/spree/testing_support/factories/taxon_image_factory.rb b/spree/core/lib/spree/testing_support/factories/taxon_image_factory.rbdeleted file mode 100644index 7ce5f6a4c2..0000000000--- a/spree/core/lib/spree/testing_support/factories/taxon_image_factory.rb+++ /dev/null@@ -1,9 +0,0 @@-FactoryBot.define do- factory :taxon_image, class: Spree::TaxonImage do- before(:create) do |taxon_image|- if taxon_image.class.method_defined?(:attachment)- taxon_image.attachment.attach(io: File.new(Spree::Core::Engine.root + 'spec/fixtures/thinking-cat.jpg'), filename: 'thinking-cat.jpg')- end- end- end-enddiff --git a/spree/core/lib/spree/testing_support/flash.rb b/spree/core/lib/spree/testing_support/flash.rbdeleted file mode 100644index 9f6c9ca894..0000000000--- a/spree/core/lib/spree/testing_support/flash.rb+++ /dev/null@@ -1,25 +0,0 @@-module Spree- module TestingSupport- module Flash- def assert_flash_success(flash)- flash = convert_flash(flash)-- within("[class='flash success']") do- expect(page).to have_content(flash)- end- end-- def assert_successful_update_message(resource)- flash = Spree.t(:successfully_updated, resource: Spree.t(resource))- assert_flash_success(flash)- end-- private-- def convert_flash(flash)- flash = Spree.t(flash) if flash.is_a?(Symbol)- flash- end- end- end-enddiff --git a/spree/core/lib/spree/testing_support/flatpickr_capybara.rb b/spree/core/lib/spree/testing_support/flatpickr_capybara.rbdeleted file mode 100644index 19dcb60285..0000000000--- a/spree/core/lib/spree/testing_support/flatpickr_capybara.rb+++ /dev/null@@ -1,124 +0,0 @@-module Spree- module TestingSupport- module FlatpickrCapybara- def fill_in_date_manually(label_text, options = {})- with_open_flatpickr(label_text) do |field|- fill_in field[:id], with: string_date(options)- end- end-- def fill_in_date_picker(label_text, options = {})- if options[:hour].blank? && options[:minute].blank?- flatpickr_date_only(label_text, options)- else- flatpickr_date_time(label_text, options)- end- end-- def fill_in_date_with_js(label_text, options = {})- date_field = find("input[id='#{label_text}']")- script = "document.querySelector('#{date_field}').flatpickr().setDate('#{string_date(options)}');"-- page.execute_script(script)- end-- private-- def flatpickr_date_only(label_text, options = {})- within_open_flatpickr(label_text) do- within_flatpickr_months do- fill_in_flatpickr_year(options[:year].to_i)- sleep(0.25) # Pause to let JavaScript adjust the month selector in the flatpickr cal in relation to any related FROM...TO cal.-- select_flatpickr_month(options[:month].to_i)- sleep(0.25) # Pause to let JavaScript adjust the day selection area in the flatpickr cal in relation to any related FROM...TO cal.-- click_on_flatpickr_day(options[:day].to_i)- end- end- end-- def flatpickr_date_time(label_text, options = {})- within_open_flatpickr(label_text) do- within_flatpickr_months do- fill_in_flatpickr_year(options[:year].to_i)- sleep(0.25) # Pause to let JavaScript adjust the month selector in the flatpickr cal in relation to any related FROM...TO cal.-- select_flatpickr_month(options[:month].to_i)- sleep(0.25) # Pause to let JavaScript adjust the day selection area in the flatpickr cal in relation to any related FROM...TO cal.-- click_on_flatpickr_day(options[:day].to_i)- end-- within_flatpickr_time do- select_flatpickr_hour(options[:hour].to_i)- select_flatpickr_min(options[:minute].to_i)- end- end- end-- def with_open_flatpickr(label_text)- field_label = find_field(id: label_text, type: :hidden)-- date_field = field_label.sibling('.flatpickr-alt-input')- date_field.click # Open the flatpickr cal.- sleep(0.25) # Pause to let JavaScript populate DOM with an open flatpickr cal.-- yield(date_field) # Complete required action within the open flatpickr cal.-- date_field.send_keys :tab # Close the date flatpickr cal.- sleep(0.25) # Pause to let JavaScript adjust any DOM values in relation to any related FROM...TO cal.- end-- def within_open_flatpickr(label_text, &block)- with_open_flatpickr(label_text) do- within find('.flatpickr-calendar.open', &block)- end- end-- def within_flatpickr_months(&block)- within find('.flatpickr-months > .flatpickr-month > .flatpickr-current-month', &block)- end-- def within_flatpickr_time(&block)- within find('.flatpickr-time', &block)- end-- def select_flatpickr_month(month)- accurate_month = (month.to_i - 1)-- find("select.flatpickr-monthDropdown-months > option[value='#{accurate_month}']").select_option- end-- def fill_in_flatpickr_year(year)- find('input.cur-year').set(year)- end-- def click_on_flatpickr_day(day)- within_flatpickr_days do- find('.flatpickr-day:not(.prevMonthDay):not(.nextMonthDay)', text: day, exact_text: true).click- end- end-- def within_flatpickr_days(&block)- within find('.flatpickr-innerContainer > .flatpickr-rContainer > .flatpickr-days > .dayContainer', &block)- end-- def select_flatpickr_hour(hour)- find('input.flatpickr-hour').set(hour)- end-- def select_flatpickr_min(min)- find('input.flatpickr-minute').set(min)- end-- def string_date(options)- if options[:hour].present? && options[:minute].present?- "#{options[:year]}-#{options[:month]}-#{options[:day]}-#{options[:hour]}-#{options[:minute]}"- else- "#{options[:year]}-#{options[:month]}-#{options[:day]}"- end- end- end- end-enddiff --git a/spree/core/lib/tasks/core.rake b/spree/core/lib/tasks/core.rakeindex 75e586164a..1fb13ab8ef 100644--- a/spree/core/lib/tasks/core.rake+++ b/spree/core/lib/tasks/core.rake@@ -1,190 +1,6 @@require 'active_record'namespace :db do- desc %q{Loads a specified fixture file:-use rake db:load_file[/absolute/path/to/sample/filename.rb]}-- task :load_file, [:file, :dir] => :environment do |_t, args|- file = Pathname.new(args.file)-- puts "loading ruby #{file}"- load file- end-- desc 'Loads fixtures from the the dir you specify using rake db:load_dir[loadfrom]'- task :load_dir, [:dir] => :environment do |_t, args|- dir = args.dir- dir = File.join(Rails.root, 'db', dir) if Pathname.new(dir).relative?-- ruby_files = {}- Dir.glob(File.join(dir, '**/*.{rb}')).each do |fixture_file|- ext = File.extname fixture_file- ruby_files[File.basename(fixture_file, '.*')] = fixture_file- end- ruby_files.sort.each do |fixture, ruby_file|- # If file exists within application it takes precedence.- if File.exist?(File.join(Rails.root, 'db/default/spree', "#{fixture}.rb"))- ruby_file = File.expand_path(File.join(Rails.root, 'db/default/spree', "#{fixture}.rb"))- end- # an invoke will only execute the task once- Rake::Task['db:load_file'].execute(Rake::TaskArguments.new([:file], [ruby_file]))- end- end-- desc 'Migrate schema to version 0 and back up again. WARNING: Destroys all data in tables!!'- task remigrate: :environment do- require 'highline/import'-- if ENV['SKIP_NAG'] || ENV['OVERWRITE'].to_s.casecmp('true').zero? || agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [y/n] ")-- # Drop all tables- ActiveRecord::Base.connection.tables.each { |t| ActiveRecord::Base.connection.drop_table t }-- # Migrate upward- Rake::Task['db:migrate'].invoke-- # Dump the schema- Rake::Task['db:schema:dump'].invoke- else- say 'Task cancelled.'- exit- end- end-- desc 'Bootstrap is: migrating, loading defaults, sample data and seeding (for all extensions) and load_products tasks'- task :bootstrap do- require 'highline/import'-- # remigrate unless production mode (as safety check)- if %w[demo development test].include? Rails.env- if ENV['AUTO_ACCEPT'] || agree("This task will destroy any data in the database. Are you sure you want to \ncontinue? [y/n] ")- ENV['SKIP_NAG'] = 'yes'- Rake::Task['db:create'].invoke- Rake::Task['db:remigrate'].invoke- else- say 'Task cancelled, exiting.'- exit- end- else- say 'NOTE: Bootstrap in production mode will not drop database before migration'- Rake::Task['db:migrate'].invoke- end-- ActiveRecord::Base.send(:subclasses).each(&:reset_column_information)-- load_defaults = Spree::Country.count == 0- load_defaults ||= agree('Countries present, load sample data anyways? [y/n]: ')- Rake::Task['db:seed'].invoke if load_defaults-- if Rails.env.production? && Spree::Product.count > 0- load_sample = agree('WARNING: In Production and products exist in database, load sample data anyways? [y/n]:')- else- load_sample = true if ENV['AUTO_ACCEPT']- load_sample ||= agree('Load Sample Data? [y/n]: ')- end-- if load_sample- # Reload models' attributes in case they were loaded in old migrations with wrong attributes- ActiveRecord::Base.descendants.each(&:reset_column_information)- Rake::Task['spree_sample:load'].invoke- end-- puts "Bootstrap Complete.\n\n"- end-- desc 'Fix orphan line items after upgrading to Spree 3.1: only needed if you have line items attached to deleted records with Slug (product) and SKU (variant) duplicates of non-deleted records.'- task fix_orphan_line_items: :environment do |_t, _args|- def get_input- STDOUT.flush- input = STDIN.gets.chomp- case input.upcase- when 'Y'- return true-- when 'N'- puts 'aborting .....'- return false- else- return true- end- end-- puts 'WARNING: This task will re-associate any line_items associated with deleted variants to non-deleted variants with matching SKUs. Because other attributes and product associations may switch during the re-association, this may have unintended side-effects. If this task finishes successfully, line items for old order should no longer be orphaned from their variants. You should run this task after you have already run the db migratoin AddDiscontinuedToProductsAndVariants. If the db migration did not warn you that it was leaving deleted records in place because of duplicate SKUs, then you do not need to run this rake task.'- puts 'Are you sure you want to continue? (Y/n):'-- if get_input- puts 'looping through all your deleted variants ...'-- # first verify that I can really fix all of your line items-- no_live_variants_found = []- variants_to_fix = []-- Spree::Variant.deleted.each do |variant|- # check if this variant has any line items at all- next if variant.line_items.none?-- variants_to_fix << variant- dup_variant = Spree::Variant.find_by(sku: variant.sku)- if dup_variant- # this variant is OK- else- no_live_variants_found << variant- end- end-- if variants_to_fix.none?- abort('ABORT: You have no deleted variants that are associated to line items. You do not need to run this raks task.')- end-- if no_live_variants_found.any?- puts "ABORT: Unfortunately, I found some deleted variants in your database that do not have matching non-deleted variants to replace them with. This script can only be used to cleanup deleted variants that have SKUs that match non-deleted variants. To continue, you must either (1) un-delete these variants (hint: mark them 'discontinued' instead) or (2) create new variants with a matching SKU for each variant in the list below."- no_live_variants_found.each do |deleted_variant|- puts "variant id #{deleted_variant.id} (sku is '#{deleted_variant.sku}') ... no match found"- end- abort- end-- puts 'Ready to fix...'- variants_to_fix.each do |variant|- dup_variant = Spree::Variant.find_by(sku: variant.sku)- puts "Changing all line items for #{variant.sku} variant id #{variant.id} (deleted) to variant id #{dup_variant.id} (not deleted) ..."- Spree::LineItem.unscoped.where(variant_id: variant.id).update_all(variant_id: dup_variant.id)- end-- puts 'DONE ! Your database should no longer have line items that are associated with deleted variants.'- end- end-- desc 'Migrates taxon icons to spree assets after upgrading to Spree 3.4: only needed if you used taxons icons.'- task migrate_taxon_icons: :environment do |_t, _args|- Spree::Taxon.where.not(icon_file_name: nil).find_each do |taxon|- taxon.create_icon(attachment_file_name: taxon.icon_file_name,- attachment_content_type: taxon.icon_content_type,- attachment_file_size: taxon.icon_file_size,- attachment_updated_at: taxon.icon_updated_at)- end- end-- desc 'Migrates taxon icons to taxon images after upgrading to Spree 3.7: only needed if you used taxons icons.'- task migrate_taxon_icons_to_images: :environment do |_t, _args|- Spree::Asset.where(type: 'Spree::TaxonIcon').update_all(type: 'Spree::TaxonImage')- end-- desc 'Ensure all Order associated with Store after upgrading to Spree 3.7'- task associate_orders_with_store: :environment do |_t, _args|- Spree::Order.where(store_id: nil).update_all(store_id: Spree::Store.default.id)- end-- desc 'Ensure all Order has currency present after upgrading to Spree 3.7'- task ensure_order_currency_presence: :environment do |_t, _args|- Spree::Order.where(currency: nil).find_in_batches do |orders|- orders.each do |order|- order.update!(currency: order.store.default_currency)- end- end- end-task migrate_admin_users_to_role_users: :environment do |_t, _args|default_store = Spree::Store.defaultSpree::RoleUser.where(resource: nil).each do |role_user|@@ -218,32 +34,6 @@ use rake db:load_file[/absolute/path/to/sample/filename.rb]}puts "Migrated #{policy_slug} to store #{store.id}"endend-- Spree::PageLink.where(linkable_type: 'ActionText::RichText').each do |page_link|- # Check if this page link is attached to ActionText content- # Find the ActionText record- action_text = ActionText::RichText.find_by(id: page_link.linkable_id)- next unless action_text-- # Check if the ActionText belongs to a store policy- if action_text.record_type == 'Spree::Store' && action_text.name.to_s.include?('policy')- # Find the corresponding policy in the new policies system- store = action_text.record- policy_name = derive_policy_name.call(action_text.name)-- policy = store.policies.find_by(name: Spree.t(policy_name))-- if policy- # Update the page link to point to the policy instead- page_link.update!(- linked_resource_type: 'Spree::Policy',- linked_resource_id: policy.id- )-- puts "Migrated #{policy_name} to store #{store.id}"- end- end- endenddesc 'Migrate product properties to metafields'@@ -266,41 +56,6 @@ use rake db:load_file[/absolute/path/to/sample/filename.rb]}endendend-- desc 'Migrate product details sections to PDP 2.0 with blocks and metafields'- task migrate_product_details_pages: :environment do |_t, _args|- Spree::PageSections::ProductDetails.find_each do |section|- next if section.blocks.any?-- if defined?(SpreeMultiTenant)- SpreeMultiTenant.with_tenant(section.tenant) do- section.send(:create_blocks)- end- else- section.send(:create_blocks)- end- end-- Spree::Pages::ProductDetails.find_each do |page|- next if page.sections.exists?(type: 'Spree::PageSections::Breadcrumbs')-- block = proc do- breadcrumbs = page.sections.create!(type: 'Spree::PageSections::Breadcrumbs')- breadcrumbs.move_to_top-- page_details = page.sections.find_by(type: 'Spree::PageSections::ProductDetails')- if page_details.present?- page_details.update!(preferred_top_padding: 0, preferred_top_border_width: 0)- end- end-- if defined?(SpreeMultiTenant)- SpreeMultiTenant.with_tenant(page.tenant, &block)- else- block.call- end- end- endendnamespace :core dodiff --git a/spree/core/spec/helpers/base_helper_spec.rb b/spree/core/spec/helpers/base_helper_spec.rbindex 1c095bd3a3..84357bb4d2 100644--- a/spree/core/spec/helpers/base_helper_spec.rb+++ b/spree/core/spec/helpers/base_helper_spec.rb@@ -100,46 +100,6 @@ describe Spree::BaseHelper, type: :helper doendend- # Regression test for #1436- context 'defining custom image helpers' do- let(:product) { build(:product) }-- before do- module ImageDecorator- module ClassMethods- def styles- super.merge(- very_strange: '1x1',- foobar: '2x2'- )- end- end-- def self.prepended(base)- base.singleton_class.prepend ClassMethods- end- end-- Spree::Image.prepend(ImageDecorator)- end-- it 'does not raise errors when style exists' do- expect { very_strange_image(product) }.not_to raise_error- end-- it 'raises NoMethodError when style is not exists' do- expect { another_strange_image(product) }.to raise_error(NoMethodError)- end-- it 'does not raise errors when helper method called' do- expect { foobar_image(product) }.not_to raise_error- end-- it 'raises NoMethodError when statement with name equal to style name called' do- expect { foobar(product) }.to raise_error(NoMethodError)- end- end-context 'link_to_tracking' doit 'returns tracking link if available' doa = link_to_tracking_html(shipping_method: true, tracking: '123', tracking_url: 'http://g.c/?t=123').css('a')@@ -301,21 +261,4 @@ describe Spree::BaseHelper, type: :helper doendendend-- describe '#spree_favicon_path' do- context 'when a store has its own favicon' do- let(:current_store) { create(:store, :with_favicon) }-- it do- expect(spree_favicon_path).to end_with('thinking-cat.jpg')- expect(URI.parse(spree_favicon_path).host).to be_present- end- end-- context 'when a store has no favicon' do- it do- expect(spree_favicon_path).to eq('favicon.ico')- end- end- endenddiff --git a/spree/core/spec/models/spree/image_spec.rb b/spree/core/spec/models/spree/image_spec.rbindex ba71c48227..719a891b6b 100644--- a/spree/core/spec/models/spree/image_spec.rb+++ b/spree/core/spec/models/spree/image_spec.rb@@ -31,21 +31,7 @@ describe Spree::Image, type: :model doit 'will return all styles for the image' dospree_image.attachment.attach(io: image_file, filename: 'thinking-cat.jpg', content_type: 'image/jpeg')spree_image.save!- res = spree_image.styles-- expect(res.length).to eq described_class.styles.keys.length- end- end-- describe '#style' do- it 'will return style for the given name' do- spree_image.attachment.attach(io: image_file, filename: 'thinking-cat.jpg', content_type: 'image/jpeg')- spree_image.save!- styles = described_class.styles.keys- random_style_name = styles.sample- res = spree_image.style(random_style_name)-- expect(res[:size]).to eq described_class.styles[random_style_name]+ expect(spree_image.styles).to be_kind_of(Array)endenddiff --git a/spree/core/spec/models/spree/store_favicon_image_spec.rb b/spree/core/spec/models/spree/store_favicon_image_spec.rbdeleted file mode 100644index a365dc07a2..0000000000--- a/spree/core/spec/models/spree/store_favicon_image_spec.rb+++ /dev/null@@ -1,43 +0,0 @@-require 'spec_helper'--describe Spree::StoreFaviconImage, type: :model do- describe 'validations' do- it 'validates image properties' do- expect(build(:favicon_image, filepath: file_fixture('icon_256x256.png'))).to be_valid- expect(build(:favicon_image, filepath: file_fixture('icon_512x512.png'))).not_to be_valid- expect(build(:favicon_image, filepath: file_fixture('icon_256x256.gif'))).not_to be_valid- expect(build(:favicon_image, filepath: file_fixture('img_256x128.png'))).not_to be_valid- end-- context 'file size' do- let(:favicon_image) do- favicon_image = build(:favicon_image)- favicon_image.attachment.attach(io: file, filename: 'favicon.png')- favicon_image- end-- let(:file) { File.open(file_fixture('icon_256x256.png')) }-- before do- allow(file).to receive(:size).and_return(size)- end-- context 'when size is 1 megabyte' do- let(:size) { 1.megabyte }-- it 'is valid' do- expect(favicon_image).to be_valid- end- end-- context 'when size is over 1 megabyte' do- let(:size) { 1.megabyte + 1 }-- it 'is invalid' do- expect(favicon_image).not_to be_valid- end- end- end- end-end-diff --git a/spree/core/spec/models/spree/taxon_image_spec.rb b/spree/core/spec/models/spree/taxon_image_spec.rbdeleted file mode 100644index 4c7e747f31..0000000000--- a/spree/core/spec/models/spree/taxon_image_spec.rb+++ /dev/null@@ -1,19 +0,0 @@-require 'spec_helper'--describe Spree::TaxonImage, type: :model do- context 'validation' do- let(:spree_image) { Spree::TaxonImage.new }- let(:image_file) { File.open(Spree::Core::Engine.root + 'spec/fixtures' + 'thinking-cat.jpg') }- let(:text_file) { File.open(Spree::Core::Engine.root + 'spec/fixtures' + 'text-file.txt') }-- it 'has allowed attachment content type' do- spree_image.attachment.attach(io: image_file, filename: 'thinking-cat.jpg', content_type: 'image/jpeg')- expect(spree_image).to be_valid- end-- it 'has no allowed attachment content type' do- spree_image.attachment.attach(io: text_file, filename: 'text-file.txt', content_type: 'text/plain')- expect(spree_image).not_to be_valid- end- end-end