From fa4fc7c3c5b16350719ad8eb5c45efd7c6ede66e Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Fri, 21 Mar 2025 13:13:52 +0100 Subject: [PATCH] Fixes Rails TimeZone rubocop offenses --- .rubocop_todo.yml | 11 ----------- app/models/spree/gateway/pay_pal_express.rb | 2 +- .../controllers/spree/credit_cards_controller_spec.rb | 2 +- spec/services/order_cycles/webhook_service_spec.rb | 8 ++++---- .../orders/customer_cancellation_service_spec.rb | 2 +- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1becd96f06..6872fe13ea 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -516,17 +516,6 @@ Rails/LexicallyScopedActionFilter: - 'app/controllers/spree/admin/zones_controller.rb' - 'app/controllers/spree/users_controller.rb' -# Offense count: 7 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: strict, flexible -Rails/TimeZone: - Exclude: - - 'app/models/spree/gateway/pay_pal_express.rb' - - 'spec/controllers/spree/credit_cards_controller_spec.rb' - - 'spec/services/order_cycles/webhook_service_spec.rb' - - 'spec/services/orders/customer_cancellation_service_spec.rb' - # Offense count: 1 # Configuration parameters: TransactionMethods. Rails/TransactionExitStatement: diff --git a/app/models/spree/gateway/pay_pal_express.rb b/app/models/spree/gateway/pay_pal_express.rb index e24062a4ce..ba2242580b 100644 --- a/app/models/spree/gateway/pay_pal_express.rb +++ b/app/models/spree/gateway/pay_pal_express.rb @@ -97,7 +97,7 @@ module Spree refund_transaction_response = provider.refund_transaction(refund_transaction) if refund_transaction_response.success? payment.source.update( - refunded_at: Time.now, + refunded_at: Time.zone.now, refund_transaction_id: refund_transaction_response.RefundTransactionID, state: "refunded", refund_type: diff --git a/spec/controllers/spree/credit_cards_controller_spec.rb b/spec/controllers/spree/credit_cards_controller_spec.rb index 943c222908..a9f3f6dcac 100644 --- a/spec/controllers/spree/credit_cards_controller_spec.rb +++ b/spec/controllers/spree/credit_cards_controller_spec.rb @@ -73,7 +73,7 @@ RSpec.describe Spree::CreditCardsController, type: :controller do { format: :json, exp_month: 12, - exp_year: Time.now.year.next, + exp_year: Time.zone.now.year.next, last4: 4242, token:, cc_type: "visa" diff --git a/spec/services/order_cycles/webhook_service_spec.rb b/spec/services/order_cycles/webhook_service_spec.rb index bdc77bb151..4569e39126 100644 --- a/spec/services/order_cycles/webhook_service_spec.rb +++ b/spec/services/order_cycles/webhook_service_spec.rb @@ -7,8 +7,8 @@ RSpec.describe OrderCycles::WebhookService do create( :simple_order_cycle, name: "Order cycle 1", - orders_open_at: "2022-09-19 09:00:00".to_time, - orders_close_at: "2022-09-19 17:00:00".to_time, + orders_open_at: Time.zone.parse("2022-09-19 09:00:00"), + orders_close_at: Time.zone.parse("2022-09-19 17:00:00"), coordinator:, ) } @@ -42,8 +42,8 @@ RSpec.describe OrderCycles::WebhookService do data = { id: order_cycle.id, name: "Order cycle 1", - orders_open_at: "2022-09-19 09:00:00".to_time, - orders_close_at: "2022-09-19 17:00:00".to_time, + orders_open_at: Time.zone.parse("2022-09-19 09:00:00"), + orders_close_at: Time.zone.parse("2022-09-19 17:00:00"), coordinator_id: coordinator.id, coordinator_name: "Starship Enterprise", } diff --git a/spec/services/orders/customer_cancellation_service_spec.rb b/spec/services/orders/customer_cancellation_service_spec.rb index a7b3e7aad8..8f32177334 100644 --- a/spec/services/orders/customer_cancellation_service_spec.rb +++ b/spec/services/orders/customer_cancellation_service_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Orders::CustomerCancellationService do context "when an order is cancelled successfully" do it "notifies the distributor by email" do - order = create(:order, completed_at: Time.now, state: 'complete') + order = create(:order, completed_at: Time.zone.now, state: 'complete') Orders::CustomerCancellationService.new(order).call