Use Time.zone.now instead of Time.now

This commit is contained in:
Rob Harrington
2017-11-17 13:44:35 +11:00
parent 03f1980b1b
commit fb28940952
14 changed files with 32 additions and 32 deletions

View File

@@ -3,7 +3,7 @@ require 'open_food_network/standing_order_payment_updater'
class StandingOrderConfirmJob
def perform
ids = proxy_orders.pluck(:id)
proxy_orders.update_all(confirmed_at: Time.now)
proxy_orders.update_all(confirmed_at: Time.zone.now)
ProxyOrder.where(id: ids).each do |proxy_order|
@order = proxy_order.order
process!
@@ -20,7 +20,7 @@ class StandingOrderConfirmJob
end
def recently_closed_order_cycles
OrderCycle.closed.where('order_cycles.orders_close_at BETWEEN (?) AND (?) OR order_cycles.updated_at BETWEEN (?) AND (?)', 1.hour.ago, Time.now, 1.hour.ago, Time.now)
OrderCycle.closed.where('order_cycles.orders_close_at BETWEEN (?) AND (?) OR order_cycles.updated_at BETWEEN (?) AND (?)', 1.hour.ago, Time.zone.now, 1.hour.ago, Time.zone.now)
end
def process!

View File

@@ -1,7 +1,7 @@
class StandingOrderPlacementJob
def perform
ids = proxy_orders.pluck(:id)
proxy_orders.update_all(placed_at: Time.now)
proxy_orders.update_all(placed_at: Time.zone.now)
ProxyOrder.where(id: ids).each do |proxy_order|
proxy_order.initialise_order!
process(proxy_order.order)

View File

@@ -12,7 +12,7 @@ class ProxyOrder < ActiveRecord::Base
def state
return 'canceled' if canceled?
if !order || order_cycle.orders_open_at > Time.now
if !order || order_cycle.orders_open_at > Time.zone.now
standing_order.paused? ? 'paused' : 'pending'
else
return 'cart' if placed_and_open?
@@ -67,6 +67,6 @@ class ProxyOrder < ActiveRecord::Base
def placed_and_open?
order.andand.state == 'complete' &&
order_cycle.orders_close_at > Time.now
order_cycle.orders_close_at > Time.zone.now
end
end

View File

@@ -9,6 +9,6 @@ class Schedule < ActiveRecord::Base
scope :with_coordinator, lambda { |enterprise| joins(:order_cycles).where('coordinator_id = ?', enterprise.id).select('DISTINCT schedules.*') }
def current_or_next_order_cycle
order_cycles.where('orders_close_at > (?)', Time.now).order('orders_close_at ASC').first
order_cycles.where('orders_close_at > (?)', Time.zone.now).order('orders_close_at ASC').first
end
end

View File

@@ -323,7 +323,7 @@ Spree::Order.class_eval do
# Override or Spree method. Used to prevent payments on standing orders from being processed in the normal way.
# ie. they are 'hidden' from processing logic until after the order cycle has closed.
def pending_payments
return [] if standing_order.present? && order_cycle.orders_close_at.andand > Time.now
return [] if standing_order.present? && order_cycle.orders_close_at.andand > Time.zone.now
payments.select {|p| p.state == "checkout"} # Original definition
end

View File

@@ -44,7 +44,7 @@ describe Admin::ProxyOrdersController, type: :controller do
json_response = JSON.parse(response.body)
expect(json_response['state']).to eq "canceled"
expect(json_response['id']).to eq proxy_order.id
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
end
end

View File

@@ -431,7 +431,7 @@ describe Admin::StandingOrdersController, type: :controller do
json_response = JSON.parse(response.body)
expect(json_response['canceled_at']).to_not be nil
expect(json_response['id']).to eq standing_order.id
expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(order.reload.state).to eq 'complete'
expect(proxy_order.reload.canceled_at).to be nil
end
@@ -451,9 +451,9 @@ describe Admin::StandingOrdersController, type: :controller do
json_response = JSON.parse(response.body)
expect(json_response['canceled_at']).to_not be nil
expect(json_response['id']).to eq standing_order.id
expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(order.reload.state).to eq 'canceled'
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(mail_mock).to have_received(:deliver)
end
end
@@ -465,7 +465,7 @@ describe Admin::StandingOrdersController, type: :controller do
json_response = JSON.parse(response.body)
expect(json_response['canceled_at']).to_not be nil
expect(json_response['id']).to eq standing_order.id
expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
end
end
end
@@ -530,7 +530,7 @@ describe Admin::StandingOrdersController, type: :controller do
json_response = JSON.parse(response.body)
expect(json_response['paused_at']).to_not be nil
expect(json_response['id']).to eq standing_order.id
expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.now
expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.zone.now
expect(order.reload.state).to eq 'complete'
expect(proxy_order.reload.canceled_at).to be nil
end
@@ -550,9 +550,9 @@ describe Admin::StandingOrdersController, type: :controller do
json_response = JSON.parse(response.body)
expect(json_response['paused_at']).to_not be nil
expect(json_response['id']).to eq standing_order.id
expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.now
expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.zone.now
expect(order.reload.state).to eq 'canceled'
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(mail_mock).to have_received(:deliver)
end
end
@@ -564,7 +564,7 @@ describe Admin::StandingOrdersController, type: :controller do
json_response = JSON.parse(response.body)
expect(json_response['paused_at']).to_not be nil
expect(json_response['id']).to eq standing_order.id
expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.now
expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.zone.now
end
end
end

