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.

Fixed deprecation warnings raised by Spree's own code (#14860)

Damian Legawiec28b150660e24
diff --git a/spree/api/app/controllers/concerns/spree/api/v3/channel_resolution.rb b/spree/api/app/controllers/concerns/spree/api/v3/channel_resolution.rb
index 3789ed2cd5..dbc62a78a4 100644
--- a/spree/api/app/controllers/concerns/spree/api/v3/channel_resolution.rb
+++ b/spree/api/app/controllers/concerns/spree/api/v3/channel_resolution.rb
@@ -60,7 +60,7 @@ module Spree
render_error(
code: ErrorHandler::ERROR_CODES[:channel_mismatch],
message: I18n.t('spree.api.errors.channel_mismatch'),
- status: :unprocessable_entity
+ status: :unprocessable_content
)
return
end
diff --git a/spree/api/app/controllers/spree/api/v3/admin/delivery_methods/rules_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/delivery_methods/rules_controller.rb
index 8edd2bb898..e934553d00 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/delivery_methods/rules_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/delivery_methods/rules_controller.rb
@@ -17,7 +17,7 @@ module Spree
return render_error(
code: ERROR_CODES[:validation_error],
message: I18n.t('spree.errors.messages.invalid_delivery_method_rule'),
- status: :unprocessable_entity
+ status: :unprocessable_content
)
end
diff --git a/spree/api/app/controllers/spree/api/v3/admin/orders/discounts_controller.rb b/spree/api/app/controllers/spree/api/v3/admin/orders/discounts_controller.rb
index 977ebf17b3..d6bcc25291 100644
--- a/spree/api/app/controllers/spree/api/v3/admin/orders/discounts_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/admin/orders/discounts_controller.rb
@@ -32,7 +32,7 @@ module Spree
if result.success?
render json: { data: serialize_collection(result.value) }, status: :created
else
- render_error(code: ERROR_CODES[:validation_error], message: result.error.to_s, status: :unprocessable_entity)
+ render_error(code: ERROR_CODES[:validation_error], message: result.error.to_s, status: :unprocessable_content)
end
end
end
@@ -93,7 +93,7 @@ module Spree
render_error(
code: ERROR_CODES[:discount_not_editable],
message: I18n.t('spree.errors.messages.promotion_discount_not_editable'),
- status: :unprocessable_entity
+ status: :unprocessable_content
)
end
end
diff --git a/spree/api/app/controllers/spree/api/v3/store/carts/fulfillments_controller.rb b/spree/api/app/controllers/spree/api/v3/store/carts/fulfillments_controller.rb
index 4a130e9db1..d8788c3c1a 100644
--- a/spree/api/app/controllers/spree/api/v3/store/carts/fulfillments_controller.rb
+++ b/spree/api/app/controllers/spree/api/v3/store/carts/fulfillments_controller.rb
@@ -55,7 +55,7 @@ module Spree
render_error(
code: ERROR_CODES[:validation_error],
message: I18n.t('spree.errors.messages.no_pickup_point_provider'),
- status: :unprocessable_entity
+ status: :unprocessable_content
)
return false
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/commission_rates_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/commission_rates_controller_spec.rb
index da0a4a899c..185f2788ca 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/commission_rates_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/commission_rates_controller_spec.rb
@@ -81,7 +81,7 @@ RSpec.describe Spree::Api::V3::Admin::CommissionRatesController, type: :controll
it 'refuses a fixed rate that states no amount anywhere' do
post :create, params: { name: 'Flat', kind: 'fixed', value: '2' }, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
end
it 'names the unknown rule type in the code and its value, not just the sentence' do
@@ -102,7 +102,7 @@ RSpec.describe Spree::Api::V3::Admin::CommissionRatesController, type: :controll
it 'refuses a percentage above one hundred' do
post :create, params: { name: 'Too high', kind: 'percentage', value: '150' }, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(json_response['error']['code']).to eq('validation_error')
end
@@ -160,7 +160,7 @@ RSpec.describe Spree::Api::V3::Admin::CommissionRatesController, type: :controll
rules: [{ type: 'nonsense_rule', preferences: {} }]
}, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
end
it 'refuses a rule naming a record that no longer exists' do
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/delivery_profiles/origin_groups_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/delivery_profiles/origin_groups_controller_spec.rb
index ceeb24f8a0..e764d92795 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/delivery_profiles/origin_groups_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/delivery_profiles/origin_groups_controller_spec.rb
@@ -34,7 +34,7 @@ RSpec.describe Spree::Api::V3::Admin::DeliveryProfiles::OriginGroupsController,
delete :destroy, params: { delivery_profile_id: profile.prefixed_id, id: group.prefixed_id }, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(Spree::DeliveryOriginGroup.exists?(group.id)).to be(true)
end
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/orders/fulfillments_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/orders/fulfillments_controller_spec.rb
index b46a524969..c1cb6309cf 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/orders/fulfillments_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/orders/fulfillments_controller_spec.rb
@@ -430,7 +430,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::FulfillmentsController, type: :con
id: shipment.prefixed_id
}, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
end
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/orders/items_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/orders/items_controller_spec.rb
index dd9d4c2771..e9de191fdf 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/orders/items_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/orders/items_controller_spec.rb
@@ -106,7 +106,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::ItemsController, type: :controller
it 'refuses with the invalid_price code' do
subject
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(json_response['error']['code']).to eq('invalid_price')
end
end
@@ -121,7 +121,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::ItemsController, type: :controller
it 'refuses with the price_override_not_allowed code' do
subject
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(json_response['error']['code']).to eq('price_override_not_allowed')
end
@@ -133,7 +133,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::ItemsController, type: :controller
it 'still refuses with price_override_not_allowed' do
subject
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(json_response['error']['code']).to eq('price_override_not_allowed')
end
end
@@ -199,7 +199,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::ItemsController, type: :controller
it 'refuses with 422 and an actionable message' do
subject
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(json_response['error']['code']).to eq('price_override_not_allowed')
expect(response.body).to include('placed order')
expect(line_item.reload.price_source).to be_nil
@@ -211,7 +211,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::ItemsController, type: :controller
it 'still refuses with price_override_not_allowed' do
subject
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(json_response['error']['code']).to eq('price_override_not_allowed')
end
end
@@ -223,7 +223,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::ItemsController, type: :controller
it 'refuses with 422 and an actionable message' do
subject
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(json_response['error']['code']).to eq('invalid_money_format')
expect(json_response['error']['details']).to eq('price' => ['must be a decimal string like "19.99"'])
expect(line_item.reload.price_source).to be_nil
@@ -236,7 +236,7 @@ RSpec.describe Spree::Api::V3::Admin::Orders::ItemsController, type: :controller
it 'refuses with the invalid_price code' do
subject
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(json_response['error']['code']).to eq('invalid_price')
end
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rb
index eb0f042469..e2f84aaf5c 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/orders_controller_spec.rb
@@ -407,7 +407,7 @@ RSpec.describe Spree::Api::V3::Admin::OrdersController, type: :controller do
it 'refuses with an actionable message' do
expect { subject }.not_to change(Spree::Order, :count)
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(response.body).to include('non-negative number')
end
end
@@ -814,7 +814,7 @@ RSpec.describe Spree::Api::V3::Admin::OrdersController, type: :controller do
items: [{ variant_id: variant.prefixed_id, quantity: 1, price: '-1' }]
}, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(response.body).to include('non-negative number')
expect(order.reload.line_items).to be_empty
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/product_types_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/product_types_controller_spec.rb
index fbedd62e73..1d3031afdd 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/product_types_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/product_types_controller_spec.rb
@@ -112,7 +112,7 @@ RSpec.describe Spree::Api::V3::Admin::ProductTypesController, type: :controller
delete :destroy, params: { id: product_type.prefixed_id }, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(Spree::ProductType.find_by(id: product_type.id)).to be_present
end
end
diff --git a/spree/api/spec/controllers/spree/api/v3/admin/products/digital_assets_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/admin/products/digital_assets_controller_spec.rb
index ef9824ed83..d5648fe181 100644
--- a/spree/api/spec/controllers/spree/api/v3/admin/products/digital_assets_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/admin/products/digital_assets_controller_spec.rb
@@ -86,7 +86,7 @@ RSpec.describe Spree::Api::V3::Admin::Products::DigitalAssetsController, type: :
it 'rejects a file with no attachment' do
post :create, params: { product_id: product.prefixed_id }, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
end
# Dev and test collapse both storage services onto one, so the distinction
@@ -116,7 +116,7 @@ RSpec.describe Spree::Api::V3::Admin::Products::DigitalAssetsController, type: :
authorized_clicks: 0
}, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
end
end
diff --git a/spree/api/spec/controllers/spree/api/v3/seller/orders/returns_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/seller/orders/returns_controller_spec.rb
index 806e3ffefa..a10aafb154 100644
--- a/spree/api/spec/controllers/spree/api/v3/seller/orders/returns_controller_spec.rb
+++ b/spree/api/spec/controllers/spree/api/v3/seller/orders/returns_controller_spec.rb
@@ -147,7 +147,7 @@ RSpec.describe Spree::Api::V3::Seller::Orders::ReturnsController, type: :control
refund_method: 'store_credit', amount: 10_000
}, as: :json
- expect(response).to have_http_status(:unprocessable_entity)
+ expect(response).to have_http_status(:unprocessable_content)
expect(return_record.reload).not_to be_refunded
end
end
diff --git a/spree/common_spree_dependencies.rb b/spree/common_spree_dependencies.rb
index 10469f7afb..c9977a94a8 100644
--- a/spree/common_spree_dependencies.rb
+++ b/spree/common_spree_dependencies.rb
@@ -3,7 +3,7 @@
# the one component of Spree.
source 'https://rubygems.org'
-gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
+gem 'tzinfo-data', platforms: [:windows]
gem 'rails', ENV.fetch('RAILS_VERSION', '~> 8.1.0'), require: false
# Held below 3.0: json 3.0 made JSON.parse's options keyword-only, and Active
diff --git a/spree/core/README.md b/spree/core/README.md
index eda72b4db3..71abb395a6 100644
--- a/spree/core/README.md
+++ b/spree/core/README.md
@@ -40,8 +40,8 @@ Services follow a consistent interface pattern and are located in `app/services/
```ruby
# Add item to cart
-Spree.cart_add_item_service.call(
- order: order,
+Spree.cart_add_item_workflow.call(
+ cart: cart,
variant: variant,
quantity: 1
)
@@ -76,7 +76,7 @@ Swap out default implementations with custom services:
```ruby
# config/initializers/spree.rb
-Spree::Dependencies.cart_add_item_service = 'MyCustom::CartAddItem'
+Spree::Dependencies.cart_add_item_workflow = 'MyCustom::CartAddItem'
```
## Configuration
diff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rb
index e6ebcb3441..acd87c13a9 100644
--- a/spree/core/app/models/spree/order.rb
+++ b/spree/core/app/models/spree/order.rb
@@ -830,7 +830,6 @@ module Spree
end
def fulfill!
- fulfillments.each { |shipment| shipment.update!(self) if shipment.persisted? }
save!
update_statuses!
end
diff --git a/spree/core/app/models/spree/product.rb b/spree/core/app/models/spree/product.rb
index 042e9eaef2..42962386e8 100644
--- a/spree/core/app/models/spree/product.rb
+++ b/spree/core/app/models/spree/product.rb
@@ -713,7 +713,7 @@ module Spree
end
def discontinue!
- self.discontinue_on = Time.current
+ write_publication_date(:discontinue_on, Time.current)
self.status = 'archived'
save(validate: false)
end
diff --git a/spree/core/app/models/spree/product/channels.rb b/spree/core/app/models/spree/product/channels.rb
index 979eefebe9..3595bbc710 100644
--- a/spree/core/app/models/spree/product/channels.rb
+++ b/spree/core/app/models/spree/product/channels.rb
@@ -43,8 +43,7 @@ module Spree
"Spree::Product##{legacy_attr}= is deprecated; set #{publication_attr} on " \
"ProductPublication instead (writes to every channel's publication). "
)
- super(value)
- product_publications.each { |publication| publication.public_send("#{publication_attr}=", value) }
+ write_publication_date(legacy_attr, value)
end
# Reading +available_on+/+discontinue_on+ prefers the current-channel
@@ -92,6 +91,14 @@ module Spree
private
+ # Writes a legacy date column together with the matching date on every
+ # channel's publication, so the two never disagree.
+ def write_publication_date(legacy_attr, value)
+ write_attribute(legacy_attr, value)
+ publication_attr = DEPRECATED_DATE_TO_PUBLICATION_FIELD.fetch(legacy_attr.to_sym)
+ product_publications.each { |publication| publication.public_send("#{publication_attr}=", value) }
+ end
+
def assign_default_store
self.store ||= Spree::Current.store || Spree::Store.default
end
diff --git a/spree/core/app/models/spree/taxon.rb b/spree/core/app/models/spree/taxon.rb
index da57813b0b..6e2c69a312 100644
--- a/spree/core/app/models/spree/taxon.rb
+++ b/spree/core/app/models/spree/taxon.rb
@@ -10,7 +10,7 @@ module Spree
# prefix (ctg), and model_name are all Spree::Category. Only the constant differs,
# so is_a?, STI, polymorphic *_type strings, and class_name: references keep
# resolving to Spree::Category. The warning below fires through Spree's deprecator
- # when this file loads (at boot under eager load, on first reference otherwise).
+ # when this file loads (on first reference; it is kept out of eager loading).
Taxon = Category
Spree::Deprecation.warn('Spree::Taxon is deprecated and will be removed in Spree 6.1. Use Spree::Category instead.')
diff --git a/spree/core/lib/spree/core.rb b/spree/core/lib/spree/core.rb
index b12297de82..2a3d457588 100644
--- a/spree/core/lib/spree/core.rb
+++ b/spree/core/lib/spree/core.rb
@@ -252,7 +252,7 @@ module Spree
# Example:
#
# Spree.dependencies do |dependency|
- # dependency.cart_add_item_service = MyCustomAddToCart
+ # dependency.cart_add_item_workflow = MyCustomAddToCart
# end
#
# This method is defined within the core gem on purpose.
@@ -543,10 +543,10 @@ module Spree
# Dynamic methods for core dependencies
#
# @example Getting a dependency (returns resolved class)
- # Spree.cart_add_item_service.call(order: order, variant: variant)
+ # Spree.cart_add_item_workflow.call(cart: cart, variant: variant)
#
# @example Setting a dependency
- # Spree.cart_add_item_service = MyApp::CartAddItem
+ # Spree.cart_add_item_workflow = MyApp::CartAddItem
def method_missing(method_name, *args, &block)
base_name = method_name.to_s.chomp('=').to_sym
diff --git a/spree/core/lib/spree/core/engine.rb b/spree/core/lib/spree/core/engine.rb
index d9dc9289c1..e82c951b2c 100644
--- a/spree/core/lib/spree/core/engine.rb
+++ b/spree/core/lib/spree/core/engine.rb
@@ -559,6 +559,25 @@ module Spree
)
end
+ # Deprecated constant aliases warn when their file loads. Leaving them
+ # out of eager loading keeps every boot quiet; they still load, and
+ # warn, the first time something references the old name.
+ DEPRECATED_ALIAS_FILES = %w[
+ app/models/concerns/spree/user_methods.rb
+ app/models/spree/asset.rb
+ app/models/spree/classification.rb
+ app/models/spree/promotion/rules/taxon.rb
+ app/models/spree/promotion_rule_taxon.rb
+ app/models/spree/return_authorization_reason.rb
+ app/models/spree/taxon.rb
+ app/services/spree/checkout/add_store_credit.rb
+ app/services/spree/checkout/remove_store_credit.rb
+ ].freeze
+
+ initializer 'spree.deprecated_aliases.skip_eager_load' do
+ Rails.autoloaders.main.do_not_eager_load(*DEPRECATED_ALIAS_FILES.map { |path| root.join(path) })
+ end
+
# filter sensitive information during logging
initializer 'spree.params.filter' do |app|
app.config.filter_parameters += [
diff --git a/spree/core/lib/spree/money.rb b/spree/core/lib/spree/money.rb
index 60e1ad5345..ca9a066a8e 100644
--- a/spree/core/lib/spree/money.rb
+++ b/spree/core/lib/spree/money.rb
@@ -1,6 +1,7 @@
require 'money'
Money.locale_backend = :i18n
+Money.default_currency = 'USD'
Money.rounding_mode = BigDecimal::ROUND_HALF_UP
module Spree
@@ -270,7 +271,6 @@ module Spree
delegate :cents, :currency, :to_d, :positive?, :zero?, to: :money
def initialize(amount, options = {})
- ::Money.default_currency ||= Spree::Store.default.default_currency || 'USD'
@money = Monetize.parse(amount, (options[:currency] || Spree::Store.default.default_currency))
@options = Spree::Money.default_formatting_rules.merge(options)
end
diff --git a/spree/core/lib/spree/testing_support/factories/product_factory.rb b/spree/core/lib/spree/testing_support/factories/product_factory.rb
index fa342f4333..42ea50d9a1 100644
--- a/spree/core/lib/spree/testing_support/factories/product_factory.rb
+++ b/spree/core/lib/spree/testing_support/factories/product_factory.rb
@@ -38,8 +38,17 @@ FactoryBot.define do
price { 19.99 }
compare_at_price { nil }
currency { nil }
+ published_at { nil }
+ unpublished_at { nil }
end
+ # The deprecated +available_on=+/+discontinue_on=+ setters warn, so the
+ # dates go straight onto the legacy columns, which code still reads and
+ # which seed the default-channel publication created below.
+ after(:build) do |product, evaluator|
+ product[:available_on] = evaluator.published_at if evaluator.published_at
+ product[:discontinue_on] = evaluator.unpublished_at if evaluator.unpublished_at
+ end
before(:create) do |_product|
create(:stock_location) unless Spree::StockLocation.any?
end
diff --git a/spree/core/lib/tasks/store_settings.rake b/spree/core/lib/tasks/store_settings.rake
index 97021040eb..cabf025566 100644
--- a/spree/core/lib/tasks/store_settings.rake
+++ b/spree/core/lib/tasks/store_settings.rake
@@ -1,5 +1,8 @@
-namespace :spree do
- namespace :store_settings do
+module Spree
+ # Constants for `rake spree:store_settings:backfill_from_config`. A rake
+ # `namespace` block does not scope constants, so they live here instead of
+ # on Object.
+ module StoreSettingsBackfill
# Settings that moved from Spree::Config onto Spree::Store, mapped to the
# default they carried as globals and — where the two differ — the name the
# store preference goes by. A global still at its default says nothing about
@@ -39,7 +42,11 @@ namespace :spree do
# is no "explicitly set" flag to read. Without this marker, a merchant who
# turns a copied setting off would have it turned back on by the next run.
BACKFILL_MARKER = 'store_settings_backfilled_from_config'.freeze
+ end
+end
+namespace :spree do
+ namespace :store_settings do
desc <<~DESC
Copies commerce settings that moved from Spree::Config onto every store
(Spree 6.0).
@@ -54,11 +61,11 @@ namespace :spree do
afterwards — the globals are deprecated and are deleted in 6.1.
DESC
task backfill_from_config: :environment do
- changed = MOVED_SETTINGS.reject do |name, config|
+ changed = Spree::StoreSettingsBackfill::MOVED_SETTINGS.reject do |name, config|
Spree::Config.send(name) == config[:default]
end
- capture_method = CAPTURE_METHOD_FROM_CONFIG.call
+ capture_method = Spree::StoreSettingsBackfill::CAPTURE_METHOD_FROM_CONFIG.call
capture_method = nil if capture_method == Spree::CaptureMethod::DEFAULT_CAPTURE_METHOD
if changed.empty? && capture_method.nil?
@@ -69,7 +76,7 @@ namespace :spree do
Spree::Store.find_each do |store|
metadata = store.metadata || {}
- if metadata[BACKFILL_MARKER]
+ if metadata[Spree::StoreSettingsBackfill::BACKFILL_MARKER]
puts " #{store.name} (#{store.id}): already backfilled — skipped."
next
end
@@ -97,7 +104,7 @@ namespace :spree do
end
end
- store.metadata = metadata.merge(BACKFILL_MARKER => true)
+ store.metadata = metadata.merge(Spree::StoreSettingsBackfill::BACKFILL_MARKER => true)
store.save!
end
end
diff --git a/spree/core/spec/lib/spree/core/engine_spec.rb b/spree/core/spec/lib/spree/core/engine_spec.rb
index d9ee5c797d..c0d8765914 100644
--- a/spree/core/spec/lib/spree/core/engine_spec.rb
+++ b/spree/core/spec/lib/spree/core/engine_spec.rb
@@ -29,4 +29,13 @@ RSpec.describe Spree::Core::Engine do
expect(Spree.hooks.for('exchanges.create.validate').map(&:class)).to eq([Spree::Returns::EligibilityValidator])
end
end
+
+ describe "'spree.deprecated_aliases.skip_eager_load' initializer" do
+ it 'keeps every deprecated alias file out of eager loading, so booting does not warn' do
+ paths = described_class::DEPRECATED_ALIAS_FILES.map { |path| described_class.root.join(path).to_s }
+
+ expect(paths).to all(satisfy { |path| File.exist?(path) })
+ expect(Rails.autoloaders.main.send(:eager_load_exclusions)).to include(*paths)
+ end
+ end
end
diff --git a/spree/core/spec/lib/tasks/core_spec.rb b/spree/core/spec/lib/tasks/core_spec.rb
index 12c2257871..22caeca013 100644
--- a/spree/core/spec/lib/tasks/core_spec.rb
+++ b/spree/core/spec/lib/tasks/core_spec.rb
@@ -81,25 +81,25 @@ describe 'core:archive_products' do
end
it 'draft, discontinue_on in the past -> archived' do
- product.update(status: 'draft', discontinue_on: 1.day.ago)
+ product.update_columns(status: 'draft', discontinue_on: 1.day.ago)
subject.invoke
expect(product.reload.status).to eq('archived')
end
it 'draft, discontinue_on in the future -> draft' do
- product.update(status: 'draft', discontinue_on: 1.day.from_now)
+ product.update_columns(status: 'draft', discontinue_on: 1.day.from_now)
subject.invoke
expect(product.reload.status).to eq('draft')
end
it 'active, discontinue_on in the past -> archived' do
- product.update(status: 'active', discontinue_on: 1.day.ago)
+ product.update_columns(status: 'active', discontinue_on: 1.day.ago)
subject.invoke
expect(product.reload.status).to eq('archived')
end
it 'active, discontinue_on in the future -> active' do
- product.update(status: 'active', discontinue_on: 1.day.from_now)
+ product.update_columns(status: 'active', discontinue_on: 1.day.from_now)
subject.invoke
expect(product.reload.status).to eq('active')
end
diff --git a/spree/core/spec/lib/tasks/upgrade_manifests_spec.rb b/spree/core/spec/lib/tasks/upgrade_manifests_spec.rb
index 8ca9dd79c2..b6daec846f 100644
--- a/spree/core/spec/lib/tasks/upgrade_manifests_spec.rb
+++ b/spree/core/spec/lib/tasks/upgrade_manifests_spec.rb
@@ -8,14 +8,16 @@ require 'rake'
describe 'spree:upgrade manifests' do
manifests = Dir[Spree::Core::Engine.root.join('lib', 'spree', 'upgrades', '*', 'manifest.yml')].sort
- # Load core's rake files into a throwaway application so tasks other specs
- # load individually don't get their actions registered twice.
- let(:rake_app) do
+ # Load core's rake files once, into a throwaway application, so tasks other
+ # specs load individually don't get their actions registered twice. Those
+ # specs may already have defined the files' constants, so redefining them
+ # here is expected.
+ before(:all) do
original = Rake.application
Rake.application = Rake::Application.new
Rake::Task.define_task(:environment)
- Dir[Spree::Core::Engine.root.join('lib', 'tasks', '*.rake')].sort.each { |file| load file }
- Rake.application
+ silence_warnings { Dir[Spree::Core::Engine.root.join('lib', 'tasks', '*.rake')].sort.each { |file| load file } }
+ @rake_app = Rake.application
ensure
Rake.application = original
end
@@ -44,7 +46,7 @@ describe 'spree:upgrade manifests' do
it 'names a defined rake task for every required step' do
missing = manifest['steps'].reject { |step| step['optional'] }.
map { |step| step['task'] }.
- reject { |task| rake_app.lookup(task) }
+ reject { |task| @rake_app.lookup(task) }
expect(missing).to be_empty, "manifest references undefined rake tasks: #{missing.join(', ')}"
end
diff --git a/spree/core/spec/models/spree/order_spec.rb b/spree/core/spec/models/spree/order_spec.rb
index 32ccf6c27f..c7fc572ce3 100644
--- a/spree/core/spec/models/spree/order_spec.rb
+++ b/spree/core/spec/models/spree/order_spec.rb
@@ -1380,7 +1380,7 @@ describe Spree::Order, type: :model do
end
it 'returns the same promotion code after line item removal' do
- Spree::Carts::RemoveLineItem.call(order: order, line_item: order.line_items.first)
+ Spree.order_remove_line_item_service.call(order: order, line_item: order.line_items.first)
expect(order.reload.promo_code).to eq(coupon_code.code)
end
end
diff --git a/spree/core/spec/models/spree/product/scopes_spec.rb b/spree/core/spec/models/spree/product/scopes_spec.rb
index 0321d94b00..17a05b4754 100644
--- a/spree/core/spec/models/spree/product/scopes_spec.rb
+++ b/spree/core/spec/models/spree/product/scopes_spec.rb
@@ -12,7 +12,7 @@ describe 'Product scopes', type: :model do
end
context 'when not discontinued' do
- let!(:product_2) { create(:product, discontinue_on: Time.current + 1.day) }
+ let!(:product_2) { create(:product, unpublished_at: Time.current + 1.day) }
it { expect(Spree::Product.available).to include(product_2) }
end
diff --git a/spree/core/spec/models/spree/product_spec.rb b/spree/core/spec/models/spree/product_spec.rb
index 8656fc79e7..9a8e13462e 100644
--- a/spree/core/spec/models/spree/product_spec.rb
+++ b/spree/core/spec/models/spree/product_spec.rb
@@ -226,7 +226,7 @@ describe Spree::Product, type: :model do
end
it 'is not available when available_on is in the future' do
- product.available_on = 1.day.from_now
+ product[:available_on] = 1.day.from_now
expect(product).not_to be_available
end
@@ -276,7 +276,7 @@ describe Spree::Product, type: :model do
before { product.make_active_at = Date.today }
context 'make_active_at is a date earlier than discontinue_on' do
- before { product.discontinue_on = 5.days.from_now }
+ before { product[:discontinue_on] = 5.days.from_now }
it 'is valid' do
expect(product).to be_valid
@@ -284,7 +284,7 @@ describe Spree::Product, type: :model do
end
context 'make_active_at is a date earlier than discontinue_on' do
- before { product.discontinue_on = 5.days.ago }
+ before { product[:discontinue_on] = 5.days.ago }
context 'is not valid' do
before { product.valid? }
@@ -296,7 +296,7 @@ describe Spree::Product, type: :model do
context 'make_active_at and discontinue_on are nil' do
before do
- product.discontinue_on = nil
+ product[:discontinue_on] = nil
product.make_active_at = nil
end
@@ -757,7 +757,7 @@ describe Spree::Product, type: :model do
describe '#discontinued?' do
let(:product_live) { build(:product, sku: 'a-sku') }
- let(:product_discontinued) { build(:product, sku: 'a-sku', discontinue_on: Time.now - 1.day) }
+ let(:product_discontinued) { build(:product, sku: 'a-sku', unpublished_at: Time.now - 1.day) }
it 'is false' do
expect(product_live.discontinued?).to be(false)
@@ -1752,7 +1752,7 @@ describe Spree::Product, type: :model do
describe 'scopes' do
describe '.not_discontinued' do
let(:product) { create(:product) }
- let(:discontinued_product) { create(:product, discontinue_on: Time.current - 1.day) }
+ let(:discontinued_product) { create(:product, unpublished_at: Time.current - 1.day) }
context 'when nothing is passed as an argument' do
it 'returns only not discontinued products' do
@@ -1772,9 +1772,9 @@ describe Spree::Product, type: :model do
end
describe '.available' do
- let!(:discontinued_product) { create(:product, discontinue_on: 1.day.ago) }
- let!(:future_product) { create(:product, available_on: 1.day.from_now, status: 'active') }
- let!(:active_product) { create(:product, available_on: 1.day.ago, status: 'active') }
+ let!(:discontinued_product) { create(:product, unpublished_at: 1.day.ago) }
+ let!(:future_product) { create(:product, published_at: 1.day.from_now, status: 'active') }
+ let!(:active_product) { create(:product, published_at: 1.day.ago, status: 'active') }
before do
active_product.default_variant.set_price('USD', 10)
@@ -1785,7 +1785,7 @@ describe Spree::Product, type: :model do
context 'when available_on is specified' do
subject(:available_products) { described_class.available(Time.current) }
- let!(:draft_product) { create(:product, available_on: 1.day.ago, status: 'draft') }
+ let!(:draft_product) { create(:product, published_at: 1.day.ago, status: 'draft') }
before do
draft_product.default_variant.set_price('USD', 10)
diff --git a/spree/core/spec/presenters/spree/data_feeds/google_presenter_spec.rb b/spree/core/spec/presenters/spree/data_feeds/google_presenter_spec.rb
index e96f1198ea..d023f1bec5 100644
--- a/spree/core/spec/presenters/spree/data_feeds/google_presenter_spec.rb
+++ b/spree/core/spec/presenters/spree/data_feeds/google_presenter_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
RSpec.describe Spree::DataFeeds::GooglePresenter do
let(:store) { @default_store }
let(:data_feed) { create(:google_data_feed, store: store) }
- let(:product) { create(:product, available_on: Date.current) }
+ let(:product) { create(:product, published_at: Date.current) }
let!(:variant) { create(:with_image_variant, product: product) }
subject { described_class.new(data_feed) }
@@ -89,7 +89,7 @@ Machine washable.</g:description>')
end
context 'when product is set to backorderable' do
- let(:product) { create(:product, available_on: 1.year.from_now) }
+ let(:product) { create(:product, published_at: 1.year.from_now) }
it 'shows backorder' do
expect(xml).to include('<g:availability>backorder</g:availability>')
@@ -97,7 +97,7 @@ Machine washable.</g:description>')
end
context 'when availability date is nil' do
- let(:product) { create(:product, available_on: nil) }
+ let(:product) { create(:product) }
it 'shows in stock' do
expect(xml).to include('<g:availability>in stock</g:availability>')
diff --git a/spree/core/spec/services/spree/carts/remove_line_item_spec.rb b/spree/core/spec/services/spree/carts/remove_line_item_spec.rb
index 55a96279b4..fbcaa6e610 100644
--- a/spree/core/spec/services/spree/carts/remove_line_item_spec.rb
+++ b/spree/core/spec/services/spree/carts/remove_line_item_spec.rb
@@ -10,7 +10,15 @@ module Spree
let(:execute) { subject.call cart: cart, line_item: line_item }
let(:value) { execute.value }
- before { cart.recalculate_totals! }
+ before do
+ allow(Spree::Deprecation).to receive(:warn)
+ cart.recalculate_totals!
+ end
+
+ it 'warns that it is deprecated' do
+ execute
+ expect(Spree::Deprecation).to have_received(:warn).with(/Spree::Carts::RemoveLineItem is deprecated/)
+ end
context 'remove line item' do
context 'with any quantity' do
diff --git a/spree/core/spec/services/spree/carts/set_quantity_spec.rb b/spree/core/spec/services/spree/carts/set_quantity_spec.rb
index a583d6b9db..05a89ee239 100644
--- a/spree/core/spec/services/spree/carts/set_quantity_spec.rb
+++ b/spree/core/spec/services/spree/carts/set_quantity_spec.rb
@@ -8,6 +8,13 @@ module Spree
let(:cart) { create(:cart, store: store) }
let(:line_item) { create(:line_item, cart: cart, order: nil) }
+ before { allow(Spree::Deprecation).to receive(:warn) }
+
+ it 'warns that it is deprecated' do
+ subject.call(cart: cart, line_item: line_item, quantity: 1)
+ expect(Spree::Deprecation).to have_received(:warn).with(/Spree::Carts::SetQuantity is deprecated/)
+ end
+
context 'with non-backorderable item' do
before do
line_item.variant.stock_levels.first.update(backorderable: false)
diff --git a/spree/lib/generators/spree/install/templates/config/initializers/spree.rb b/spree/lib/generators/spree/install/templates/config/initializers/spree.rb
index 70ae855c8c..f8dea138a3 100644
--- a/spree/lib/generators/spree/install/templates/config/initializers/spree.rb
+++ b/spree/lib/generators/spree/install/templates/config/initializers/spree.rb
@@ -34,8 +34,8 @@
# https://docs.spreecommerce.org/developer/customization/dependencies
Spree.dependencies do |dependencies|
# Example:
- # Uncomment to change the default Service handling adding Items to Cart
- # dependencies.cart_add_item_service = 'MyNewAwesomeService'
+ # Uncomment to change the default workflow handling adding items to the cart
+ # dependencies.cart_add_item_workflow = 'MyNewAwesomeWorkflow'
end
# Spree.api.cart_serializer = 'MyRailsApp::CartSerializer'
diff --git a/spree/providers/meilisearch/spec/requests/spree_meilisearch/search_integration_spec.rb b/spree/providers/meilisearch/spec/requests/spree_meilisearch/search_integration_spec.rb
index 9841d4e40f..852da5b113 100644
--- a/spree/providers/meilisearch/spec/requests/spree_meilisearch/search_integration_spec.rb
+++ b/spree/providers/meilisearch/spec/requests/spree_meilisearch/search_integration_spec.rb
@@ -73,11 +73,11 @@ RSpec.describe 'Meilisearch Integration', type: :controller, if: ENV['MEILISEARC
let!(:draft_product) { create(:product, name: 'Draft Hat', status: 'draft') }
let!(:future_product) do
- create(:product, name: 'Future Coat', status: 'active', store: store, available_on: 2.weeks.from_now, price: 99.99)
+ create(:product, name: 'Future Coat', status: 'active', store: store, published_at: 2.weeks.from_now, price: 99.99)
end
let!(:discontinued_product) do
- create(:product, name: 'Old Jacket', status: 'active', store: store, discontinue_on: 2.days.ago, price: 49.99)
+ create(:product, name: 'Old Jacket', status: 'active', store: store, unpublished_at: 2.days.ago, price: 49.99)
end
before do