mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Fix proxy_order.placed_at test and deal with time
Relying on Rails' `freeze_time` is much more reliable than this brittle magic number. It turns out Timecop is not needed for this case anymore. See https://frontdeveloper.pl/2020/03/how-we-migrated-from-timecop-to-built-in-rails-5-2-time-helpers/.
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe PlaceOrder do
|
||||
include ActiveSupport::Testing::TimeHelpers
|
||||
|
||||
subject { described_class.new(proxy_order, summarizer, logger, changes) }
|
||||
|
||||
let(:changes) { {} }
|
||||
@@ -22,12 +24,13 @@ describe PlaceOrder do
|
||||
|
||||
before do
|
||||
allow(SubscriptionMailer).to receive(:empty_email) { mail_mock }
|
||||
subject.initialise_order
|
||||
end
|
||||
|
||||
it "marks placeable proxy_orders as processed by setting placed_at" do
|
||||
expect{ subject.call(order, subject) }.to change{ proxy_order.reload.placed_at }
|
||||
expect(proxy_order.placed_at).to be_within(5.seconds).of Time.zone.now
|
||||
freeze_time do
|
||||
expect { subject.call }.to change { proxy_order.reload.placed_at }
|
||||
expect(proxy_order.placed_at).to eq(Time.zone.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user