From d2eee1dafdeb83e5f4864a22420a1f35b7cd066d Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 20 Feb 2020 17:42:26 +0000 Subject: [PATCH] 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 --- app/controllers/base_controller.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index b01b5b002e..45b6a6f155 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -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