solidus_core 4.6.1 → 4.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ab07c75d9886b9eda75453847a2a2ec936e5aabd8bff99854a10381c4bd1dc0
4
- data.tar.gz: 58e45a9450049e9efbd8c768875a42eeabcf8529f3c23b2fb087ceaa4bd95099
3
+ metadata.gz: 54346c8f091dd2395832f0e0118d80c50e52f6fc7bda852c0147164061f28055
4
+ data.tar.gz: 445ada16ce8a53ae7f4904fdacae27215954de7f2f1387a39ae4f6b8c8ee73be
5
5
  SHA512:
6
- metadata.gz: 41b675b7a0df269e5ff38496b42eac3b22379192961da29717ed9a8f72b922d478d530cdbc457e6620badb5d9ccc4c006264be968c796a6495774322eabd905e
7
- data.tar.gz: ad1547dd2d1f7f6dcb024200910f59ba1d7f48845b9ae90feccbe1da1dff2da9c215d8a811ad7bd24bfc40b4bbc2be917388917d96285bf64cf67629b81079dc
6
+ metadata.gz: 92d7572979dddd22c078e452a0ade011ac4f230876ea24cbb130917d7c088086d316685e2efe6618d73ed5317a24aa17aeb9376cb6d18c4a4704c56f0f3caf51
7
+ data.tar.gz: e815c14e8992cdb3549c44711338c43e24f8dfe2195b6f0540b9427f0f7043832d94e7f78c32028af579ea842a53a8edbb53714d5fa7ee97fda962e12b8b19c6
@@ -5,21 +5,25 @@ module Spree
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- after_update :enqueue_state_change_tracking, if: :saved_change_to_state?
8
+ after_update :enqueue_state_change_tracking, if: :track_state_change?
9
9
  end
10
10
 
11
11
  private
12
12
 
13
+ def track_state_change?
14
+ saved_change_to_state?
15
+ end
16
+
13
17
  # Enqueue background job to track state changes asynchronously
14
18
  def enqueue_state_change_tracking
15
19
  previous_state, current_state = saved_changes['state']
16
20
 
17
21
  # Enqueue the job to track this state change
18
- StateChangeTrackingJob.perform_later(
19
- self,
20
- previous_state,
21
- current_state,
22
- Time.current
22
+ Spree::Config.state_change_tracking_class.call(
23
+ stateful: self,
24
+ previous_state:,
25
+ current_state:,
26
+ transition_timestamp: Time.current
23
27
  )
24
28
  end
25
29
  end
@@ -83,7 +83,7 @@ module Spree
83
83
  when String
84
84
  separator = I18n.t('number.currency.format.separator')
85
85
  number = amount.delete("^0-9-#{separator}\.").tr(separator, '.')
86
- number.to_d if number.present?
86
+ number.presence&.to_d
87
87
  end || amount
88
88
  end
89
89
 
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ # Configurable class to enqueue state change tracking jobs
5
+ # Configure your custom logic by setting Spree::Config.state_change_tracking_class
6
+ # @example Spree::Config.state_change_tracking_class = MyCustomTracker
7
+ class StateChangeTracker
8
+ # @param stateful [Object] The stateful object to track changes for
9
+ # @param previous_state [String] The previous state of the order
10
+ # @param current_state [String] The current state of the order
11
+ # @param transition_timestamp [Time] When the state transition occurred
12
+ # @param stateful_name [String] The element name of the state transition being
13
+ # tracked. It defaults to the `stateful` model element name.
14
+ def self.call(
15
+ stateful:,
16
+ previous_state:,
17
+ current_state:,
18
+ transition_timestamp:,
19
+ stateful_name: stateful.class.model_name.element
20
+ )
21
+ # Enqueue a background job to track this state change
22
+ StateChangeTrackingJob.perform_later(
23
+ stateful,
24
+ previous_state,
25
+ current_state,
26
+ transition_timestamp,
27
+ stateful_name
28
+ )
29
+ end
30
+ end
31
+ end
@@ -7,7 +7,7 @@ class AddShippingCategoryForeignKeys < ActiveRecord::Migration[7.0]
7
7
  # Uncomment the following code to remove orphaned records if the following code fails
8
8
  #
9
9
  # say_with_time "Removing orphaned products (no corresponding shipping category)" do
10
- # Spree::Product.left_joins(:shipping_category).where(spree_shipping_category: { id: nil }).delete_all
10
+ # Spree::Product.left_joins(:shipping_category).where(spree_shipping_categories: { id: nil }).delete_all
11
11
  # end
12
12
  begin
13
13
  add_foreign_key :spree_products, :spree_shipping_categories, column: :shipping_category_id, null: false
@@ -27,7 +27,7 @@ class AddShippingCategoryForeignKeys < ActiveRecord::Migration[7.0]
27
27
  # Uncomment the following code to remove orphaned records if the following code fails
28
28
  #
29
29
  # say_with_time "Removing orphaned shipping method categories (no corresponding shipping category)" do
30
- # Spree::ShippingMethodCategory.left_joins(:shipping_category).where(spree_shipping_category: { id: nil }).delete_all
30
+ # Spree::ShippingMethodCategory.left_joins(:shipping_category).where(spree_shipping_categories: { id: nil }).delete_all
31
31
  # end
32
32
  begin
33
33
  add_foreign_key :spree_shipping_method_categories, :spree_shipping_methods, column: :shipping_method_id, null: false
@@ -47,7 +47,7 @@ class AddShippingCategoryForeignKeys < ActiveRecord::Migration[7.0]
47
47
  # Uncomment the following code to remove orphaned records if the following code fails
48
48
  #
49
49
  # say_with_time "Removing orphaned shipping method categories (no corresponding shipping method)" do
50
- # Spree::ShippingMethodCategory.left_joins(:shipping_method).where(spree_shipping_method: { id: nil }).delete_all
50
+ # Spree::ShippingMethodCategory.left_joins(:shipping_method).where(spree_shipping_methods: { id: nil }).delete_all
51
51
  # end
52
52
  begin
53
53
  add_foreign_key :spree_shipping_method_categories, :spree_shipping_categories, column: :shipping_category_id, null: false
@@ -4,7 +4,9 @@ begin
4
4
  user_class.classify.constantize
5
5
  rescue NameError
6
6
  say_status :error, "Can't find an existing user class named #{user_class.classify}, plese set up one before using this authentication option.", :red
7
+ # rubocop:disable Rails/Exit
7
8
  abort
9
+ # rubocop:enable Rails/Exit
8
10
  end
9
11
 
10
12
  generate "spree:custom_user #{user_class.shellescape}"
@@ -549,6 +549,13 @@ module Spree
549
549
  product: '680x680>',
550
550
  large: '1200x1200>' }
