From 1125ac635bb9db44b7595c8cfc5ce2030d745c44 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 23 Jun 2021 12:54:18 +0200 Subject: [PATCH] Make test not too dangerously play with time We could get hurt and introduce flakiness in the build. --- spec/jobs/subscription_placement_job_spec.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/jobs/subscription_placement_job_spec.rb b/spec/jobs/subscription_placement_job_spec.rb index e44caf472b..fed457b1b4 100644 --- a/spec/jobs/subscription_placement_job_spec.rb +++ b/spec/jobs/subscription_placement_job_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' describe SubscriptionPlacementJob do + include ActiveSupport::Testing::TimeHelpers + let(:job) { SubscriptionPlacementJob.new } let(:summarizer) { OrderManagement::Subscriptions::Summarizer.new } @@ -141,11 +143,13 @@ describe SubscriptionPlacementJob do end it "processes the order to completion, but does not process the payment" do - # If this spec starts complaining about no shipping methods being available - # on CI, there is probably another spec resetting the currency though Rails.cache.clear - expect{ service.call }.to change{ order.reload.completed_at }.from(nil) - expect(order.completed_at).to be_within(5.seconds).of Time.zone.now - expect(order.payments.first.state).to eq "checkout" + freeze_time do + service.call + proxy_order.order.reload.completed_at + + expect(proxy_order.order.completed_at).to eq(Time.zone.now) + expect(proxy_order.order.payments.first.state).to eq "checkout" + end end it "does not enqueue confirmation emails" do