-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The specs here were specific to the legacy implementation of the event system, and therefore no longer pass on the `master` branch of Solidus where we now use a [new implementation of the event bus](solidusio/solidus#4342). This change attempts to refactor the tests to focus on observing the side-effects of the object under test which should be independent of the underlying implementation. This test is valuable regardless of what version of Solidus we are running against as our extension relies on the event being published when a specific action happens and that the payload contains the necessary object. Co-authored-by: Andrew Stewart <andrew@super.gd>
- Loading branch information
1 parent
ff8a77e
commit 10a5cee
Showing
3 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,45 @@ | ||
RSpec.describe Spree::OrderUpdater do | ||
describe '#update' do | ||
subject { described_class.new(order).update } | ||
|
||
let(:order) { create(:order) } | ||
|
||
module TestSubscriber | ||
include Spree::Event::Subscriber | ||
include SolidusSupport::LegacyEventCompat::Subscriber | ||
|
||
event_action :order_recalculated | ||
|
||
def order_recalculated(_event) | ||
end | ||
end | ||
|
||
if SolidusSupport::LegacyEventCompat.using_legacy? | ||
let(:event_type_class) { ActiveSupport::Notifications::Event } | ||
|
||
before do | ||
if TestSubscriber.respond_to?(:subscribe!) | ||
TestSubscriber.subscribe! | ||
else | ||
TestSubscriber.activate | ||
end | ||
end | ||
else | ||
let(:event_type_class) { Omnes::UnstructuredEvent } | ||
|
||
before { TestSubscriber.omnes_subscriber.subscribe_to(Spree::Bus) } | ||
end | ||
|
||
it 'fires the order_recalculated event exactly once' do | ||
stub_const('Spree::Event', class_spy(Spree::Event)) | ||
order = create(:order) | ||
allow(TestSubscriber).to receive(:order_recalculated) | ||
|
||
described_class.new(order).update | ||
subject | ||
|
||
expect(Spree::Event).to have_received(:fire).with('order_recalculated', order: order).once | ||
expect(TestSubscriber).to have_received(:order_recalculated) | ||
.with(instance_of(event_type_class)) | ||
.once do |event| | ||
expect(event.payload[:order]).to eq(order) | ||
end | ||
end | ||
end | ||
end |