solidus_core 3.4.2 → 4.0.0

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.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/products_helper.rb +1 -1
  3. data/app/models/concerns/spree/active_storage_adapter.rb +0 -17
  4. data/app/models/concerns/spree/default_price.rb +0 -15
  5. data/app/models/concerns/spree/ransackable_attributes.rb +0 -21
  6. data/app/models/spree/adjustment.rb +0 -13
  7. data/app/models/spree/carton.rb +1 -1
  8. data/app/models/spree/fulfilment_changer.rb +2 -14
  9. data/app/models/spree/option_value.rb +2 -11
  10. data/app/models/spree/order.rb +8 -20
  11. data/app/models/spree/order_updater.rb +0 -29
  12. data/app/models/spree/payment.rb +5 -37
  13. data/app/models/spree/product/scopes.rb +0 -5
  14. data/app/models/spree/product.rb +3 -10
  15. data/app/models/spree/promotion/rules/item_total.rb +0 -11
  16. data/app/models/spree/promotion.rb +7 -30
  17. data/app/models/spree/promotion_rule.rb +0 -5
  18. data/app/models/spree/taxon.rb +2 -2
  19. data/app/models/spree/taxonomy.rb +1 -1
  20. data/app/models/spree/variant/price_selector.rb +1 -14
  21. data/app/models/spree/variant.rb +1 -17
  22. data/db/migrate/20210815004823_add_unique_index_to_option_values_variants.rb +16 -0
  23. data/db/migrate/20230321161854_change_column_null_option_values_option_type_id.rb +5 -0
  24. data/db/migrate/20230322085416_remove_match_policy_from_spree_promotion.rb +5 -0
  25. data/db/migrate/20230325132905_remove_unused_columns_from_promotion_rules.rb +6 -0
  26. data/db/migrate/20230325161633_drop_unused_promo_action_line_items.rb +13 -0
  27. data/db/migrate/20230425103509_remove_taxon_position.rb +5 -0
  28. data/db/migrate/20230427095534_drop_deprecated_address_id_from_shipments.rb +11 -0
  29. data/lib/generators/solidus/install/app_templates/frontend/none.rb +1 -2
  30. data/lib/generators/solidus/install/app_templates/frontend/starter.rb +1 -3
  31. data/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +2 -14
  32. data/lib/generators/solidus/install/app_templates/payment_method/stripe.rb +5 -0
  33. data/lib/generators/solidus/install/install_generator.rb +58 -152
  34. data/lib/spree/app_configuration.rb +2 -82
  35. data/lib/spree/bus.rb +0 -11
  36. data/lib/spree/core/controller_helpers/auth.rb +0 -16
  37. data/lib/spree/core/engine.rb +11 -31
  38. data/lib/spree/core/validators/email.rb +0 -4
  39. data/lib/spree/core/version.rb +2 -2
  40. data/lib/spree/core.rb +0 -2
  41. data/lib/spree/preferences/preferable_class_methods.rb +1 -25
  42. data/lib/spree/testing_support/common_rake.rb +5 -1
  43. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +4 -8
  44. data/lib/spree/testing_support/dummy_app.rb +1 -6
  45. data/lib/spree/testing_support/factories/address_factory.rb +0 -7
  46. data/lib/spree/testing_support/factories/adjustment_factory.rb +0 -11
  47. data/lib/spree/testing_support/factories/adjustment_reason_factory.rb +0 -5
  48. data/lib/spree/testing_support/factories/calculator_factory.rb +0 -5
  49. data/lib/spree/testing_support/factories/carton_factory.rb +0 -8
  50. data/lib/spree/testing_support/factories/country_factory.rb +0 -5
  51. data/lib/spree/testing_support/factories/credit_card_factory.rb +0 -5
  52. data/lib/spree/testing_support/factories/customer_return_factory.rb +0 -9
  53. data/lib/spree/testing_support/factories/image_factory.rb +0 -5
  54. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +0 -10
  55. data/lib/spree/testing_support/factories/line_item_factory.rb +0 -8
  56. data/lib/spree/testing_support/factories/option_type_factory.rb +0 -8
  57. data/lib/spree/testing_support/factories/option_value_factory.rb +0 -5
  58. data/lib/spree/testing_support/factories/order_factory.rb +0 -12
  59. data/lib/spree/testing_support/factories/order_promotion_factory.rb +0 -8
  60. data/lib/spree/testing_support/factories/payment_factory.rb +0 -10
  61. data/lib/spree/testing_support/factories/payment_method_factory.rb +0 -5
  62. data/lib/spree/testing_support/factories/price_factory.rb +0 -7
  63. data/lib/spree/testing_support/factories/product_factory.rb +0 -11
  64. data/lib/spree/testing_support/factories/product_option_type_factory.rb +0 -8
  65. data/lib/spree/testing_support/factories/product_property_factory.rb +0 -8
  66. data/lib/spree/testing_support/factories/promotion_category_factory.rb +0 -5
  67. data/lib/spree/testing_support/factories/promotion_code_factory.rb +0 -8
  68. data/lib/spree/testing_support/factories/promotion_factory.rb +0 -8
  69. data/lib/spree/testing_support/factories/property_factory.rb +0 -5
  70. data/lib/spree/testing_support/factories/refund_factory.rb +0 -8
  71. data/lib/spree/testing_support/factories/refund_reason_factory.rb +0 -5
  72. data/lib/spree/testing_support/factories/reimbursement_factory.rb +0 -7
  73. data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +0 -5
  74. data/lib/spree/testing_support/factories/return_authorization_factory.rb +0 -9
  75. data/lib/spree/testing_support/factories/return_item_factory.rb +0 -9
  76. data/lib/spree/testing_support/factories/return_reason_factory.rb +0 -5
  77. data/lib/spree/testing_support/factories/role_factory.rb +0 -5
  78. data/lib/spree/testing_support/factories/shipment_factory.rb +0 -10
  79. data/lib/spree/testing_support/factories/shipping_category_factory.rb +0 -5
  80. data/lib/spree/testing_support/factories/shipping_method_factory.rb +0 -9
  81. data/lib/spree/testing_support/factories/shipping_rate_factory.rb +0 -8
  82. data/lib/spree/testing_support/factories/state_factory.rb +0 -8
  83. data/lib/spree/testing_support/factories/stock_item_factory.rb +0 -8
  84. data/lib/spree/testing_support/factories/stock_location_factory.rb +0 -9
  85. data/lib/spree/testing_support/factories/stock_movement_factory.rb +0 -7
  86. data/lib/spree/testing_support/factories/stock_package_factory.rb +0 -8
  87. data/lib/spree/testing_support/factories/store_credit_category_factory.rb +0 -5
  88. data/lib/spree/testing_support/factories/store_credit_event_factory.rb +0 -8
  89. data/lib/spree/testing_support/factories/store_credit_factory.rb +0 -9
  90. data/lib/spree/testing_support/factories/store_credit_reason_factory.rb +0 -5
  91. data/lib/spree/testing_support/factories/store_credit_type_factory.rb +0 -5
  92. data/lib/spree/testing_support/factories/store_factory.rb +0 -5
  93. data/lib/spree/testing_support/factories/tax_category_factory.rb +0 -8
  94. data/lib/spree/testing_support/factories/tax_rate_factory.rb +0 -9
  95. data/lib/spree/testing_support/factories/taxon_factory.rb +0 -7
  96. data/lib/spree/testing_support/factories/taxonomy_factory.rb +0 -5
  97. data/lib/spree/testing_support/factories/user_factory.rb +0 -9
  98. data/lib/spree/testing_support/factories/variant_factory.rb +0 -10
  99. data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +0 -8
  100. data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +0 -9
  101. data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +0 -8
  102. data/lib/spree/testing_support/factories/zone_factory.rb +0 -8
  103. data/lib/spree/testing_support/factory_bot.rb +4 -28
  104. data/lib/spree/testing_support/sequences.rb +0 -5
  105. data/solidus_core.gemspec +2 -2
  106. metadata +43 -51
  107. data/app/subscribers/spree/mailer_subscriber.rb +0 -29
  108. data/lib/generators/solidus/install/app_templates/frontend/break_down_solidus_gem.rb +0 -54
  109. data/lib/generators/solidus/install/app_templates/frontend/classic.rb +0 -16
  110. data/lib/generators/solidus/install/app_templates/payment_method/bolt.rb +0 -13
  111. data/lib/spree/core/controller_helpers/current_host.rb +0 -19
  112. data/lib/spree/event/adapters/active_support_notifications.rb +0 -67
  113. data/lib/spree/event/configuration.rb +0 -25
  114. data/lib/spree/event/subscriber.rb +0 -86
  115. data/lib/spree/event/subscriber_registry.rb +0 -92
  116. data/lib/spree/event.rb +0 -119
  117. data/lib/spree/promotion/match_policies.rb +0 -2
  118. data/lib/spree/rails_compatibility.rb +0 -106
  119. data/lib/spree/testing_support/factories.rb +0 -11
  120. data/lib/spree/testing_support.rb +0 -36
  121. data/lib/tasks/solidus/check_orders_with_invalid_email.rake +0 -18
  122. data/lib/tasks/solidus/split_promotions_with_any_match_policy.rake +0 -33
