Improve readability of order_cycle_set process method

This commit is contained in:
wandji20
2024-08-20 20:31:23 +01:00
parent d599cf77a2
commit 4d222c61c6
2 changed files with 15 additions and 7 deletions

View File

@@ -9,16 +9,25 @@ module Sets
super(OrderCycle, collection, attributes)
end
def process(found_element, attributes)
if @confirm_datetime_change && found_element.orders.exists? &&
((attributes.key?(:orders_open_at) &&
!found_element.same_datetime_value(:orders_open_at, attributes[:orders_open_at])) ||
(attributes.key?(:orders_close_at) &&
!found_element.same_datetime_value(:orders_close_at, attributes[:orders_close_at])))
def process(order_cycle, attributes)
if @confirm_datetime_change &&
order_cycle.orders.exists? &&
datetime_value_changed(order_cycle, attributes)
raise @error_class
end
super
end
private
def datetime_value_changed(order_cycle, attributes)
# return true if either key is present in params and change in values detected
return true if attributes.key?(:orders_open_at) &&
!order_cycle.same_datetime_value(:orders_open_at, attributes[:orders_open_at])
attributes.key?(:orders_close_at) &&
!order_cycle.same_datetime_value(:orders_close_at, attributes[:orders_close_at])
end
end
end

View File

@@ -336,7 +336,6 @@ module Admin
context "as a manager of the coordinator" do
let(:user) { coordinator.owner }
let(:error_class) { Admin::OrderCyclesController::DateTimeChangeError }
let(:expected) {
[order_cycle, allowed.merge(restricted).merge(datetime_confirmation_attrs), user]
}