mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Improve readability of order_cycle_set process method
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user