View File

@@ -76,7 +76,7 @@ feature 'Standing Orders' do
find("a.cancel-order").trigger('click')
end
expect(page).to have_content 'CANCELLED'
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
# Resuming an order
accept_alert 'Are you sure?' do

View File

@@ -324,7 +324,7 @@ describe StandingOrderForm do
expect(standing_order.reload.proxy_orders.count).to be 1
expect(standing_order.reload.orders.count).to be 1
expect(form.save).to be false
expect(standing_order.reload.begins_at).to be_within(5.seconds).of Time.now
expect(standing_order.reload.begins_at).to be_within(5.seconds).of Time.zone.now
expect(standing_order.proxy_orders.count).to be 1
expect(standing_order.orders.count).to be 1
end

View File

@@ -70,7 +70,7 @@ describe StandingOrderConfirmJob do
it "marks confirmable proxy_orders as processed by setting confirmed_at" do
expect{ job.perform }.to change{ proxy_order.reload.confirmed_at }
expect(proxy_order.confirmed_at).to be_within(5.seconds).of Time.now
expect(proxy_order.confirmed_at).to be_within(5.seconds).of Time.zone.now
end
it "processes confirmable proxy_orders" do

View File

@@ -49,7 +49,7 @@ describe StandingOrderPlacementJob do
it "marks placeable proxy_orders as processed by setting placed_at" do
expect{ job.perform }.to change{ proxy_order.reload.placed_at }
expect(proxy_order.placed_at).to be_within(5.seconds).of Time.now
expect(proxy_order.placed_at).to be_within(5.seconds).of Time.zone.now
end
it "processes placeable proxy_orders" do
@@ -158,7 +158,7 @@ describe StandingOrderPlacementJob 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{ job.send(:process, order) }.to change{ order.reload.completed_at }.from(nil)
expect(order.completed_at).to be_within(5.seconds).of Time.now
expect(order.completed_at).to be_within(5.seconds).of Time.zone.now
expect(order.payments.first.state).to eq "checkout"
end

View File

@@ -14,7 +14,7 @@ describe ProxyOrder, type: :model do
it "returns true and sets canceled_at to the current time" do
expect(proxy_order.cancel).to be true
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(proxy_order.state).to eq 'canceled'
end
end
@@ -25,7 +25,7 @@ describe ProxyOrder, type: :model do
it "returns true and sets canceled_at to the current time, and cancels the order" do
expect(Spree::OrderMailer).to receive(:cancel_email) { double(:email, deliver: true) }
expect(proxy_order.cancel).to be true
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(order.reload.state).to eq 'canceled'
expect(proxy_order.state).to eq 'canceled'
end
@@ -36,7 +36,7 @@ describe ProxyOrder, type: :model do
it "returns true and sets canceled_at to the current time" do
expect(proxy_order.cancel).to be true
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(order.reload.state).to eq 'cart'
expect(proxy_order.state).to eq 'canceled'
end
@@ -124,7 +124,7 @@ describe ProxyOrder, type: :model do
it "returns false and does nothing" do
expect(proxy_order.resume).to eq false
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(proxy_order.state).to eq 'canceled'
end
end
@@ -138,7 +138,7 @@ describe ProxyOrder, type: :model do
it "returns false and does nothing" do
expect(proxy_order.resume).to eq false
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(order.reload.state).to eq 'canceled'
expect(proxy_order.state).to eq 'canceled'
end
@@ -149,7 +149,7 @@ describe ProxyOrder, type: :model do
it "returns false and does nothing" do
expect(proxy_order.resume).to eq false
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(order.reload.state).to eq 'complete'
expect(proxy_order.state).to eq 'canceled'
end

View File

@@ -31,7 +31,7 @@ describe StandingOrder, type: :model do
it "marks the standing order as cancelled and calls #cancel on all proxy_orders" do
standing_order.cancel
expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.now
expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
expect(proxy_order1).to have_received(:cancel)
expect(proxy_order2).to have_received(:cancel)
end

View File

@@ -25,9 +25,9 @@ module OpenFoodNetwork
10.times do
syncer = ProxyOrderSyncer.new(standing_orders.reload)
t1 = Time.now
t1 = Time.zone.now
syncer.sync!
t2 = Time.now
t2 = Time.zone.now
times << t2 - t1
puts (t2 - t1).round(2)
@@ -48,9 +48,9 @@ module OpenFoodNetwork
standing_orders.update_all(begins_at: start + 8.days + 1.minute)
syncer = ProxyOrderSyncer.new(standing_orders.reload)
t1 = Time.now
t1 = Time.zone.now
syncer.sync!
t2 = Time.now
t2 = Time.zone.now
times << t2 - t1
puts (t2 - t1).round(2)