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.

Raneme event names to past tense to unify with webhooks

Damian Legawiecb49af0b53d91
diff --git a/admin/app/subscribers/spree/admin/import_row_subscriber.rb b/admin/app/subscribers/spree/admin/import_row_subscriber.rb
index 541517af23..7ca11e6989 100644
--- a/admin/app/subscribers/spree/admin/import_row_subscriber.rb
+++ b/admin/app/subscribers/spree/admin/import_row_subscriber.rb
@@ -4,7 +4,7 @@ module Spree
module Admin
# Handles ImportRow events for the admin interface.
#
- # This subscriber listens to import_row.complete and import_row.fail events
+ # This subscriber listens to import_row.completed and import_row.failed events
# and handles:
# - Adding the row to the import view (Turbo Streams)
# - Updating the footer in the import view (Turbo Streams)
@@ -12,10 +12,10 @@ module Spree
# We use async: false because the UI updates should happen immediately.
#
class ImportRowSubscriber < Spree::Subscriber
- subscribes_to 'import_row.complete', 'import_row.fail', async: false
+ subscribes_to 'import_row.completed', 'import_row.failed', async: false
- on 'import_row.complete', :update_import_view
- on 'import_row.fail', :update_import_view
+ on 'import_row.completed', :update_import_view
+ on 'import_row.failed', :update_import_view
def update_import_view(event)
import_row_id = event.payload['id']
diff --git a/admin/app/subscribers/spree/admin/import_subscriber.rb b/admin/app/subscribers/spree/admin/import_subscriber.rb
index 1eea6c69f7..25f5b71351 100644
--- a/admin/app/subscribers/spree/admin/import_subscriber.rb
+++ b/admin/app/subscribers/spree/admin/import_subscriber.rb
@@ -4,16 +4,16 @@ module Spree
module Admin
# Handles Import events for the admin interface.
#
- # This subscriber listens to import.complete event and handles:
+ # This subscriber listens to import.completed event and handles:
# - Updating the loader in the import view (Turbo Streams)
#
# We use async: false because the UI update should happen immediately
# after the import completes.
#
class ImportSubscriber < Spree::Subscriber
- subscribes_to 'import.complete', async: false
+ subscribes_to 'import.completed', async: false
- on 'import.complete', :update_loader_in_import_view
+ on 'import.completed', :update_loader_in_import_view
def update_loader_in_import_view(event)
import_id = event.payload['id']
diff --git a/api/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rb b/api/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rb
index 92c9594b6d..a8753ea397 100644
--- a/api/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rb
+++ b/api/spec/serializers/spree/api/v2/platform/taxon_serializer_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'
describe Spree::Api::V2::Platform::TaxonSerializer do
- include_context 'API v2 serializers params'
-
subject { described_class.new(taxon.reload, params: serializer_params).serializable_hash }
+ include_context 'API v2 serializers params'
+
let(:taxonomy) { create(:taxonomy, store: store) }
let(:taxon) { create(:taxon, :with_description, taxonomy: taxonomy, products: create_list(:product, 2, stores: [store])) }
let!(:children) { create_list(:taxon, 2, taxonomy: taxonomy, parent: taxon) }
@@ -56,10 +56,7 @@ describe Spree::Api::V2::Platform::TaxonSerializer do
}
},
image: {
- data: {
- id: taxon.icon.id.to_s,
- type: :taxon_image
- }
+ data: nil
},
children: {
data: [
@@ -133,10 +130,7 @@ describe Spree::Api::V2::Platform::TaxonSerializer do
}
},
image: {
- data: {
- id: taxon.icon.id.to_s,
- type: :taxon_image
- }
+ data: nil
},
products: {
data: [
diff --git a/api/spec/serializers/spree/v2/storefront/taxon_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/taxon_serializer_spec.rb
index 7babfda614..254ff4c4ed 100644
--- a/api/spec/serializers/spree/v2/storefront/taxon_serializer_spec.rb
+++ b/api/spec/serializers/spree/v2/storefront/taxon_serializer_spec.rb
@@ -72,10 +72,7 @@ describe Spree::V2::Storefront::TaxonSerializer do
]
},
image: {
- data: {
- id: taxon.icon.id.to_s,
- type: :taxon_image
- }
+ data: nil
},
metafields: {
data: [
diff --git a/core/app/models/concerns/spree/publishable.rb b/core/app/models/concerns/spree/publishable.rb
index 4dbf1d8cff..ef33f23a32 100644
--- a/core/app/models/concerns/spree/publishable.rb
+++ b/core/app/models/concerns/spree/publishable.rb
@@ -16,7 +16,7 @@ module Spree
# class Spree::Order < Spree.base_class
# def complete!
# # ... completion logic ...
- # publish_event('order.complete')
+ # publish_event('order.completed')
# end
# end
#
@@ -149,9 +149,9 @@ module Spree
# @return [Spree::Event] The published event
#
# @example
- # order.publish_event('order.complete')
- # order.publish_event('order.complete', { custom: 'data' })
- # order.publish_event('order.complete', metadata: { user_id: 1 })
+ # order.publish_event('order.completed')
+ # order.publish_event('order.completed', { custom: 'data' })
+ # order.publish_event('order.completed', metadata: { user_id: 1 })
#
def publish_event(event_name, payload = nil, metadata = {})
return unless Spree::Events.enabled?
@@ -235,18 +235,18 @@ module Spree
end
def publish_create_event
- publish_event("#{event_prefix}.create")
+ publish_event("#{event_prefix}.created")
end
def publish_update_event
- publish_event("#{event_prefix}.update")
+ publish_event("#{event_prefix}.updated")
end
def publish_destroy_event
# For destroy, we need to capture the data before it's gone
# The after_commit runs after the record is deleted, so we use
# the previously captured payload
- publish_event("#{event_prefix}.destroy", @_pre_destroy_payload || event_payload)
+ publish_event("#{event_prefix}.destroyed", @_pre_destroy_payload || event_payload)
end
def capture_pre_destroy_payload
diff --git a/core/app/models/spree/events.rb b/core/app/models/spree/events.rb
index 52c17908ed..13d27d046b 100644
--- a/core/app/models/spree/events.rb
+++ b/core/app/models/spree/events.rb
@@ -8,13 +8,13 @@ module Spree
# allowing for future changes without affecting subscriber code.
#
# @example Publishing an event
- # Spree::Events.publish('order.complete', order.serializable_hash)
+ # Spree::Events.publish('order.completed', order.serializable_hash)
#
# @example Subscribing with a class
- # Spree::Events.subscribe('order.complete', OrderCompleteHandler)
+ # Spree::Events.subscribe('order.completed', OrderCompletedHandler)
#
# @example Subscribing with a block
- # Spree::Events.subscribe('order.complete') do |event|
+ # Spree::Events.subscribe('order.completed') do |event|
# puts "Order completed: #{event.payload['number']}"
# end
#
@@ -32,8 +32,8 @@ module Spree
# @return [Spree::Event] The published event
#
# @example
- # Spree::Events.publish('product.create', product.serializable_hash)
- # Spree::Events.publish('order.complete', order.serializable_hash, { user_id: current_user.id })
+ # Spree::Events.publish('product.created', product.serializable_hash)
+ # Spree::Events.publish('order.completed', order.serializable_hash, { user_id: current_user.id })
#
def publish(name, payload = {}, metadata = {})
adapter.publish(name, payload, metadata)
@@ -50,16 +50,16 @@ module Spree
# @return [void]
#
# @example With a subscriber class
- # Spree::Events.subscribe('order.complete', SendConfirmationEmail)
+ # Spree::Events.subscribe('order.completed', SendConfirmationEmail)
#
# @example With a block
- # Spree::Events.subscribe('order.complete') { |event| puts event.name }
+ # Spree::Events.subscribe('order.completed') { |event| puts event.name }
#
# @example With pattern matching
# Spree::Events.subscribe('order.*', OrderAuditLogger)
#
# @example Synchronous execution
- # Spree::Events.subscribe('order.complete', MyHandler, async: false)
+ # Spree::Events.subscribe('order.completed', MyHandler, async: false)
#
def subscribe(pattern, subscriber = nil, options = {}, &block)
subscriber = block if block_given?
diff --git a/core/app/models/spree/gift_card.rb b/core/app/models/spree/gift_card.rb
index 9aad59df6a..92f372c45d 100644
--- a/core/app/models/spree/gift_card.rb
+++ b/core/app/models/spree/gift_card.rb
@@ -18,13 +18,13 @@ module Spree
transition partially_redeemed: :redeemed
end
after_transition to: :redeemed, do: :after_redeem
- after_transition to: :redeemed, do: :send_gift_card_redeemed_event
+ after_transition to: :redeemed, do: :publish_gift_card_redeemed_event
event :partial_redeem do
transition active: :partially_redeemed
transition partially_redeemed: :partially_redeemed
end
- after_transition to: :partially_redeemed, do: :send_gift_card_partial_redeemed_event
+ after_transition to: :partially_redeemed, do: :publish_gift_card_partially_redeemed_event
end
#
@@ -158,12 +158,12 @@ module Spree
update!(redeemed_at: Time.current)
end
- def send_gift_card_redeemed_event
- publish_event('gift_card.redeem')
+ def publish_gift_card_redeemed_event
+ publish_event('gift_card.redeemed')
end
- def send_gift_card_partial_redeemed_event
- publish_event('gift_card.partial_redeem')
+ def publish_gift_card_partially_redeemed_event
+ publish_event('gift_card.partially_redeemed')
end
def ensure_can_be_deleted
diff --git a/core/app/models/spree/import.rb b/core/app/models/spree/import.rb
index 1f97475538..5ada787eff 100644
--- a/core/app/models/spree/import.rb
+++ b/core/app/models/spree/import.rb
@@ -60,9 +60,9 @@ module Spree
event :complete do
transition from: :processing, to: :completed
end
- after_transition to: :completed, do: :send_import_completed_event
+ after_transition to: :completed, do: :publish_import_completed_event
# NOTE: send_import_completed_email and update_loader_in_import_view
- # are now handled by Spree::ImportSubscriber listening to 'import.complete' event
+ # are now handled by Spree::Admin::ImportSubscriber listening to 'import.completed' event
event :fail do
transition to: :failed
@@ -164,8 +164,8 @@ module Spree
"#{Spree.t(type.demodulize.pluralize.downcase)} #{number}"
end
- def send_import_completed_event
- publish_event('import.complete')
+ def publish_import_completed_event
+ publish_event('import.completed')
end
# Returns the headers of the csv file
diff --git a/core/app/models/spree/import_row.rb b/core/app/models/spree/import_row.rb
index 4aa78c7072..f06612d470 100644
--- a/core/app/models/spree/import_row.rb
+++ b/core/app/models/spree/import_row.rb
@@ -86,11 +86,11 @@ module Spree
end
def publish_import_row_completed_event
- publish_event('import_row.complete')
+ publish_event('import_row.completed')
end
def publish_import_row_failed_event
- publish_event('import_row.fail')
+ publish_event('import_row.failed')
end
end
end
diff --git a/core/app/models/spree/invitation.rb b/core/app/models/spree/invitation.rb
index 39f3ce0d7f..33b7cc1e31 100644
--- a/core/app/models/spree/invitation.rb
+++ b/core/app/models/spree/invitation.rb
@@ -46,7 +46,7 @@ module Spree
transition pending: :accepted
end
after_transition to: :accepted, do: :after_accept
- after_transition to: :accepted, do: :send_invitation_accepted_event
+ after_transition to: :accepted, do: :publish_invitation_accepted_event
end
#
@@ -54,7 +54,7 @@ module Spree
#
after_initialize :set_defaults, if: :new_record?
before_validation :set_invitee_from_email, on: :create
- after_create :send_invitation_email, unless: :skip_email
+ after_create :publish_invitation_created_event, unless: :skip_email
# returns the store for the invitation
# if the resource is a store, return the resource
@@ -81,7 +81,7 @@ module Spree
def resend!
return if expired? || deleted? || accepted?
- publish_event('invitation.resend')
+ publish_event('invitation.resent')
end
private
@@ -92,12 +92,12 @@ module Spree
set_accepted_at
end
- def send_invitation_accepted_event
- publish_event('invitation.accept')
+ def publish_invitation_accepted_event
+ publish_event('invitation.accepted')
end
- def send_invitation_email
- publish_event('invitation.create')
+ def publish_invitation_created_event
+ publish_event('invitation.created')
end
# This method is kept for backwards compatibility.
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 5bb05f81a6..7c7b2391ad 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -393,7 +393,7 @@ module Spree
end
# Manually publish update event since update_all bypasses callbacks
- publish_event('order.update') if changes.present?
+ publish_event('order.updated') if changes.present?
end
def disassociate_user!
@@ -530,7 +530,7 @@ module Spree
consider_risk
- send_order_completed_event
+ publish_order_completed_event
end
def fulfill!
@@ -698,7 +698,7 @@ module Spree
update_column(:shipment_total, 0)
# Manually publish update event since update_column bypasses callbacks
- publish_event('order.update')
+ publish_event('order.updated')
restart_checkout_flow
end
@@ -711,7 +711,7 @@ module Spree
)
# Manually publish update event since update_columns bypasses callbacks
- publish_event('order.update')
+ publish_event('order.updated')
next! unless line_items.empty?
end
@@ -754,7 +754,7 @@ module Spree
end
# Manually publish update event since update_columns bypasses callbacks
- publish_event('order.update')
+ publish_event('order.canceled')
end
def approved_by(user)
@@ -767,7 +767,7 @@ module Spree
end
# Manually publish update event since update_columns bypasses callbacks
- publish_event('order.update')
+ publish_event('order.approved')
end
def approved?
@@ -795,14 +795,14 @@ module Spree
update_column(:considered_risky, true)
# Manually publish update event since update_column bypasses callbacks
- publish_event('order.update')
+ publish_event('order.updated')
end
def approve!
update_column(:considered_risky, false)
# Manually publish update event since update_column bypasses callbacks
- publish_event('order.update')
+ publish_event('order.approved')
end
def tax_total
@@ -928,7 +928,7 @@ module Spree
errors.add(:base, Spree.t(:items_cannot_be_shipped))
end
- return false
+ false
end
end
@@ -948,14 +948,14 @@ module Spree
send_cancel_email
update_with_updater!
send_order_canceled_webhook
- send_order_canceled_event
+ publish_order_canceled_event
end
def after_resume
shipments.each(&:resume!)
consider_risk
send_order_resumed_webhook
- send_order_resumed_event
+ publish_order_resumed_event
end
def use_billing?
@@ -994,16 +994,16 @@ module Spree
end
end
- def send_order_completed_event
- publish_event('order.complete')
+ def publish_order_completed_event
+ publish_event('order.completed')
end
- def send_order_canceled_event
- publish_event('order.cancel')
+ def publish_order_canceled_event
+ publish_event('order.canceled')
end
- def send_order_resumed_event
- publish_event('order.resume')
+ def publish_order_resumed_event
+ publish_event('order.resumed')
end
end
end
diff --git a/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rb
index b58022513d..f6c0e2e597 100644
--- a/core/app/models/spree/payment.rb
+++ b/core/app/models/spree/payment.rb
@@ -114,11 +114,11 @@ module Spree
event :complete do
transition from: [:processing, :pending, :checkout], to: :completed
end
- after_transition to: :completed, do: [:after_completed, :send_payment_completed_webhook, :send_payment_completed_event]
+ after_transition to: :completed, do: [:after_completed, :send_payment_completed_webhook, :publish_payment_completed_event]
event :void do
transition from: [:pending, :processing, :completed, :checkout], to: :void
end
- after_transition to: :void, do: [:after_void, :send_payment_voided_webhook, :send_payment_voided_event]
+ after_transition to: :void, do: [:after_void, :send_payment_voided_webhook, :publish_payment_voided_event]
# when the card brand isn't supported
event :invalidate do
transition from: [:checkout], to: :invalid
@@ -291,12 +291,12 @@ module Spree
def after_completed
end
- def send_payment_completed_event
- publish_event('payment.complete')
+ def publish_payment_completed_event
+ publish_event('payment.completed')
end
- def send_payment_voided_event
- publish_event('payment.void')
+ def publish_payment_voided_event
+ publish_event('payment.voided')
end
def has_invalid_state?
diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb
index 01bd3bb669..c4c5df100d 100644
--- a/core/app/models/spree/product.rb
+++ b/core/app/models/spree/product.rb
@@ -262,12 +262,12 @@ module Spree
event :activate do
transition to: :active
end
- after_transition to: :active, do: [:after_activate, :send_product_activated_webhook, :send_product_activated_event]
+ after_transition to: :active, do: [:after_activate, :send_product_activated_webhook, :publish_product_activated_event]
event :archive do
transition to: :archived
end
- after_transition to: :archived, do: [:after_archive, :send_product_archived_webhook, :send_product_archived_event]
+ after_transition to: :archived, do: [:after_archive, :send_product_archived_webhook, :publish_product_archived_event]
event :draft do
transition to: :draft
@@ -673,7 +673,8 @@ module Spree
if has_variants?
variants_including_master.each_with_index do |variant, index|
- csv_lines << Spree::CSV::ProductVariantPresenter.new(self, variant, index, properties_for_csv, taxons_for_csv, store, metafields_for_csv).call
+ csv_lines << Spree::CSV::ProductVariantPresenter.new(self, variant, index, properties_for_csv, taxons_for_csv, store,
+ metafields_for_csv).call
end
else
csv_lines << Spree::CSV::ProductVariantPresenter.new(self, master, 0, properties_for_csv, taxons_for_csv, store, metafields_for_csv).call
@@ -849,12 +850,12 @@ module Spree
# Implement your logic here
end
- def send_product_activated_event
- publish_event('product.activate')
+ def publish_product_activated_event
+ publish_event('product.activated')
end
- def send_product_archived_event
- publish_event('product.archive')
+ def publish_product_archived_event
+ publish_event('product.archived')
end
end
end
diff --git a/core/app/models/spree/reimbursement.rb b/core/app/models/spree/reimbursement.rb
index e08ed98e3a..7a73b53f3b 100644
--- a/core/app/models/spree/reimbursement.rb
+++ b/core/app/models/spree/reimbursement.rb
@@ -76,7 +76,7 @@ module Spree
event :reimbursed do
transition to: :reimbursed, from: [:pending, :errored]
end
- after_transition to: :reimbursed, do: :send_reimbursement_reimbursed_event
+ after_transition to: :reimbursed, do: :publish_reimbursement_reimbursed_event
end
class << self
@@ -139,7 +139,7 @@ module Spree
private
- def send_reimbursement_reimbursed_event
+ def publish_reimbursement_reimbursed_event
publish_event('reimbursement.reimbursed')
end
diff --git a/core/app/models/spree/return_authorization.rb b/core/app/models/spree/return_authorization.rb
index 3a708c97aa..e596045eb6 100644
--- a/core/app/models/spree/return_authorization.rb
+++ b/core/app/models/spree/return_authorization.rb
@@ -34,7 +34,7 @@ module Spree
state_machine initial: :authorized do
before_transition to: :canceled, do: :cancel_return_items
- after_transition to: :canceled, do: :send_return_authorization_canceled_event
+ after_transition to: :canceled, do: :publish_return_authorization_canceled_event
event :cancel do
transition to: :canceled, from: :authorized, if: ->(return_authorization) { return_authorization.can_cancel_return_items? }
@@ -80,8 +80,8 @@ module Spree
return_items.each { |item| item.cancel! if item.can_cancel? }
end
- def send_return_authorization_canceled_event
- publish_event('return_authorization.cancel')
+ def publish_return_authorization_canceled_event
+ publish_event('return_authorization.canceled')
end
def generate_expedited_exchange_reimbursements
diff --git a/core/app/models/spree/return_item.rb b/core/app/models/spree/return_item.rb
index 319bf12865..4f3cfb42cd 100644
--- a/core/app/models/spree/return_item.rb
+++ b/core/app/models/spree/return_item.rb
@@ -85,7 +85,7 @@ module Spree
state_machine :reception_status, initial: :awaiting do
after_transition to: :received, do: :attempt_accept
after_transition to: :received, do: :process_inventory_unit!
- after_transition to: :received, do: :send_return_item_received_event
+ after_transition to: :received, do: :publish_return_item_received_event
event :receive do
transition to: :received, from: :awaiting
@@ -94,12 +94,12 @@ module Spree
event :cancel do
transition to: :cancelled, from: :awaiting
end
- after_transition to: :cancelled, do: :send_return_item_canceled_event
+ after_transition to: :cancelled, do: :publish_return_item_canceled_event
event :give do
transition to: :given_to_customer, from: :awaiting
end
- after_transition to: :given_to_customer, do: :send_return_item_given_event
+ after_transition to: :given_to_customer, do: :publish_return_item_given_event
end
extend DisplayMoney
@@ -274,16 +274,16 @@ module Spree
resellable? && variant.should_track_inventory? && stock_item && Spree::Config[:restock_inventory]
end
- def send_return_item_received_event
- publish_event('return_item.receive')
+ def publish_return_item_received_event
+ publish_event('return_item.received')
end
- def send_return_item_canceled_event
- publish_event('return_item.cancel')
+ def publish_return_item_canceled_event
+ publish_event('return_item.canceled')
end
- def send_return_item_given_event
- publish_event('return_item.give')
+ def publish_return_item_given_event
+ publish_event('return_item.given')
end
end
end
diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb
index 36a8c11582..b551a30f16 100644
--- a/core/app/models/spree/shipment.rb
+++ b/core/app/models/spree/shipment.rb
@@ -82,12 +82,12 @@ module Spree
event :ship do
transition from: %i(ready canceled), to: :shipped
end
- after_transition to: :shipped, do: [:after_ship, :send_shipment_shipped_webhook, :send_shipment_shipped_event]
+ after_transition to: :shipped, do: [:after_ship, :send_shipment_shipped_webhook, :publish_shipment_shipped_event]
event :cancel do
transition to: :canceled, from: %i(pending ready)
end
- after_transition to: :canceled, do: [:after_cancel, :send_shipment_canceled_event]
+ after_transition to: :canceled, do: [:after_cancel, :publish_shipment_canceled_event]
event :resume do
transition from: :canceled, to: :ready, if: lambda { |shipment|
@@ -95,7 +95,7 @@ module Spree
}
transition from: :canceled, to: :pending
end
- after_transition from: :canceled, to: %i(pending ready shipped), do: [:after_resume, :send_shipment_resumed_event]
+ after_transition from: :canceled, to: %i(pending ready shipped), do: [:after_resume, :publish_shipment_resumed_event]
after_transition do |shipment, transition|
shipment.state_changes.create!(
@@ -455,16 +455,16 @@ module Spree
ShipmentHandler.factory(self).perform
end
- def send_shipment_shipped_event
- publish_event('shipment.ship')
+ def publish_shipment_shipped_event
+ publish_event('shipment.shipped')
end
- def send_shipment_canceled_event
- publish_event('shipment.cancel')
+ def publish_shipment_canceled_event
+ publish_event('shipment.canceled')
end
- def send_shipment_resumed_event
- publish_event('shipment.resume')
+ def publish_shipment_resumed_event
+ publish_event('shipment.resumed')
end
def can_get_rates?
diff --git a/core/app/serializers/spree/events/order_serializer.rb b/core/app/serializers/spree/events/order_serializer.rb
index f4a5b6f0bd..7166981a81 100644
--- a/core/app/serializers/spree/events/order_serializer.rb
+++ b/core/app/serializers/spree/events/order_serializer.rb
@@ -24,8 +24,12 @@ module Spree
email: resource.email,
user_id: resource.user_id,
store_id: resource.store_id,
+ canceler_id: resource.canceler_id,
+ approver_id: resource.approver_id,
+ considered_risky: resource.considered_risky,
completed_at: timestamp(resource.completed_at),
canceled_at: timestamp(resource.canceled_at),
+ approved_at: timestamp(resource.approved_at),
created_at: timestamp(resource.created_at),
updated_at: timestamp(resource.updated_at)
}
diff --git a/core/app/subscribers/spree/export_subscriber.rb b/core/app/subscribers/spree/export_subscriber.rb
index 114d6b43fa..6aecd532d1 100644
--- a/core/app/subscribers/spree/export_subscriber.rb
+++ b/core/app/subscribers/spree/export_subscriber.rb
@@ -12,9 +12,9 @@ module Spree
# so there's no benefit to running the subscriber itself asynchronously.
#
class ExportSubscriber < Spree::Subscriber
- subscribes_to 'export.create', async: false
+ subscribes_to 'export.created', async: false
- on 'export.create', :generate_export_async
+ on 'export.created', :generate_export_async
def generate_export_async(event)
export_id = event.payload['id']
diff --git a/core/app/subscribers/spree/invitation_email_subscriber.rb b/core/app/subscribers/spree/invitation_email_subscriber.rb
index 093a08fd26..d27d22e342 100644
--- a/core/app/subscribers/spree/invitation_email_subscriber.rb
+++ b/core/app/subscribers/spree/invitation_email_subscriber.rb
@@ -2,11 +2,11 @@
module Spree
class InvitationEmailSubscriber < Spree::Subscriber
- subscribes_to 'invitation.create', 'invitation.accept', 'invitation.resend'
+ subscribes_to 'invitation.created', 'invitation.accepted', 'invitation.resent'
- on 'invitation.create', :send_invitation_email
- on 'invitation.accept', :send_acceptance_notification
- on 'invitation.resend', :resend_invitation_email
+ on 'invitation.created', :send_invitation_email
+ on 'invitation.accepted', :send_acceptance_notification
+ on 'invitation.resent', :resend_invitation_email
private
diff --git a/core/app/subscribers/spree/report_subscriber.rb b/core/app/subscribers/spree/report_subscriber.rb
index d0dbd648cb..c9aca4370b 100644
--- a/core/app/subscribers/spree/report_subscriber.rb
+++ b/core/app/subscribers/spree/report_subscriber.rb
@@ -12,9 +12,9 @@ module Spree
# so there's no benefit to running the subscriber itself asynchronously.
#
class ReportSubscriber < Spree::Subscriber
- subscribes_to 'report.create', async: false
+ subscribes_to 'report.created', async: false
- on 'report.create', :generate_report_async
+ on 'report.created', :generate_report_async
def generate_report_async(event)
report_id = event.payload['id']
diff --git a/core/spec/models/spree/events_spec.rb b/core/spec/models/spree/events_spec.rb
index 6a0314b4fa..c2b86489e7 100644
--- a/core/spec/models/spree/events_spec.rb
+++ b/core/spec/models/spree/events_spec.rb
@@ -13,15 +13,15 @@ RSpec.describe Spree::Events do
describe '.publish' do
it 'publishes an event' do
- event = described_class.publish('order.complete', { id: 1 })
+ event = described_class.publish('order.completed', { id: 1 })
expect(event).to be_a(Spree::Event)
- expect(event.name).to eq('order.complete')
+ expect(event.name).to eq('order.completed')
expect(event.payload).to eq({ 'id' => 1 })
end
it 'includes metadata with IDs as strings' do
- event = described_class.publish('order.complete', { id: 1 }, { user_id: 5 })
+ event = described_class.publish('order.completed', { id: 1 }, { user_id: 5 })
expect(event.metadata['user_id']).to eq('5')
end
@@ -29,12 +29,12 @@ RSpec.describe Spree::Events do
it 'notifies subscribers synchronously when async: false' do
received_events = []
- described_class.subscribe('order.complete', async: false) do |event|
+ described_class.subscribe('order.completed', async: false) do |event|
received_events << event
end
described_class.activate!
- described_class.publish('order.complete', { id: 1 })
+ described_class.publish('order.completed', { id: 1 })
expect(received_events.size).to eq(1)
end
@@ -44,12 +44,12 @@ RSpec.describe Spree::Events do
it 'subscribes with a block' do
called = false
- described_class.subscribe('order.complete', async: false) do |_event|
+ described_class.subscribe('order.completed', async: false) do |_event|
called = true
end
described_class.activate!
- described_class.publish('order.complete', {})
+ described_class.publish('order.completed', {})
expect(called).to be true
end
@@ -62,9 +62,9 @@ RSpec.describe Spree::Events do
end
end
- described_class.subscribe('order.complete', handler_class, async: false)
+ described_class.subscribe('order.completed', handler_class, async: false)
described_class.activate!
- described_class.publish('order.complete', {})
+ described_class.publish('order.completed', {})
expect(received.size).to eq(1)
end
@@ -77,12 +77,12 @@ RSpec.describe Spree::Events do
end
described_class.activate!
- described_class.publish('order.complete', {})
- described_class.publish('order.cancel', {})
- described_class.publish('product.create', {})
+ described_class.publish('order.completed', {})
+ described_class.publish('order.canceled', {})
+ described_class.publish('product.created', {})
expect(received_events.size).to eq(2)
- expect(received_events.map(&:name)).to contain_exactly('order.complete', 'order.cancel')
+ expect(received_events.map(&:name)).to contain_exactly('order.completed', 'order.canceled')
end
it 'supports global wildcard' do
@@ -93,14 +93,14 @@ RSpec.describe Spree::Events do
end
described_class.activate!
- described_class.publish('order.complete', {})
- described_class.publish('product.create', {})
+ described_class.publish('order.completed', {})
+ described_class.publish('product.created', {})
expect(received_events.size).to eq(2)
end
it 'raises error when no subscriber provided' do
- expect { described_class.subscribe('order.complete') }.to raise_error(ArgumentError)
+ expect { described_class.subscribe('order.completed') }.to raise_error(ArgumentError)
end
end
@@ -109,10 +109,10 @@ RSpec.describe Spree::Events do
received_events = []
handler = ->(event) { received_events << event }
- described_class.subscribe('order.complete', handler, async: false)
- described_class.unsubscribe('order.complete', handler)
+ described_class.subscribe('order.completed', handler, async: false)
+ described_class.unsubscribe('order.completed', handler)
described_class.activate!
- described_class.publish('order.complete', {})
+ described_class.publish('order.completed', {})
expect(received_events).to be_empty
end
@@ -120,17 +120,17 @@ RSpec.describe Spree::Events do
describe '.patterns' do
it 'returns all registered patterns' do
- described_class.subscribe('order.complete', async: false) { }
+ described_class.subscribe('order.completed', async: false) { }
described_class.subscribe('order.*', async: false) { }
- expect(described_class.patterns).to contain_exactly('order.complete', 'order.*')
+ expect(described_class.patterns).to contain_exactly('order.completed', 'order.*')
end
end
describe '.subscriptions' do
it 'returns all subscriptions' do
- described_class.subscribe('order.complete', async: false) { }
- described_class.subscribe('order.cancel', async: false) { }
+ described_class.subscribe('order.completed', async: false) { }
+ described_class.subscribe('order.canceled', async: false) { }
expect(described_class.subscriptions.size).to eq(2)
end
@@ -140,14 +140,14 @@ RSpec.describe Spree::Events do
it 'disables events within the block' do
received = false
- described_class.subscribe('order.complete', async: false) do
+ described_class.subscribe('order.completed', async: false) do
received = true
end
described_class.activate!
described_class.disable do
- described_class.publish('order.complete', {})
+ described_class.publish('order.completed', {})
end
expect(received).to be false
@@ -187,7 +187,7 @@ RSpec.describe Spree::Events do
describe '.reset!' do
it 'clears all subscriptions' do
- described_class.subscribe('order.complete', async: false) { }
+ described_class.subscribe('order.completed', async: false) { }
described_class.reset!
@@ -200,11 +200,11 @@ RSpec.describe Spree::Events do
received1 = []
received2 = []
- described_class.subscribe('order.complete', async: false) { |e| received1 << e }
- described_class.subscribe('order.complete', async: false) { |e| received2 << e }
+ described_class.subscribe('order.completed', async: false) { |e| received1 << e }
+ described_class.subscribe('order.completed', async: false) { |e| received2 << e }
described_class.activate!
- described_class.publish('order.complete', {})
+ described_class.publish('order.completed', {})
expect(received1.size).to eq(1)
expect(received2.size).to eq(1)
@@ -214,12 +214,12 @@ RSpec.describe Spree::Events do
exact_received = []
pattern_received = []
- described_class.subscribe('order.complete', async: false) { |e| exact_received << e }
+ described_class.subscribe('order.completed', async: false) { |e| exact_received << e }
described_class.subscribe('order.*', async: false) { |e| pattern_received << e }
described_class.activate!
- described_class.publish('order.complete', {})
- described_class.publish('order.cancel', {})
+ described_class.publish('order.completed', {})
+ described_class.publish('order.canceled', {})
expect(exact_received.size).to eq(1)
expect(pattern_received.size).to eq(2)
diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rb
index fe7563d30f..0ff7f44f94 100644
--- a/core/spec/models/spree/order_spec.rb
+++ b/core/spec/models/spree/order_spec.rb
@@ -224,45 +224,24 @@ describe Spree::Order, type: :model do
context 'events' do
let(:order) { create(:completed_order_with_totals, store: store) }
- let(:received_events) { [] }
- before do
- Spree::Events.reset!
- Spree::Events.subscribe('order.cancel', async: false) { |e| received_events << e }
- Spree::Events.activate!
- end
-
- after { Spree::Events.reset! }
-
- it 'publishes order.cancel event' do
+ it 'publishes order.canceled event' do
+ expect(order).to receive(:publish_event).with('order.canceled').at_least(:once)
+ allow(order).to receive(:publish_event).with(anything)
order.cancel!
-
- expect(received_events.size).to eq(1)
- expect(received_events.first.payload['id']).to eq(order.id)
- expect(received_events.first.payload['number']).to eq(order.number)
end
end
end
describe '#after_resume' do
let(:order) { create(:completed_order_with_totals, store: store) }
- let(:received_events) { [] }
-
- before do
- Spree::Events.reset!
- Spree::Events.subscribe('order.resume', async: false) { |e| received_events << e }
- Spree::Events.activate!
- order.cancel!
- end
- after { Spree::Events.reset! }
+ before { order.cancel! }
- it 'publishes order.resume event' do
+ it 'publishes order.resumed event' do
+ expect(order).to receive(:publish_event).with('order.resumed').at_least(:once)
+ allow(order).to receive(:publish_event).with(anything)
order.resume!
-
- expect(received_events.size).to eq(1)
- expect(received_events.first.payload['id']).to eq(order.id)
- expect(received_events.first.payload['number']).to eq(order.number)
end
end
@@ -312,15 +291,9 @@ describe Spree::Order, type: :model do
context 'events' do
let(:order) { create(:completed_order_with_totals) }
- it 'publishes order.update event' do
- events = []
- Spree::Events.subscribe('order.update', async: false) { |e| events << e }
-
+ it 'publishes order.canceled event' do
+ expect(order).to receive(:publish_event).with('order.canceled')
order.canceled_by(admin_user)
-
- update_event = events.find { |e| e.payload['canceler_id'] == admin_user.id }
- expect(update_event).not_to be_nil
- expect(update_event.payload).to include('id' => order.id)
end
end
end
@@ -428,23 +401,13 @@ describe Spree::Order, type: :model do
context 'events' do
let(:order) { create(:order_with_line_items, store: store) }
- let(:received_events) { [] }
-
- before do
- Spree::Events.reset!
- Spree::Events.subscribe('order.complete', async: false) { |e| received_events << e }
- Spree::Events.activate!
- order.update_column(:state, 'complete')
- end
- after { Spree::Events.reset! }
+ before { order.update_column(:state, 'complete') }
- it 'publishes order.complete event' do
+ it 'publishes order.completed event' do
+ expect(order).to receive(:publish_event).with('order.completed').at_least(:once)
+ allow(order).to receive(:publish_event).with(anything)
order.finalize!
-
- expect(received_events.size).to eq(1)
- expect(received_events.first.payload['id']).to eq(order.id)
- expect(received_events.first.payload['number']).to eq(order.number)
end
end
end
@@ -723,16 +686,10 @@ describe Spree::Order, type: :model do
end
context 'events' do
- it 'publishes order.update event' do
+ it 'publishes order.updated event' do
order = create(:order_with_totals, state: 'delivery')
- events = []
- Spree::Events.subscribe('order.update', async: false) { |e| events << e }
-
+ expect(order).to receive(:publish_event).with('order.updated').at_least(:once)
order.restart_checkout_flow
-
- update_event = events.find { |e| e.payload['state'] == 'cart' }
- expect(update_event).not_to be_nil
- expect(update_event.payload).to include('id' => order.id)
end
end
end
@@ -783,7 +740,7 @@ describe Spree::Order, type: :model do
expect(order.collect_frontend_payment_methods).to include(payment_method)
end
- it 'does not include backend payment method ' do
+ it 'does not include backend payment method' do
Spree::PaymentMethod.create!(name: 'Fake', active: true, display_on: 'back_end', stores: [store])
expect(order.collect_frontend_payment_methods.count).to eq(0)
end
@@ -796,7 +753,7 @@ describe Spree::Order, type: :model do
it 'does not include a payment method that is not suitable for this order' do
allow(Spree::PaymentMethod).to receive(:available_on_front_end).and_return(methods)
- expect(order.collect_frontend_payment_methods).to match_array [ok_method]
+ expect(order.collect_frontend_payment_methods).to contain_exactly(ok_method)
end
it 'does not include a payment method from different stores' do
@@ -1008,22 +965,16 @@ describe Spree::Order, type: :model do
context 'events' do
let(:order) { create(:order, order_attributes) }
- it 'publishes order.update event' do
- events = []
- Spree::Events.subscribe('order.update', async: false) { |e| events << e }
-
+ it 'publishes order.updated event' do
+ expect(order).to receive(:publish_event).with('order.updated')
order.associate_user!(user)
-
- expect(events.size).to eq(1)
- expect(events.first.payload).to include('id' => order.id)
- expect(events.first.payload).to include('user_id' => user.id)
end
end
end
describe '#disassociate_user!' do
let(:order) { create(:order_with_line_items) }
- let(:expected_order_attributes) {
+ let(:expected_order_attributes) do
{
user: nil,
user_id: nil,
@@ -1035,7 +986,7 @@ describe Spree::Order, type: :model do
ship_address: nil,
ship_address_id: nil
}
- }
+ end
it 'disassociates a user from an order' do
order.disassociate_user!
@@ -1065,15 +1016,9 @@ describe Spree::Order, type: :model do
end
context 'events' do
- it 'publishes order.update event' do
- events = []
- Spree::Events.subscribe('order.update', async: false) { |e| events << e }
-
+ it 'publishes order.approved event' do
+ expect(order).to receive(:publish_event).with('order.approved').at_least(:once)
order.approved_by(admin_user)
-
- update_event = events.find { |e| e.payload['approver_id'] == admin_user.id }
- expect(update_event).not_to be_nil
- expect(update_event.payload).to include('id' => order.id)
end
end
end
@@ -1087,15 +1032,9 @@ describe Spree::Order, type: :model do
end
context 'events' do
- it 'publishes order.update event' do
- events = []
- Spree::Events.subscribe('order.update', async: false) { |e| events << e }
-
+ it 'publishes order.updated event' do
+ expect(order).to receive(:publish_event).with('order.updated')
order.considered_risky!
-
- update_event = events.find { |e| e.payload['considered_risky'] == true }
- expect(update_event).not_to be_nil
- expect(update_event.payload).to include('id' => order.id)
end
end
end
@@ -1113,15 +1052,9 @@ describe Spree::Order, type: :model do
end
context 'events' do
- it 'publishes order.update event' do
- events = []
- Spree::Events.subscribe('order.update', async: false) { |e| events << e }
-
+ it 'publishes order.approved event' do
+ expect(order).to receive(:publish_event).with('order.approved')
order.approve!
-
- update_event = events.find { |e| e.payload['considered_risky'] == false }
- expect(update_event).not_to be_nil
- expect(update_event.payload).to include('id' => order.id)
end
end
end
@@ -1154,15 +1087,9 @@ describe Spree::Order, type: :model do
end
context 'events' do
- it 'publishes order.update event' do
- events = []
- Spree::Events.subscribe('order.update', async: false) { |e| events << e }
-
+ it 'publishes order.updated event' do
+ expect(order).to receive(:publish_event).with('order.updated').at_least(:once)
order.ensure_updated_shipments
-
- update_event = events.find { |e| e.payload['shipment_total'].to_f == 0 }
- expect(update_event).not_to be_nil
- expect(update_event.payload).to include('id' => order.id)
end
end
end
@@ -1658,7 +1585,7 @@ describe Spree::Order, type: :model do
end
context 'when zero amount credit-card payment' do
it 'expect not to build a new payment' do
- expect { order.assign_attributes(attributes) }.to change { order.payments.size }.by(0)
+ expect { order.assign_attributes(attributes) }.not_to change { order.payments.size }
end
end
@@ -1741,13 +1668,13 @@ describe Spree::Order, type: :model do
describe '#valid_promotions' do
def create_adjustment(label, order_or_line_item, amount, source)
create(:adjustment,
- order: order,
- adjustable: order_or_line_item,
- source: source,
- amount: amount,
- state: 'closed',
- label: label,
- mandatory: false)
+ order: order,
+ adjustable: order_or_line_item,
+ source: source,
+ amount: amount,
+ state: 'closed',
+ label: label,
+ mandatory: false)
end
let!(:order) { create(:order_with_line_items, line_items_count: 10) }
@@ -1957,7 +1884,7 @@ describe Spree::Order, type: :model do
let!(:user) { create(:user_with_addresses) }
it 'changes user default bill address' do
- expect(user.bill_address_id).not_to be nil
+ expect(user.bill_address_id).not_to be_nil
expect { subject }.to(change { user.bill_address_id })
end
@@ -1978,7 +1905,7 @@ describe Spree::Order, type: :model do
let!(:user) { create(:user) }
it 'changes user default bill addresss' do
- expect(user.bill_address_id).to be nil
+ expect(user.bill_address_id).to be_nil
expect(user.addresses).to be_empty
expect { subject }.to change { user.bill_address_id }
@@ -1992,7 +1919,7 @@ describe Spree::Order, type: :model do
before { user.bill_address = nil }
it 'changes user default bill addresss' do
- expect(user.bill_address_id).to be nil
+ expect(user.bill_address_id).to be_nil
expect(user.addresses).not_to be_empty
expect { subject }.to change { user.bill_address_id }
@@ -2052,7 +1979,7 @@ describe Spree::Order, type: :model do
let!(:user) { create(:user) }
it 'changes user default ship address' do
- expect(user.ship_address_id).to be nil
+ expect(user.ship_address_id).to be_nil
expect(user.addresses).to be_empty
expect { subject }.to change { user.ship_address_id }
@@ -2066,7 +1993,7 @@ describe Spree::Order, type: :model do
before { user.update(ship_address: nil) }
it 'changes user default ship address' do
- expect(user.ship_address_id).to be nil
+ expect(user.ship_address_id).to be_nil
expect(user.addresses).not_to be_empty
expect { subject }.to change { user.ship_address_id }
diff --git a/emails/app/subscribers/spree/order_email_subscriber.rb b/emails/app/subscribers/spree/order_email_subscriber.rb
index 33ca9bca63..1015d03dbd 100644
--- a/emails/app/subscribers/spree/order_email_subscriber.rb
+++ b/emails/app/subscribers/spree/order_email_subscriber.rb
@@ -2,10 +2,10 @@
module Spree
class OrderEmailSubscriber < Spree::Subscriber
- subscribes_to 'order.complete', 'order.cancel', 'order.resend_confirmation_email'
+ subscribes_to 'order.completed', 'order.canceled', 'order.resend_confirmation_email'
- on 'order.complete', :send_confirmation_email
- on 'order.cancel', :send_cancel_email
+ on 'order.completed', :send_confirmation_email
+ on 'order.canceled', :send_cancel_email
on 'order.resend_confirmation_email', :resend_confirmation_email
private
diff --git a/emails/app/subscribers/spree/shipment_email_subscriber.rb b/emails/app/subscribers/spree/shipment_email_subscriber.rb
index 0fc5bff9bd..ea3dcc165d 100644
--- a/emails/app/subscribers/spree/shipment_email_subscriber.rb
+++ b/emails/app/subscribers/spree/shipment_email_subscriber.rb
@@ -2,7 +2,7 @@
module Spree
class ShipmentEmailSubscriber < Spree::Subscriber
- subscribes_to 'shipment.ship'
+ subscribes_to 'shipment.shipped'
def handle(event)
shipment = find_shipment(event)