mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Inspecting 1481 files
...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................C.C.................................................................................................................................................................................................................................................................................C..............C..........................................................C...............................C....C..........CC................................................................
Offenses:
app/services/create_order_cycle.rb:41:24: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
orders_close_at: Time.zone.now + 1.month
^^^^^^^^^^^^^^^^^^^^^^^
spec/jobs/order_cycle_closing_job_spec.rb:7:74: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
create(:order_cycle, automatic_notifications: true, orders_close_at: Time.zone.now - 1.minute)
^^^^^^^^^^^^^^^^^^^^^^^^
spec/jobs/order_cycle_closing_job_spec.rb:10:74: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
create(:order_cycle, automatic_notifications: true, orders_close_at: Time.zone.now + 1.minute)
^^^^^^^^^^^^^^^^^^^^^^^^
spec/jobs/order_cycle_closing_job_spec.rb:13:75: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
create(:order_cycle, automatic_notifications: false, orders_close_at: Time.zone.now - 1.minute)
^^^^^^^^^^^^^^^^^^^^^^^^
spec/jobs/order_cycle_opened_job_spec.rb:7:42: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
create(:order_cycle, orders_open_at: Time.zone.now - 1.hour)
^^^^^^^^^^^^^^^^^^^^^^
spec/jobs/order_cycle_opened_job_spec.rb:13:42: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
create(:order_cycle, orders_open_at: Time.zone.now + 1.minute)
^^^^^^^^^^^^^^^^^^^^^^^^
spec/services/permissions/order_spec.rb:26:58: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
completed_at: Time.zone.now - 1.year)
^^^^^^^^^^^^^^^^^^^^^^
spec/services/terms_of_service_spec.rb:21:71: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
allow(customer).to receive(:terms_and_conditions_accepted_at) { Time.zone.now - 1.week }
^^^^^^^^^^^^^^^^^^^^^^
spec/services/terms_of_service_spec.rb:22:59: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
allow(TermsOfServiceFile).to receive(:updated_at) { Time.zone.now - 2.weeks }
^^^^^^^^^^^^^^^^^^^^^^^
spec/services/terms_of_service_spec.rb:36:71: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
allow(customer).to receive(:terms_and_conditions_accepted_at) { Time.zone.now - 1.week }
^^^^^^^^^^^^^^^^^^^^^^
spec/services/terms_of_service_spec.rb:38:45: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
ActiveStorage::Blob.new(created_at: Time.zone.now - 2.weeks)
^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:647:57: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
completed_at: Time.zone.now + 1.week,
^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:652:57: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
completed_at: Time.zone.now + 2.weeks,
^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:661:40: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
oc3.update!(orders_close_at: Time.zone.now + 2.weeks)
^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/bulk_order_management_spec.rb:662:39: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
oc3.update!(orders_open_at: Time.zone.now + 1.week)
^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_cycles/list_spec.rb:128:18: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
oc_open_at = Time.zone.now - 2.weeks
^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/order_cycles/list_spec.rb:129:19: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
oc_close_at = Time.zone.now + 2.weeks
^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/orders_spec.rb:289:40: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
order2.update!(completed_at: Time.zone.now - 2.weeks)
^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/orders_spec.rb:290:40: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
order3.update!(completed_at: Time.zone.now - 3.weeks)
^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/orders_spec.rb:291:40: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
order4.update!(completed_at: Time.zone.now - 4.weeks)
^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/orders_spec.rb:292:40: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
order5.update!(completed_at: Time.zone.now - 5.weeks)
^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/reports/orders_and_fulfillment_spec.rb:113:31: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
let(:completed_at1) { Time.zone.now - 1500.hours } # 1500 hours in the past
^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/reports/orders_and_fulfillment_spec.rb:114:31: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
let(:completed_at2) { Time.zone.now - 1700.hours } # 1700 hours in the past
^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/reports/orders_and_fulfillment_spec.rb:115:33: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
let(:datetime_start1) { Time.zone.now - 1600.hours } # 1600 hours in the past
^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/reports/orders_and_fulfillment_spec.rb:116:33: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
let(:datetime_start2) { Time.zone.now - 1800.hours } # 1600 hours in the past
^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/reports/orders_and_fulfillment_spec.rb:117:30: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
let(:datetime_end) { Time.zone.now - 1400.hours } # 1400 hours in the past
^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/system/admin/reports/packing_report_spec.rb:13:26: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a method call.
let!(:open_datetime) { (1.month.ago).strftime("%Y-%m-%d 00:00") }
^^^^^^^^^^^^^
spec/system/admin/reports/packing_report_spec.rb:13:27: C: [Corrected] Rails/DurationArithmetic: Do not add or subtract duration.
let!(:open_datetime) { (Time.zone.now - 1.month).strftime("%Y-%m-%d 00:00") }
^^^^^^^^^^^^^^^^^^^^^^^
1481 files inspected, 28 offenses detected, 28 offenses corrected
68 lines
1.6 KiB
Ruby
68 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Creates an order cycle for the provided enterprise and selecting all the
|
|
# variants specified for both incoming and outgoing exchanges
|
|
class CreateOrderCycle
|
|
# Constructor
|
|
#
|
|
# @param enterprise [Enterprise]
|
|
# @param variants [Array<Spree::Variant>]
|
|
def initialize(enterprise, variants)
|
|
@enterprise = enterprise
|
|
@variants = variants
|
|
end
|
|
|
|
# Creates the order cycle
|
|
def call
|
|
incoming_exchange.order_cycle = order_cycle
|
|
incoming_exchange.variants << variants
|
|
|
|
outgoing_exchange.order_cycle = order_cycle
|
|
outgoing_exchange.variants << variants
|
|
|
|
order_cycle.exchanges << incoming_exchange
|
|
order_cycle.exchanges << outgoing_exchange
|
|
|
|
order_cycle.save!
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :enterprise, :variants
|
|
|
|
# Builds an order cycle for the next month, starting now
|
|
#
|
|
# @return [OrderCycle]
|
|
def order_cycle
|
|
@order_cycle ||= OrderCycle.new(
|
|
coordinator_id: enterprise.id,
|
|
name: 'Monthly order cycle',
|
|
orders_open_at: Time.zone.now,
|
|
orders_close_at: 1.month.from_now
|
|
)
|
|
end
|
|
|
|
# Builds an exchange with the enterprise both as sender and receiver
|
|
#
|
|
# @return [Exchange]
|
|
def incoming_exchange
|
|
@incoming_exchange ||= Exchange.new(
|
|
sender_id: enterprise.id,
|
|
receiver_id: enterprise.id,
|
|
incoming: true
|
|
)
|
|
end
|
|
|
|
# Builds an exchange with the enterprise both as sender and receiver
|
|
#
|
|
# @return [Exchange]
|
|
def outgoing_exchange
|
|
@outgoing_exchange ||= Exchange.new(
|
|
sender_id: enterprise.id,
|
|
receiver_id: enterprise.id,
|
|
pickup_time: '8 am',
|
|
incoming: false
|
|
)
|
|
end
|
|
end
|