OC will renotify automatically if closing date change

This commit is contained in:
Sebastian Castro
2021-12-10 20:17:18 +01:00
parent b76defc602
commit ed64b6176f
2 changed files with 31 additions and 1 deletions

View File

@@ -28,6 +28,8 @@ class OrderCycle < ApplicationRecord
attr_accessor :incoming_exchanges, :outgoing_exchanges
before_update :reset_processed_at, if: :will_save_change_to_orders_close_at?
validates :name, :coordinator_id, presence: true
validate :orders_close_at_after_orders_open_at?
@@ -276,4 +278,8 @@ class OrderCycle < ApplicationRecord
errors.add(:orders_close_at, :after_orders_open_at)
end
def reset_processed_at
self.processed_at = nil if orders_close_at > orders_close_at_was
end
end

View File

@@ -371,7 +371,7 @@ describe OrderCycle do
it "clones itself" do
coordinator = create(:enterprise);
oc = create(:simple_order_cycle,
coordinator_fees: [create(:enterprise_fee, enterprise: coordinator)],
coordinator_fees: [create(:enterprise_fee, enterprise: coordinator)],
preferred_product_selection_from_coordinator_inventory_only: true,
automatic_notifications: true)
ex1 = create(:exchange, order_cycle: oc)
@@ -545,6 +545,30 @@ describe OrderCycle do
end
end
describe "processed_at " do
let!(:oc) {
create(:simple_order_cycle, orders_open_at: 1.week.ago, orders_close_at: 1.day.ago, processed_at: 1.hour.ago)
}
it "reset processed_at if close date change in future" do
expect(oc.processed_at).to_not be_nil
oc.update!(orders_close_at: 1.week.from_now)
expect(oc.processed_at).to be_nil
end
it "it does not reset processed_at if close date change in the past" do
expect(oc.processed_at).to_not be_nil
oc.update!(orders_close_at: 2.day.ago)
expect(oc.processed_at).to_not be_nil
end
it "it does not reset processed_at if close date do not change" do
expect(oc.processed_at).to_not be_nil
oc.update!(orders_open_at: 2.weeks.ago)
expect(oc.processed_at).to_not be_nil
end
end
def core_exchange_attributes(exchange)
exterior_attribute_keys = %w(id order_cycle_id created_at updated_at)
exchange.attributes.