551
551
 
552
+ # Allows to provide your own class for tracking state changes of stateful models
553
+ #
554
+ # @!attribute [rw] state_change_tracking_class
555
+ # @return [Class] a class with the same public interfaces as
556
+ # Spree::StateChangeTracker.
557
+ class_name_attribute :state_change_tracking_class, default: "Spree::StateChangeTracker"
558
+
552
559
  # Allows providing your own class for prioritizing store credit application
553
560
  # to an order.
554
561
  #
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "4.6.1"
4
+ VERSION = "4.6.2"
5
5
 
6
6
  def self.solidus_version = VERSION
7
7
 
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples "tracking state changes" do
4
+ context "with track_state_change? true" do
5
+ before do
6
+ expect(stateful).to receive(:track_state_change?).and_return(true)
7
+ end
8
+
9
+ it "enqueues state change tracking job" do
10
+ expect { stateful.update!(state:) }
11
+ .to enqueue_job(Spree::StateChangeTrackingJob)
12
+ end
13
+ end
14
+
15
+ context "with track_state_change? false" do
16
+ before do
17
+ expect(stateful).to receive(:track_state_change?).and_return(false)
18
+ end
19
+
20
+ it "does not enqueue state change tracking job" do
21
+ expect { stateful.update!(state:) }
22
+ .not_to enqueue_job(Spree::StateChangeTrackingJob)
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.6.1
4
+ version: 4.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
@@ -684,6 +684,7 @@ files:
684
684
  - app/models/spree/simple_order_contents.rb
685
685
  - app/models/spree/state.rb
686
686
  - app/models/spree/state_change.rb
687
+ - app/models/spree/state_change_tracker.rb
687
688
  - app/models/spree/stock/allocator/base.rb
688
689
  - app/models/spree/stock/allocator/on_hand_first.rb
689
690
  - app/models/spree/stock/availability.rb
@@ -1056,6 +1057,7 @@ files:
1056
1057
  - lib/spree/testing_support/shared_examples/calculator.rb
1057
1058
  - lib/spree/testing_support/shared_examples/gallery.rb
1058
1059
  - lib/spree/testing_support/shared_examples/order_factory.rb
1060
+ - lib/spree/testing_support/shared_examples/state_change_tracking.rb
1059
1061
  - lib/spree/testing_support/shared_examples/working_factory.rb
1060
1062
  - lib/spree/testing_support/silence_deprecations.rb
1061
1063
  - lib/spree/testing_support/translations.rb
@@ -1112,7 +1114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1112
1114
  - !ruby/object:Gem::Version
1113
1115
  version: 1.8.23
1114
1116
  requirements: []
1115
- rubygems_version: 3.6.9
1117
+ rubygems_version: 3.7.2
1116
1118
  specification_version: 4
1117
1119
  summary: Essential models, mailers, and classes for the Solidus e-commerce project.
1118
1120
  test_files: []