Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Move `Spree::Events` code from models to lib
Damian Legawiec477a4daa428b
diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rbindex dc26a807f6..87d97c6cfb 100644--- a/core/lib/spree/core.rb+++ b/core/lib/spree/core.rb@@ -426,6 +426,7 @@ require 'spree/permitted_attributes'require 'spree/service_module'require 'spree/database_type_utilities'require 'spree/analytics'+require 'spree/events'require 'spree/core/partials'require 'spree/core/importer'diff --git a/core/app/models/spree/events.rb b/core/lib/spree/events.rbsimilarity index 97%rename from core/app/models/spree/events.rbrename to core/lib/spree/events.rbindex 13d27d046b..bf38eecdae 100644--- a/core/app/models/spree/events.rb+++ b/core/lib/spree/events.rb@@ -1,5 +1,9 @@# frozen_string_literal: true+require_relative 'events/registry'+require_relative 'events/adapters/base'+require_relative 'events/adapters/active_support_notifications'+module Spree# Main entry point for the Spree event system.#diff --git a/core/app/models/spree/events/adapters/active_support_notifications.rb b/core/lib/spree/events/adapters/active_support_notifications.rbsimilarity index 100%rename from core/app/models/spree/events/adapters/active_support_notifications.rbrename to core/lib/spree/events/adapters/active_support_notifications.rbdiff --git a/core/app/models/spree/events/adapters/base.rb b/core/lib/spree/events/adapters/base.rbsimilarity index 100%rename from core/app/models/spree/events/adapters/base.rbrename to core/lib/spree/events/adapters/base.rbdiff --git a/core/app/models/spree/events/registry.rb b/core/lib/spree/events/registry.rbsimilarity index 100%rename from core/app/models/spree/events/registry.rbrename to core/lib/spree/events/registry.rbdiff --git a/core/spec/models/spree/events/registry_spec.rb b/core/spec/lib/spree/events/registry_spec.rbsimilarity index 100%rename from core/spec/models/spree/events/registry_spec.rbrename to core/spec/lib/spree/events/registry_spec.rbdiff --git a/core/spec/models/spree/events_spec.rb b/core/spec/lib/spree/events_spec.rbsimilarity index 100%rename from core/spec/models/spree/events_spec.rbrename to core/spec/lib/spree/events_spec.rbdiff --git a/core/spec/models/spree/event_spec.rb b/core/spec/models/spree/event_spec.rbindex b0e5aac99c..966d23272b 100644--- a/core/spec/models/spree/event_spec.rb+++ b/core/spec/models/spree/event_spec.rb@@ -14,26 +14,25 @@ RSpec.describe Spree::Event doexpect(event.payload).to eq({ 'id' => 1, 'number' => 'R123' })end- it 'freezes the name, payload, and metadata' do+ it 'freezes the payload and metadata' doevent = described_class.new(name: 'order.complete',payload: { id: 1 })- expect(event.name).to be_frozenexpect(event.payload).to be_frozenexpect(event.metadata).to be_frozenend- it 'sets a timestamp' do+ it 'sets created_at' doevent = described_class.new(name: 'test', payload: {})- expect(event.timestamp).to be_within(1.second).of(Time.current)+ expect(event.created_at).to be_within(1.second).of(Time.current)end- it 'generates an event_id in metadata' do+ it 'generates an id' doevent = described_class.new(name: 'test', payload: {})- expect(event.metadata['event_id']).to be_present- expect(event.metadata['event_id']).to match(/\A[0-9a-f-]{36}\z/)+ expect(event.id).to be_present+ expect(event.id).to match(/\A[0-9a-f-]{36}\z/)endit 'includes spree_version in metadata' do@@ -126,27 +125,27 @@ RSpec.describe Spree::Event doendend- describe '#to_h' do- it 'returns a hash representation with IDs as strings' do+ describe '#attributes' do+ it 'returns a hash representation with string keys' doevent = described_class.new(name: 'order.complete',payload: { id: 1 },metadata: { user_id: 5 })- hash = event.to_h+ hash = event.attributes- expect(hash[:name]).to eq('order.complete')- expect(hash[:payload]).to eq({ 'id' => 1 })- expect(hash[:metadata]['user_id']).to eq('5')- expect(hash[:timestamp]).to eq(event.timestamp)+ expect(hash['name']).to eq('order.complete')+ expect(hash['payload']).to eq({ 'id' => 1 })+ expect(hash['metadata']['user_id']).to eq('5')+ expect(hash['created_at']).to eq(event.created_at)endenddescribe '#inspect' doit 'returns a readable string representation' doevent = described_class.new(name: 'order.complete', payload: {})- expect(event.inspect).to match(/Spree::Event name="order.complete"/)+ expect(event.inspect).to match(/Spree::Event id="[0-9a-f-]{36}" name="order.complete" created_at=/)endendend