@@ -1,54 +0,0 @@
1
- # # This will unpack the solidus gem into its components without calling `bundle install`.
2
- #
3
- # # Nothing to do if the `solidus` gem is not there.
4
- solidus = Bundler.locked_gems.dependencies['solidus'] or return
5
-
6
- # Write and remove into and from a Gemfile
7
- #
8
- # This custom injector fixes support for path, git and custom sources,
9
- # which is missing in bundler's upstream injector for a dependency fetched
10
- # with `Bundler.locked_gems.dependencies`.
11
- bundler_injector = Class.new(Bundler::Injector) do
12
- def build_gem_lines(conservative_versioning)
13
- @deps.map do |d|
14
- name = d.name.dump
15
- is_local = d.source.instance_of?(Bundler::Source::Path)
16
- is_git = d.source.instance_of?(Bundler::Source::Git)
17
-
18
- requirement = if is_local
19
- ", path: \"#{d.source.path}\""
20
- elsif is_git
21
- ", git: \"#{d.git}\"".then { |g| d.ref ? g + ", ref: \"#{d.ref}\"" : g }
22
- elsif conservative_versioning
23
- ", \"#{conservative_version(@definition.specs[d.name][0])}\""
24
- else
25
- ", #{d.requirement.as_list.map(&:dump).join(", ")}"
26
- end
27
-
28
- source = ", source: \"#{d.source.remotes.join(",")}\"" unless is_local || is_git || d.source.nil?
29
-
30
- %(gem #{name}#{requirement}#{source})
31
- end.join("\n")
32
- end
33
- end
34
-
35
- to_dependency = ->(component) do
36
- Bundler::Dependency.new(
37
- component,
38
- solidus.requirement,
39
- "source" => solidus.source,
40
- "git" => solidus.source.try(:uri),
41
- "ref" => solidus.source.try(:ref),
42
- )
43
- end
44
-
45
- bundler_injector.inject(%w[
46
- solidus_core
47
- solidus_backend
48
- solidus_api
49
- solidus_sample
50
- ].map(&to_dependency))
51
-
52
- bundler_injector.remove(%w[
53
- solidus
54
- ])
@@ -1,16 +0,0 @@
1
- solidus = Bundler.locked_gems.dependencies['solidus']
2
-
3
- if Bundler.locked_gems.dependencies['solidus_frontend']
4
- say_status :skipping, "solidus_frontend is already in the bundle", :blue
5
- else
6
- # `solidus_frontend` is not sourced from rubygems if the solidus gem was not.
7
- github_solidus_frontend = '--github solidusio/solidus_frontend' unless solidus.nil? || solidus.source.is_a?(Bundler::Source::Rubygems)
8
-
9
- bundle_command("add solidus_frontend #{github_solidus_frontend}")
10
- end
11
-
12
- # Disable solidus_bolt installation from solidus_frontend as it can be
13
- # explicitly selected directly from the solidus installer.
14
- with_env('SKIP_SOLIDUS_BOLT' => 'true') do
15
- generate 'solidus_frontend:install'
16
- end
@@ -1,13 +0,0 @@
1
- unless Bundler.locked_gems.dependencies['solidus_frontend']
2
- say_status :warning, "Support for frontends other than `solidus_frontend` by `solidus_bolt` is still in progress.", :yellow
3
- end
4
-
5
- unless Bundler.locked_gems.dependencies['solidus_auth_devise']
6
- say_status :warning, "Running solidus_bolt without solidus_auth_devise is not supported.", :yellow
7
- end
8
-
9
- unless Bundler.locked_gems.dependencies['solidus_bolt']
10
- bundle_command 'add solidus_bolt'
11
- end
12
-
13
- generate "solidus_bolt:install --auto-run-migrations=#{options[:migrate]}"
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Spree
4
- module Core
5
- module ControllerHelpers
6
- module CurrentHost
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- Spree::Deprecation.warn <<~MSG
11
- 'Spree::Core::ControllerHelpers::CurrentHost' is deprecated.
12
- Please, include 'ActiveStorage::SetCurrent' instead.
13
- MSG
14
- include ActiveStorage::SetCurrent
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Spree
4
- module Event
5
- module Adapters
6
- module ActiveSupportNotifications
7
- class InvalidEventNameType < StandardError; end
8
-
9
- extend self
10
-
11
- def fire(event_name, opts)
12
- ActiveSupport::Notifications.instrument event_name, opts do
13
- yield opts if block_given?
14
- end
15
- end
16
-
17
- def subscribe(event_name)
18
- ActiveSupport::Notifications.subscribe event_name do |*args|
19
- event = ActiveSupport::Notifications::Event.new(*args)
20
- yield event
21
- end
22
- end
23
-
24
- def unsubscribe(subscriber_or_name)
25
- ActiveSupport::Notifications.unsubscribe(subscriber_or_name)
26
- end
27
-
28
- def listeners_for(names)
29
- names.each_with_object({}) do |name, memo|
30
- listeners = ActiveSupport::Notifications.notifier.listeners_for(name)
31
- memo[name] = listeners if listeners.present?
32
- end
33
- end
34
-
35
- # Normalizes the event name according to this specific adapter rules.
36
- # When the event name is a string or a symbol, if the suffix is missing, then
37
- # it is added automatically.
38
- # When the event name is a regexp, due to the huge variability of regexps, adding
39
- # or not the suffix is developer's responsibility (if you don't, you will subscribe
40
- # to all internal rails events as well).
41
- # When the event type is not supported, an error is raised.
42
- #
43
- # @param [String, Symbol, Regexp] event_name the event name, with or without the
44
- # suffix (Spree::Config.events.suffix defaults to `.spree`).
45
- def normalize_name(event_name)
46
- case event_name
47
- when Regexp
48
- event_name
49
- when String, Symbol
50
- name = event_name.to_s
51
- name.end_with?(suffix) ? name : [name, suffix].join
52
- else
53
- raise InvalidEventNameType, "Invalid event name type: #{event_name.class}"
54
- end
55
- end
56
-
57
- # The suffix used for namespacing event names, defaults to
58
- # `.spree`
59
- #
60
- # @see Spree::Event::Configuration#suffix
61
- def suffix
62
- Spree::Config.events.suffix
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Spree
4
- module Event
5
- class Configuration
6
- def subscriber_registry
7
- @subscriber_registry ||= Spree::Event::SubscriberRegistry.new
8
- end
9
-
10
- attr_writer :adapter, :suffix, :autoload_subscribers
11
-
12
- def autoload_subscribers
13
- @autoload_subscribers.nil? ? true : !!@autoload_subscribers
14
- end
15
-
16
- def adapter
17
- @adapter ||= Spree::Event::Adapters::ActiveSupportNotifications
18
- end
19
-
20
- def suffix
21
- @suffix ||= '.spree'
22
- end
23
- end
24
- end
25
- end
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Spree
4
- module Event
5
- # This module simplifies adding and removing subscriptions to {Spree::Event} events.
6
- # Here's a complete example:
7
- # module EmailSender
8
- # include Spree::Event::Subscriber
9
- #
10
- # event_action :order_finalized
11
- # event_action :confirm_reimbursement, event_name: :reimbursement_reimbursed
12
- #
13
- # def order_finalized(event)
14
- # Mailer.send_email(event.payload[:order])
15
- # end
16
- #
17
- # def confirm_reimbursement(event)
18
- # Mailer.send_email(event.payload[:reimbursement])
19
- # end
20
- # end
21
- #
22
- # # Optional, required only when the subscriber needs to be loaded manually.
23
- # #
24
- # # If Spree::Config.events.autoload_subscribers is set to `true` and the module
25
- # # file matches the pattern `app/subscribers/**/*_subscriber.rb` then it will
26
- # # be loaded automatically at boot and this line can be removed:
27
- # EmailSender.activate
28
- module Subscriber
29
- def self.included(base)
30
- base.extend base
31
-
32
- base.mattr_accessor :event_actions
33
- base.event_actions = {}
34
-
35
- Spree::Event.subscriber_registry.register(base)
36
- end
37
-
38
- # Declares a method name in the including module that can be subscribed/unsubscribed
39
- # to an event.
40
- #
41
- # @param method_name [String, Symbol] the method that will be called when the subscribed event is fired
42
- # @param event_name [String, Symbol] the name of the event to be subscribed
43
- #
44
- # @example Declares 'send_email' as an event action that can subscribe the event 'order_finalized'
45
- # module EmailSender
46
- # event_action :send_email, event_name: :order_finalized
47
- #
48
- # def send_email(event)
49
- # Mailer.send_email(event.payload[:order])
50
- # end
51
- # end
52
- #
53
- # @example Same as above, but the method name is same as the event name:
54
- # module EmailSender
55
- # event_action :order_completed
56
- #
57
- # def order_completed(event)
58
- # Mailer.send_email(event.payload[:order])
59
- # end
60
- # end
61
- def event_action(method_name, event_name: nil)
62
- event_actions[method_name] = (event_name || method_name).to_s
63
- end
64
-
65
- # Activates all declared event actions to their events. Only actions that are activated
66
- # will be called when their event fires.
67
- #
68
- # @example activate all event actions for module 'EmailSender'
69
- # EmailSender.activate
70
- def activate
71
- Spree::Event.subscriber_registry.activate_subscriber(self)
72
- end
73
-
74
- # Deactivates all declared event actions (or a single specific one) from their events.
75
- # This means that when an event fires then none of its unsubscribed event actions will
76
- # be called.
77
- # @example deactivate all event actions for module 'EmailSender'
78
- # EmailSender.deactivate
79
- # @example deactivate only order_finalized for module 'EmailSender'
80
- # EmailSender.deactivate(:order_finalized)
81
- def deactivate(event_action_name = nil)
82
- Spree::Event.subscriber_registry.deactivate_subscriber(self, event_action_name)
83
- end
84
- end
85
- end
86
- end
@@ -1,92 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Spree
4
- module Event
5
- class SubscriberRegistry
6
- def initialize
7
- @registry = {}
8
- @semaphore = Mutex.new
9
- end
10
-
11
- def register(subscriber)
12
- registry[subscriber.name] ||= {}
13
- end
14
-
15
- def activate_autoloadable_subscribers
16
- require_subscriber_files
17
- activate_all_subscribers
18
- end
19
-
20
- def activate_all_subscribers
21
- registry.each_key { |subscriber_name| activate_subscriber(subscriber_name.constantize) }
22
- end
23
-
24
- def deactivate_all_subscribers
25
- registry.each_key { |subscriber_name| deactivate_subscriber(subscriber_name.constantize) }
26
- end
27
-
28
- def activate_subscriber(subscriber)
29
- return unless registry[subscriber.name]
30
-
31
- subscriber.event_actions.each do |event_action, event_name|
32
- @semaphore.synchronize do
33
- unsafe_deactivate_subscriber(subscriber, event_action)
34
-
35
- subscription = Spree::Event.subscribe(event_name) { |event| subscriber.send(event_action, event) }
36
-
37
- # deprecated mappings, to be removed when Solidus 2.10 is not supported anymore:
38
- if subscriber.respond_to?("#{event_action}_handler=")
39
- subscriber.send("#{event_action}_handler=", subscription)
40
- end
41
-
42
- registry[subscriber.name][event_action] = subscription
43
- end
44
- end
45
- end
46
-
47
- def deactivate_subscriber(subscriber, event_action_name = nil)
48
- @semaphore.synchronize do
49
- unsafe_deactivate_subscriber(subscriber, event_action_name)
50
- end
51
- end
52
-
53
- private
54
-
55
- attr_reader :registry
56
-
57
- # Loads all Solidus' core and application's event subscribers files.
58
- # The latter are loaded automatically only when the preference
59
- # Spree::Config.events.autoload_subscribers is set to a truthy value.
60
- #
61
- # Files must be placed under the directory `app/subscribers` and their
62
- # name must end with `_subscriber.rb`.
63
- #
64
- # Loading the files has the side effect of adding their module to the
65
- # list in Spree::Event.subscribers.
66
- def require_subscriber_files
67
- require_dependency(
68
- Spree::Core::Engine.root.join('app', 'subscribers', 'spree', 'mailer_subscriber.rb')
69
- )
70
-
71
- pattern = "app/subscribers/**/*_subscriber.rb"
72
-
73
- # Load application subscribers, only when the flag is set to true:
74
- if Spree::Config.events.autoload_subscribers
75
- Rails.root.glob(pattern) { |c| require_dependency(c.to_s) }
76
- end
77
- end
78
-
79
- def unsafe_deactivate_subscriber(subscriber, event_action_name = nil)
80
- to_unsubscribe = Array.wrap(event_action_name || subscriber.event_actions.keys)
81
-
82
- to_unsubscribe.each do |event_action|
83
- if (subscription = registry.dig(subscriber.name, event_action))
84
- Spree::Event.unsubscribe(subscription)
85
-
86
- registry[subscriber.name].delete(event_action)
87
- end
88
- end
89
- end
90
- end
91
- end
92
- end
data/lib/spree/event.rb DELETED
@@ -1,119 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'event/adapters/active_support_notifications'
4
- require_relative 'event/subscriber_registry'
5
- require_relative 'event/configuration'
6
- require_relative 'event/subscriber'
7
-
8
- module Spree
9
- module Event
10
- extend self
11
-
12
- delegate :activate_autoloadable_subscribers, :activate_all_subscribers, :deactivate_all_subscribers, to: :subscriber_registry
13
-
14
- # Allows to trigger events that can be subscribed using #subscribe. An
15
- # optional block can be passed that will be executed immediately. The
16
- # actual code implementation is delegated to the adapter.
17
- #
18
- # @param [String] event_name the name of the event. The suffix ".spree"
19
- # will be added automatically if not present
20
- # @param [Hash] opts a list of options to be passed to the triggered event
21
- #
22
- # @example Trigger an event named 'order_finalized'
23
- # Spree::Event.fire 'order_finalized', order: @order do
24
- # @order.complete!
25
- # end
26
- def fire(event_name, opts = {})
27
- adapter.fire normalize_name(event_name), opts do
28
- yield opts if block_given?
29
- end
30
- end
31
-
32
- # Subscribe to an event with the given name. The provided block is executed
33
- # every time the subscribed event is fired.
34
- #
35
- # @param [String, Regexp] event_name the name of the event.
36
- # When String, the suffix ".spree" will be added automatically if not present,
37
- # when using the default adapter for ActiveSupportNotifications.
38
- # When Regexp, due to the unpredictability of all possible regexp combinations,
39
- # adding the suffix is developer's responsibility (if you don't, you will
40
- # subscribe to all notifications, including internal Rails notifications
41
- # as well).
42
- #
43
- # @see Spree::Event::Adapters::ActiveSupportNotifications#normalize_name
44
- #
45
- # @return a subscription object that can be used as reference in order
46
- # to remove the subscription
47
- #
48
- # @example Subscribe to the `order_finalized` event
49
- # Spree::Event.subscribe 'order_finalized' do |event|
50
- # order = event.payload[:order]
51
- # Spree::Mailer.order_finalized(order).deliver_later
52
- # end
53
- #
54
- # @see Spree::Event#unsubscribe
55
- def subscribe(event_name, &block)
56
- name = normalize_name(event_name)
57
- listener_names << name
58
- adapter.subscribe(name, &block)
59
- end
60
-
61
- # Unsubscribes a whole event or a specific subscription object
62
- #
63
- # @param [String, Object] subscriber the event name as a string (with
64
- # or without the ".spree" suffix) or the subscription object
65
- #
66
- # @example Unsubscribe a single subscription
67
- # subscription = Spree::Event.fire 'order_finalized'
68
- # Spree::Event.unsubscribe(subscription)
69
- # @example Unsubscribe all `order_finalized` event subscriptions
70
- # Spree::Event.unsubscribe('order_finalized')
71
- # @example Unsubscribe an event by name with explicit prefix
72
- # Spree::Event.unsubscribe('order_finalized.spree')
73
- def unsubscribe(subscriber)
74
- name_or_subscriber = subscriber.is_a?(String) ? normalize_name(subscriber) : subscriber
75
- adapter.unsubscribe(name_or_subscriber)
76
- end
77
-
78
- # Lists all subscriptions currently registered under the ".spree"
79
- # namespace. Actual implementation is delegated to the adapter
80
- #
81
- # @return [Hash] an hash with event names as keys and arrays of subscriptions
82
- # as values
83
- #
84
- # @example Current subscriptions
85
- # Spree::Event.listeners
86
- # # => {"order_finalized.spree"=> [#<ActiveSupport...>],
87
- # "reimbursement_reimbursed.spree"=> [#<ActiveSupport...>]}
88
- def listeners
89
- adapter.listeners_for(listener_names)
90
- end
91
-
92
- # The adapter used by Spree::Event, defaults to
93
- # Spree::Event::Adapters::ActiveSupportNotifications
94
- #
95
- # @example Change the adapter
96
- # Spree::Config.events.adapter = "Spree::EventBus.new"
97
- #
98
- # @see Spree::AppConfiguration
99
- def adapter
100
- Spree::Config.events.adapter
101
- end
102
-
103
- # @!attribute [r] subscribers
104
- # @return <Spree::Event::SubscriberRegistry> The registry for supporting class reloading for Spree::Event::Subscriber instances
105
- def subscriber_registry
106
- Spree::Config.events.subscriber_registry
107
- end
108
-
109
- private
110
-
111
- def normalize_name(name)
112
- adapter.normalize_name(name)
113
- end
114
-
115
- def listener_names
116
- @listeners_names ||= Set.new
117
- end
118
- end
119
- end
@@ -1,2 +0,0 @@
1
- Spree::Promotion::MATCH_POLICIES = %w(all any)
2
- Spree::Deprecation.warn('Spree::Promotion::MATCH_POLICIES is deprecated')
@@ -1,106 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/gem_version'
4
-
5
- module Spree
6
- # Supported Rails versions compatibility
7
- #
8
- # This module is meant to wrap some Rails API changes between supported
9
- # versions. It's also meant to contain compatibility for features that we use
10
- # internally in the Solidus code base.
11
- module RailsCompatibility
12
- # Method `#to_fs`
13
- #
14
- # Available since Rails 7.0, substitutes `#to_s(format)`
15
- #
16
- # It includes:
17
- #
18
- # ActiveSupport::NumericWithFormat
19
- # ActiveSupport::RangeWithFormat
20
- # ActiveSupport::TimeWithZone
21
- # Array
22
- # Date
23
- # DateTime
24
- # Time
25
- #
26
- # See https://github.com/rails/rails/pull/43772 &
27
- # https://github.com/rails/rails/pull/44354
28
- #
29
- # TODO: Remove when deprecating Rails 6.1
30
- def self.to_fs(value, *args, **kwargs, &block)
31
- if version_gte?('7.0')
32
- value.to_fs(*args, **kwargs, &block)
33
- else
34
- value.to_s(*args, **kwargs, &block)
35
- end
36
- end
37
-
38
- # `raise_on_missing_translations` config option
39
- #
40
- # Changed from ActionView to I18n on Rails 6.1
41
- #
42
- # See https://github.com/rails/rails/pull/31571
43
- #
44
- # TODO: Remove when deprecating Rails 6.0
45
- def self.raise_on_missing_translations(value)
46
- if version_gte?('6.1')
47
- Rails.application.config.i18n.raise_on_missing_translations = value
48
- else
49
- Rails.application.config.action_view.raise_on_missing_translations = value
50
- end
51
- end
52
-
53
- # Set default image attachment adapter
54
- #
55
- # TODO: Remove when deprecating Rails 6.0
56
- def self.default_image_attachment_module
57
- if version_gte?("6.1")
58
- "Spree::Image::ActiveStorageAttachment"
59
- else
60
- "Spree::Image::PaperclipAttachment"
61
- end
62
- end
63
-
64
- # Set default taxon attachment adapter
65
- #
66
- # TODO: Remove when deprecating Rails 6.0
67
- def self.default_taxon_attachment_module
68
- if version_gte?("6.1")
69
- "Spree::Taxon::ActiveStorageAttachment"
70
- else
71
- "Spree::Taxon::PaperclipAttachment"
72
- end
73
- end
74
-
75
- # Set current host for ActiveStorage
76
- #
77
- # Changed from `#host` to `#url_options` on Rails 7
78
- #
79
- # See https://github.com/rails/rails/issues/41388
80
- #
81
- # TODO: Remove when deprecating Rails 6.1
82
- def self.active_storage_url_options_host(value)
83
- if version_gte?('7')
84
- ActiveStorage::Current.url_options = { host: value }
85
- else
86
- ActiveStorage::Current.host = value
87
- end
88
- end
89
-
90
- # Default ActiveStorage variant processor
91
- #
92
- # Changed from `:mini_magick` to `vips` on Rails 7
93
- #
94
- # See https://github.com/rails/rails/issues/42744
95
- #
96
- # TODO: Remove when deprecating Rails 6.1
97
- def self.variant_processor
98
- version_gte?('7') ? :vips : :mini_magick
99
- end
100
-
101
- def self.version_gte?(version)
102
- ::Rails.gem_version >= Gem::Version.new(version)
103
- end
104
- private_class_method :version_gte?
105
- end
106
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spree/testing_support/factory_bot'
4
-
5
- Spree::Deprecation.warn(
6
- "Please do not try to load factories directly. " \
7
- 'Use factory_bot_rails and rely on the default configuration instead.', caller(1)
8
- )
9
-
10
- Spree::TestingSupport::FactoryBot.check_version
11
- Spree::TestingSupport::FactoryBot::PATHS.each { |path| require path }
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spree/testing_support/factory_bot'
4
- require 'spree/deprecation'
5
-
6
- Spree::Deprecation.warn <<-WARN
7
- Using `require 'spree/testing_support'` is deprecated and will be removed in
8
- Solidus 4.0.
9
- WARN
10
-
11
- module Spree
12
- module TestingSupport
13
- autoload :FactoryBot, "spree/testing_support/factory_bot"
14
- autoload :SEQUENCES, "spree/testing_support/factory_bot"
15
- autoload :FACTORIES, "spree/testing_support/factory_bot"
16
-
17
- def factory_bot_paths
18
- Spree::TestingSupport::FactoryBot.definition_file_paths
19
- end
20
-
21
- def check_factory_bot_version
22
- Spree::TestingSupport::FactoryBot.check_version
23
- end
24
-
25
- def load_all_factories
26
- Spree::TestingSupport::FactoryBot.add_paths_and_load!
27
- end
28
-
29
- deprecate(
30
- factory_bot_paths: "Spree::TestingSupport::FactoryBot.definition_file_paths",
31
- check_factory_bot_version: "Spree::TestingSupport::FactoryBot.check_version",
32
- load_all_factories: "Spree::TestingSupport::FactoryBot.add_paths_and_load!",
33
- deprecator: Spree::Deprecation
34
- )
35
- end
36
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- namespace :solidus do
4
- desc 'Prints orders with invalid email (after fix for GHSA-qxmr-qxh6-2cc9)'
5
- task check_orders_with_invalid_email: :environment do
6
- matches = Spree::Order.find_each.reduce([]) do |matches, order|
7
- order.email.nil? || Spree::EmailValidator::EMAIL_REGEXP.match?(order.email) ? matches : matches + [order]
8
- end
9
- if matches.any?
10
- puts 'Email / ID / Number'
11
- puts(matches.map do |order|
12
- "#{order.email} / #{order.id} / #{order.number}"
13
- end.join("\n"))
14
- else
15
- puts 'NO MATCHES'
16
- end
17
- end
18
- end