Extract and fix reset_order_cycle logic from set_order_cycles: ActiveRecord.count will reload the relation and ignore the changes done by the TagRuleApplicator

This commit is contained in:
Luis Ramos
2020-02-20 17:42:26 +00:00
parent 540b26105f
commit d2eee1dafd

View File

@@ -37,9 +37,17 @@ class BaseController < ApplicationController
current_customer.andand.tag_list)
applicator.filter!(@order_cycles)
# And default to the only order cycle if there's only the one
if @order_cycles.count == 1
current_order(true).set_order_cycle! @order_cycles.first
end
reset_order_cycle
end
# Default to the only order cycle if there's only one
#
# Here we need to use @order_cycles.size not @order_cycles.count
# because TagRuleApplicator changes ActiveRecord::Relation @order_cycles
# and these changes are not seen if the relation is reloaded with count
def reset_order_cycle
return if @order_cycles.size != 1
current_order(true).set_order_cycle! @order_cycles.first
end
end