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
Remove super class re-definition for testing prependings.
Sebastian Palmaef979a75cc37
diff --git a/api/app/models/spree/api/webhooks/payment.rb b/api/app/models/spree/api/webhooks/payment.rbindex 119d6f7da6..6e3dda54b0 100644--- a/api/app/models/spree/api/webhooks/payment.rb+++ b/api/app/models/spree/api/webhooks/payment.rb@@ -2,9 +2,7 @@ module Spreemodule Apimodule Webhooksmodule Payment- private-- def after_void+ def voidsuperSpree::Webhooks::Endpoints::QueueRequests.call(event: 'payment.void', payload: {})enddiff --git a/api/app/models/spree/api/webhooks/shipment.rb b/api/app/models/spree/api/webhooks/shipment.rbindex 152da17260..1594bcdca3 100644--- a/api/app/models/spree/api/webhooks/shipment.rb+++ b/api/app/models/spree/api/webhooks/shipment.rb@@ -2,9 +2,7 @@ module Spreemodule Apimodule Webhooksmodule Shipment- private-- def after_ship+ def shipsuperSpree::Webhooks::Endpoints::QueueRequests.call(event: 'shipment.ship', payload: {})enddiff --git a/api/spec/models/spree/api/webhooks/order_spec.rb b/api/spec/models/spree/api/webhooks/order_spec.rbindex 5cdabee86b..86c37de87f 100644--- a/api/spec/models/spree/api/webhooks/order_spec.rb+++ b/api/spec/models/spree/api/webhooks/order_spec.rb@@ -1,47 +1,34 @@require 'spec_helper'-class TextFormatter-end--xdescribe Spree::Order do+describe Spree::Order dodescribe 'sending webhooks after transitioning from states' do- let(:order) { Spree::Order.create }let(:payload) { {} }let(:queue_requests) { instance_double(Spree::Webhooks::Endpoints::QueueRequests) }+ let!(:store) { create(:store, default: true) }- shared_examples 'queues a webhook request' do |event, method_name|- before do- allow(Spree::Webhooks::Endpoints::QueueRequests).to receive(:new).and_return(queue_requests)- allow(queue_requests).to receive(:call).with(any_args)- # redefine `method_name` method body to assert super is being used- # [TODO]: find another way to test super is being used- # this makes other tests relying on `method_name` fail- described_class.class_eval do- define_method(method_name) do- TextFormatter.new.to_s- end- end- end-- it "executes QueueRequests.call with a order.#{event} event and {} payload after calling super" do- expect(TextFormatter).to(- receive(:new).and_return(- double(:scope).tap { |scope| expect(scope).to receive(:to_s) }- )- )- order.send(method_name)- expect(queue_requests).to have_received(:call).with(event: "order.#{event}", payload: payload).once- end+ before do+ allow(Spree::Webhooks::Endpoints::QueueRequests).to receive(:new).and_return(queue_requests)+ allow(queue_requests).to receive(:call).with(any_args)endcontext '#cancel' do- include_examples 'queues a webhook request', :cancel, :cancel+ let(:order) { create(:completed_order_with_totals, store: store) }++ it 'executes QueueRequests.call with a order.cancel event and {} payload after calling super' do+ order.cancel+ expect(queue_requests).to have_received(:call).with(event: 'order.cancel', payload: payload).once+ endendcontext '#finalize!' do- before { order.update_column :state, 'complete' }+ let(:order) { Spree::Order.create(email: '[email protected]', store: store) }- include_examples 'queues a webhook request', :complete, :finalize!+ it 'executes QueueRequests.call with a order.complete event and {} payload after calling super' do+ # check the last statement in the method body is actually+ # executed, because Order doesn't have a complete method.+ order.finalize!+ expect(queue_requests).to have_received(:call).with(event: 'order.complete', payload: payload).once+ endendendenddiff --git a/api/spec/models/spree/api/webhooks/payment_spec.rb b/api/spec/models/spree/api/webhooks/payment_spec.rbindex b9c2d9f412..92d3a10fb4 100644--- a/api/spec/models/spree/api/webhooks/payment_spec.rb+++ b/api/spec/models/spree/api/webhooks/payment_spec.rb@@ -1,34 +1,19 @@require 'spec_helper'-class TextFormatter-end-describe Spree::Payment dolet(:payment) { create(:payment) }- describe '#after_void' do+ describe '#void' dolet(:payload) { {} }let(:queue_requests) { instance_double(Spree::Webhooks::Endpoints::QueueRequests) }before do- # redefine the after_void method body to assert super is being used- described_class.class_eval do- def after_void- TextFormatter.new.to_s- end- end-allow(Spree::Webhooks::Endpoints::QueueRequests).to receive(:new).and_return(queue_requests)allow(queue_requests).to receive(:call).with(any_args)endshared_examples 'queues a webhook request' do- it 'executes QueueRequests.call with a payment.void event and {} payload after calling super' do- expect(TextFormatter).to(- receive(:new).and_return(- double(:scope).tap { |scope| expect(scope).to receive(:to_s) }- )- )+ it 'executes QueueRequests.call with a payment.void event and {} payload after invoking void' dopayment.voidexpect(queue_requests).to have_received(:call).with(event: 'payment.void', payload: payload).onceenddiff --git a/api/spec/models/spree/api/webhooks/shipment_spec.rb b/api/spec/models/spree/api/webhooks/shipment_spec.rbindex 376464ec8b..b53be83fb5 100644--- a/api/spec/models/spree/api/webhooks/shipment_spec.rb+++ b/api/spec/models/spree/api/webhooks/shipment_spec.rb@@ -1,20 +1,10 @@require 'spec_helper'-class TextFormatter-end-describe Spree::Shipment dolet(:shipment) { create(:shipment) }- context '#after_ship' do+ context '#ship' dobefore do- # redefine the after_ship method body to assert super is being used- described_class.class_eval do- def after_ship- TextFormatter.new.to_s- end- end-allow(Spree::Webhooks::Endpoints::QueueRequests).to receive(:new).and_return(queue_requests)allow(queue_requests).to receive(:call).with(any_args)end@@ -23,11 +13,7 @@ describe Spree::Shipment dolet(:queue_requests) { instance_double(Spree::Webhooks::Endpoints::QueueRequests) }it 'executes QueueRequests.call with a shipment.ship event and {} payload after calling super' do- expect(TextFormatter).to(- receive(:new).and_return(- double(:scope).tap { |scope| expect(scope).to receive(:to_s) }- )- )+ expect(shipment).to receive(:after_ship).onceshipment.cancel # previous state that allows the object be shippedshipment.shipexpect(queue_requests).to have_received(:call).with(event: 'shipment.ship', payload: payload).oncediff --git a/api/spec/serializers/spree/v2/storefront/menu_serializer_spec.rb b/api/spec/serializers/spree/v2/storefront/menu_serializer_spec.rbindex c8bc0c06b5..f22ad9983b 100644--- a/api/spec/serializers/spree/v2/storefront/menu_serializer_spec.rb+++ b/api/spec/serializers/spree/v2/storefront/menu_serializer_spec.rb@@ -3,9 +3,12 @@ require 'spec_helper'describe Spree::V2::Storefront::MenuSerializer dosubject { described_class.new(menu) }- let!(:menu) { create(:menu) }+ let(:menu) { create(:menu) }- before { Rails.cache.clear }+ before do+ allow_any_instance_of(Spree::Base).to receive(:queue_webhooks_requests!)+ menu+ endit { expect(subject.serializable_hash).to be_kind_of(Hash) }diff --git a/api/spec/spec_helper.rb b/api/spec/spec_helper.rbindex 998de3c110..c003672004 100644--- a/api/spec/spec_helper.rb+++ b/api/spec/spec_helper.rb@@ -65,6 +65,8 @@ RSpec.configure do |config|config.include Spree::TestingSupport::ImageHelpersconfig.before do+ Rails.cache.clear+reset_spree_preferencesSpree::Api::Config[:requires_authentication] = truediff --git a/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rbindex 85313d24b5..be52a2231a 100644--- a/core/app/models/spree/payment.rb+++ b/core/app/models/spree/payment.rb@@ -97,7 +97,6 @@ module Spreeevent :void dotransition from: [:pending, :processing, :completed, :checkout], to: :voidend- after_transition to: :void, do: :after_void# when the card brand isnt supportedevent :invalidate dotransition from: [:checkout], to: :invalid@@ -196,10 +195,6 @@ module Spreeprivate- def after_void- # this method is prepended in api/ to queue Webhooks requests- end-def has_invalid_state?INVALID_STATES.include?(state)end